diff --git a/.gitignore b/.gitignore index aa5f392d329..aa76ccdd104 100644 --- a/.gitignore +++ b/.gitignore @@ -61,3 +61,8 @@ cache.sqlite-journal out.png /test/android/app/.cxx /test/android/app/build + +# Rust +**/target/ +**/*.rs.bk +**/*.profraw diff --git a/platform/rust-cxx/.gitignore b/platform/rust-cxx/.gitignore new file mode 100644 index 00000000000..fd094e14f57 --- /dev/null +++ b/platform/rust-cxx/.gitignore @@ -0,0 +1,16 @@ +# Generated by Cargo +# will have compiled files and executables +**/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# These are temp files generated by trybuild +wip + +# coverage reports +**/*.profraw diff --git a/platform/rust-cxx/build.rs b/platform/rust-cxx/build.rs index 7492b77f2e1..5de758f7020 100644 --- a/platform/rust-cxx/build.rs +++ b/platform/rust-cxx/build.rs @@ -1,10 +1,18 @@ fn main() { - cxx_build::bridge("src/main.rs") - .file("src/blobstore.cc") - .std("c++20") - .compile("cxxbridge-demo"); + // use src/main.rs to generate a header + // use cmake crate with flags to compile that header + rust-ffi.cc + core -> staticlib - println!("cargo:rerun-if-changed=src/main.rs"); - println!("cargo:rerun-if-changed=src/blobstore.cc"); - println!("cargo:rerun-if-changed=include/blobstore.h"); + // println what to link with + println!("cargo:rustc-link-lib=static=rust-ffi"); + + + // + // cxx_build::bridge("src/main.rs") + // .file("src/blobstore.cc") + // .std("c++20") + // .compile("cxxbridge-demo"); + // + // println!("cargo:rerun-if-changed=src/main.rs"); + // println!("cargo:rerun-if-changed=src/blobstore.cc"); + // println!("cargo:rerun-if-changed=include/blobstore.h"); } diff --git a/platform/rust-cxx/justfile b/platform/rust-cxx/justfile new file mode 100644 index 00000000000..f9e5604d1eb --- /dev/null +++ b/platform/rust-cxx/justfile @@ -0,0 +1,64 @@ +#!/usr/bin/env just --justfile + +@_default: + just --list + +# Clean all build artifacts +clean: + cargo clean + +# Update all dependencies, including the breaking changes. Requires nightly toolchain (install with `rustup install nightly`) +update: + cargo +nightly -Z unstable-options update --breaking + cargo update + +# Quick compile without building a binary +check: + RUSTFLAGS='-D warnings' cargo check --workspace --all-targets + +# Build the library +build: + cargo build --workspace + +# Run cargo clippy to lint the code +clippy: + cargo clippy --all-targets --workspace -- -D warnings + +# Test code formatting +test-fmt: + cargo fmt --all -- --check + +# Reformat all code `cargo fmt`. If nightly is available, use it for better results +fmt: + #!/usr/bin/env bash + set -euo pipefail + if command -v cargo +nightly &> /dev/null; then + echo 'Reformatting Rust code using nightly Rust fmt to sort imports' + cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate + else + echo 'Reformatting Rust with the stable cargo fmt. Install nightly with `rustup install nightly` for better results' + cargo fmt --all + fi + +# Run all tests +test: + cargo test --all-targets --workspace + +# Test documentation +test-doc: + RUSTDOCFLAGS="-D warnings" cargo doc --no-deps + +# Build and open code documentation +docs: + cargo doc --no-deps --open + +# Print Rust version information +rust-info: + rustc --version + cargo --version + +# Run all tests as expected by CI +ci-test: rust-info test-fmt clippy build test test-doc + +# Run minimal subset of tests to ensure compatibility with MSRV (Minimum Supported Rust Version). This assumes the default toolchain is already set to MSRV. +ci-test-msrv: rust-info build test diff --git a/platform/rust-cxx/src/rust-ffi.cc b/platform/rust-cxx/src/rust-ffi.cc new file mode 100644 index 00000000000..a083d389d3e --- /dev/null +++ b/platform/rust-cxx/src/rust-ffi.cc @@ -0,0 +1 @@ +// use ParsedColor diff --git a/platform/rust-cxx/src/rust-ffi.h b/platform/rust-cxx/src/rust-ffi.h new file mode 100644 index 00000000000..a083d389d3e --- /dev/null +++ b/platform/rust-cxx/src/rust-ffi.h @@ -0,0 +1 @@ +// use ParsedColor