]> git.seodisparate.com - UDPConnection/commitdiff
Add buildgen rust binding
authorStephen Seo <seo.disparate@gmail.com>
Wed, 17 Apr 2019 05:19:28 +0000 (14:19 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 17 Apr 2019 06:15:53 +0000 (15:15 +0900)
18 files changed:
archLinuxPkg/.gitignore [new file with mode: 0644]
archLinuxPkg/PKGBUILD [new file with mode: 0644]
c_impl/CMakeLists.txt [moved from CMakeLists.txt with 75% similarity]
c_impl/src/UDPC_Defines.h [moved from src/UDPC_Defines.h with 100% similarity]
c_impl/src/UDPC_Deque.c [moved from src/UDPC_Deque.c with 100% similarity]
c_impl/src/UDPC_Deque.h [moved from src/UDPC_Deque.h with 100% similarity]
c_impl/src/UDPC_HashMap.c [moved from src/UDPC_HashMap.c with 100% similarity]
c_impl/src/UDPC_HashMap.h [moved from src/UDPC_HashMap.h with 100% similarity]
c_impl/src/UDPConnection.c [moved from src/UDPConnection.c with 100% similarity]
c_impl/src/UDPConnection.h [moved from src/UDPConnection.h with 100% similarity]
c_impl/src/test/UDPC_NetworkTest.c [moved from src/test/UDPC_NetworkTest.c with 100% similarity]
c_impl/src/test/UDPC_UnitTest.c [moved from src/test/UDPC_UnitTest.c with 100% similarity]
c_impl/src/test/UDPC_UnitTest.h [moved from src/test/UDPC_UnitTest.h with 100% similarity]
rust_binding/.gitignore [new file with mode: 0644]
rust_binding/Cargo.toml [new file with mode: 0644]
rust_binding/build.rs [new file with mode: 0644]
rust_binding/src/lib.rs [new file with mode: 0644]
rust_binding/wrapper.h [new file with mode: 0644]

diff --git a/archLinuxPkg/.gitignore b/archLinuxPkg/.gitignore
new file mode 100644 (file)
index 0000000..468cd87
--- /dev/null
@@ -0,0 +1 @@
+*.pkg.tar.xz
diff --git a/archLinuxPkg/PKGBUILD b/archLinuxPkg/PKGBUILD
new file mode 100644 (file)
index 0000000..8d19e23
--- /dev/null
@@ -0,0 +1,43 @@
+# Maintainer: Your Name <youremail@domain.com>
+pkgname=UDPConnection
+pkgver=1.0
+pkgrel=1
+epoch=
+pkgdesc="A C library that provides a UDP connection"
+arch=('x86_64')
+url=""
+license=('MIT')
+groups=()
+depends=()
+makedepends=()
+checkdepends=()
+optdepends=()
+provides=()
+conflicts=()
+replaces=()
+backup=()
+options=()
+install=
+changelog=
+source=()
+noextract=()
+md5sums=()
+validpgpkeys=()
+
+prepare() {
+    echo >&/dev/null
+}
+
+build() {
+    cmake \
+        -DCMAKE_BUILD_TYPE=Release \
+        -DCMAKE_INSTALL_PREFIX=/usr \
+        -DBUILD_SHARED_LIBS=True \
+        -G Ninja \
+        ../../c_impl/
+    ninja
+}
+
+package() {
+    DESTDIR="$pkgdir/" ninja install
+}
similarity index 75%
rename from CMakeLists.txt
rename to c_impl/CMakeLists.txt
index 08a24091fb28762f249a737c7726cbf502ddb3d5..b4edbb59d35be357f1854fc1e6b9b57e94599b58 100644 (file)
@@ -1,6 +1,8 @@
 cmake_minimum_required(VERSION 3.7)
 project(UDPConnection)
 
+set(UDPConnection_VERSION 1.0)
+
 set(UDPConnection_SOURCES
     src/UDPConnection.c
     src/UDPC_Deque.c
@@ -19,6 +21,8 @@ endif()
 
 add_library(UDPConnection ${UDPConnection_SOURCES})
 
+set_target_properties(UDPConnection PROPERTIES VERSION ${UDPConnection_VERSION})
+
 target_compile_features(UDPConnection PUBLIC c_std_11)
 target_link_libraries(UDPConnection PUBLIC pthread)
 
@@ -35,3 +39,11 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
     target_link_libraries(NetworkTest PUBLIC UDPConnection)
     target_include_directories(NetworkTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
 endif()
+
+install(TARGETS UDPConnection CONFIGURATIONS Release DESTINATION lib)
+install(FILES
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/UDPConnection.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/UDPC_Defines.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/UDPC_Deque.h
+    ${CMAKE_CURRENT_SOURCE_DIR}/src/UDPC_HashMap.h
+    DESTINATION include)
similarity index 100%
rename from src/UDPC_Defines.h
rename to c_impl/src/UDPC_Defines.h
similarity index 100%
rename from src/UDPC_Deque.c
rename to c_impl/src/UDPC_Deque.c
similarity index 100%
rename from src/UDPC_Deque.h
rename to c_impl/src/UDPC_Deque.h
similarity index 100%
rename from src/UDPC_HashMap.c
rename to c_impl/src/UDPC_HashMap.c
similarity index 100%
rename from src/UDPC_HashMap.h
rename to c_impl/src/UDPC_HashMap.h
diff --git a/rust_binding/.gitignore b/rust_binding/.gitignore
new file mode 100644 (file)
index 0000000..1e7caa9
--- /dev/null
@@ -0,0 +1,2 @@
+Cargo.lock
+target/
diff --git a/rust_binding/Cargo.toml b/rust_binding/Cargo.toml
new file mode 100644 (file)
index 0000000..ab94e15
--- /dev/null
@@ -0,0 +1,10 @@
+[package]
+name = "udpc_rs"
+version = "0.1.0"
+authors = ["Stephen Seo <seo.disparate@gmail.com>"]
+edition = "2018"
+
+[dependencies]
+
+[build-dependencies]
+bindgen = "0.42.2"
diff --git a/rust_binding/build.rs b/rust_binding/build.rs
new file mode 100644 (file)
index 0000000..345cd53
--- /dev/null
@@ -0,0 +1,44 @@
+use bindgen;
+
+use std::env;
+use std::path::PathBuf;
+
+fn main() {
+    println!("cargo:rustc-link-lib=UDPConnection");
+
+    let bindings = bindgen::Builder::default()
+        .header("wrapper.h")
+        .whitelist_type("UDPC_callback_connected")
+        .whitelist_type("UDPC_callback_disconnected")
+        .whitelist_type("UDPC_callback_received")
+        .whitelist_type("UDPC_Context")
+        .whitelist_function("UDPC_init")
+        .whitelist_function("UDPC_init_threaded_update")
+        .whitelist_function("UDPC_destroy")
+        .whitelist_function("UDPC_set_callback_connected")
+        .whitelist_function("UDPC_set_callback_disconnected")
+        .whitelist_function("UDPC_set_callback_received")
+        .whitelist_function("UDPC_check_events")
+        .whitelist_function("UDPC_client_initiate_connection")
+        .whitelist_function("UDPC_queue_send")
+        .whitelist_function("UDPC_get_queue_send_available")
+        .whitelist_function("UDPC_get_accept_new_connections")
+        .whitelist_function("UDPC_set_accept_new_connections")
+        .whitelist_function("UDPC_get_protocol_id")
+        .whitelist_function("UDPC_set_protocol_id")
+        .whitelist_function("UDPC_get_error")
+        .whitelist_function("UDPC_get_error_str")
+        .whitelist_function("UDPC_set_logging_type")
+        .whitelist_function("UDPC_update")
+        .whitelist_function("UDPC_strtoa")
+        .opaque_type("UDPC_Context")
+        .opaque_type("UDPC_Deque")
+        .opaque_type("UDPC_HashMap")
+        .generate()
+        .expect("Unable to generate bindings");
+
+    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
+    bindings
+        .write_to_file(out_path.join("bindings.rs"))
+        .expect("Couldn't write bindings!");
+}
diff --git a/rust_binding/src/lib.rs b/rust_binding/src/lib.rs
new file mode 100644 (file)
index 0000000..a38a13a
--- /dev/null
@@ -0,0 +1,5 @@
+#![allow(non_upper_case_globals)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+
+include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
diff --git a/rust_binding/wrapper.h b/rust_binding/wrapper.h
new file mode 100644 (file)
index 0000000..ae5a4d9
--- /dev/null
@@ -0,0 +1 @@
+#include "../c_impl/src/UDPConnection.h"