From 05c320383e8ed46de47974d33497a271f9814790 Mon Sep 17 00:00:00 2001 From: Dom Rodriguez Date: Thu, 14 Sep 2023 23:51:04 +0100 Subject: [PATCH] Add Rust support Signed-off-by: Dom Rodriguez --- src/rust/CMakeLists.txt | 13 +++ src/rust/Cargo.lock | 173 ++++++++++++++++++++++++++++++++++++++++ src/rust/Cargo.toml | 14 ++++ src/rust/src/lib.rs | 21 +++++ 4 files changed, 221 insertions(+) create mode 100644 src/rust/CMakeLists.txt create mode 100644 src/rust/Cargo.lock create mode 100644 src/rust/Cargo.toml create mode 100644 src/rust/src/lib.rs diff --git a/src/rust/CMakeLists.txt b/src/rust/CMakeLists.txt new file mode 100644 index 00000000..a86a5d87 --- /dev/null +++ b/src/rust/CMakeLists.txt @@ -0,0 +1,13 @@ +find_program(CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/") +if (CXXBRIDGE STREQUAL "CXXBRIDGE-NOTFOUND") + find_program(CARGO cargo PATHS "$ENV{HOME}/.cargo/bin/") + if (CARGO STREQUAL "CARGO-NOTFOUND") + message(FATAL_ERROR "Requires cargo available in path, install via rustup https://rustup.rs/") + endif() + message("Could not find cxxbridge, trying to install with `cargo install cxxbridge-cmd'") + execute_process(COMMAND ${CARGO} install cxxbridge-cmd) + find_program(CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/") +endif() + +corrosion_import_crate(MANIFEST_PATH Cargo.toml) +corrosion_add_cxxbridge(rustlib CRATE openpinebuds_rs FILES lib.rs) diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock new file mode 100644 index 00000000..001363f7 --- /dev/null +++ b/src/rust/Cargo.lock @@ -0,0 +1,173 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "cxx" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e928d50d5858b744d1ea920b790641129c347a770d1530c3a85b77705a5ee031" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8332ba63f8a8040ca479de693150129067304a3496674477fff6d0c372cc34ae" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5966a5a87b6e9bb342f5fab7170a93c77096efe199872afffc4b477cfeb86957" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b2dab6991c7ab1572fea8cb049db819b1aeea1e2dac74c0869f244d9f21a7c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" +dependencies = [ + "cc", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "openpinebuds-rs" +version = "0.1.0" +dependencies = [ + "cxx", + "cxx-build", +] + +[[package]] +name = "proc-macro2" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92de25114670a878b1261c79c9f8f729fb97e95bac93f6312f583c60dd6a1dfe" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5907a1b7c277254a8b15170f6e7c97cfa60ee7872a3217663bb81151e48184bb" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "scratch" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" + +[[package]] +name = "syn" +version = "2.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c3457aacde3c65315de5031ec191ce46604304d2446e803d71ade03308d970" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "unicode-ident" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml new file mode 100644 index 00000000..fd5abbd6 --- /dev/null +++ b/src/rust/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "openpinebuds-rs" +version = "0.1.0" +edition = "2021" + +[lib] +name = "openpinebuds_rs" +crate-type = ["staticlib"] + +[dependencies] +cxx = "1.0" + +[build-dependencies] +cxx-build = "1.0" diff --git a/src/rust/src/lib.rs b/src/rust/src/lib.rs new file mode 100644 index 00000000..9854e143 --- /dev/null +++ b/src/rust/src/lib.rs @@ -0,0 +1,21 @@ +//! Rust library for OpenPineBuds +#![deny( + warnings, + missing_copy_implementations, + missing_debug_implementations, + missing_docs, + clippy::all, + clippy::cargo, + trivial_casts, + trivial_numeric_casts, + unused_import_braces, + unused_qualifications, + unused_extern_crates, + variant_size_differences +)] + +#[cxx::bridge] +mod ffi { +//! Rust FFI module for OpenPineBuds + +}