From 4fc24f8724126834b43dd8319dd39ce2c027734d Mon Sep 17 00:00:00 2001 From: Christian Eltzschig Date: Tue, 30 Apr 2024 03:00:40 +0200 Subject: [PATCH] [#210] Create simple playground example --- Cargo.toml | 5 +++++ iceoryx2-lang/c/Cargo.toml | 26 ++++++++++++++++++++++++++ iceoryx2-lang/c/README.md | 4 ++++ iceoryx2-lang/c/build.rs | 19 +++++++++++++++++++ iceoryx2-lang/c/iceoryx2.h | 6 ++++++ iceoryx2-lang/c/src/lib.rs | 4 ++++ 6 files changed, 64 insertions(+) create mode 100644 iceoryx2-lang/c/Cargo.toml create mode 100644 iceoryx2-lang/c/README.md create mode 100644 iceoryx2-lang/c/build.rs create mode 100644 iceoryx2-lang/c/iceoryx2.h create mode 100644 iceoryx2-lang/c/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 00569a38..7e14ca3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,8 @@ members = [ "iceoryx2-bb/testing", "iceoryx2-bb/trait-tests", + "iceoryx2-lang/c", + "iceoryx2-cal", "iceoryx2", "iceoryx2-pal/concurrency-sync", @@ -54,10 +56,13 @@ iceoryx2-pal-configuration = { version = "0.3.0", path = "iceoryx2-pal/configura iceoryx2-cal = { version = "0.3.0", path = "iceoryx2-cal" } +iceoryx2-lang-c = { version = "0.3.0", path = "iceoryx2-lang-c" } + iceoryx2 = { version = "0.3.0", path = "iceoryx2/" } bindgen = { version = "0.69.4" } bitflags = { version = "2.5.0" } +cbindgen = { version = "0.26.0" } cc = { version = "1.0.98" } cdr = { version = "0.2.4" } clap = { version = "4.5.4", features = ["derive"] } diff --git a/iceoryx2-lang/c/Cargo.toml b/iceoryx2-lang/c/Cargo.toml new file mode 100644 index 00000000..6f6e9b4c --- /dev/null +++ b/iceoryx2-lang/c/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "iceoryx2-lang-c" +categories.workspace = true +description.workspace = true +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +rust-version.workspace = true +version.workspace = true +build = "build.rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +path = "src/lib.rs" +name = "iceoryx2_lang_c" +crate-type = ["cdylib", "staticlib"] + +[build-dependencies] +cbindgen = { workspace = true } + +[dependencies] +iceoryx2 = { workspace = true } diff --git a/iceoryx2-lang/c/README.md b/iceoryx2-lang/c/README.md new file mode 100644 index 00000000..438dc7b9 --- /dev/null +++ b/iceoryx2-lang/c/README.md @@ -0,0 +1,4 @@ + * compile: `gcc example.c -Ltarget/debug -liceoryx2_lang_c` + * set library path: `set -gx LD_LIBRARY_PATH $HOME/Development/iceoryx2/target/debug/` + + * see: https://github.com/corrosion-rs/corrosion diff --git a/iceoryx2-lang/c/build.rs b/iceoryx2-lang/c/build.rs new file mode 100644 index 00000000..b8f6634b --- /dev/null +++ b/iceoryx2-lang/c/build.rs @@ -0,0 +1,19 @@ +extern crate cbindgen; + +use std::env; + +use cbindgen::Config; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + + let mut config = Config::default(); + config.language = cbindgen::Language::C; + + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_config(config) + .generate() + .expect("Unable to generate c bindings") + .write_to_file("iceoryx2.h"); +} diff --git a/iceoryx2-lang/c/iceoryx2.h b/iceoryx2-lang/c/iceoryx2.h new file mode 100644 index 00000000..d5996b6b --- /dev/null +++ b/iceoryx2-lang/c/iceoryx2.h @@ -0,0 +1,6 @@ +#include +#include +#include +#include + +void zero_copy_service_list(void); diff --git a/iceoryx2-lang/c/src/lib.rs b/iceoryx2-lang/c/src/lib.rs new file mode 100644 index 00000000..53609cb2 --- /dev/null +++ b/iceoryx2-lang/c/src/lib.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern "C" fn zero_copy_service_list() { + println!("hello world"); +}