diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e62fe19..72b11e1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ else() string(APPEND mxl_VERSION ".0") endif() +option(BUILD_TESTS "Build the tests" ON) +option(BUILD_TOOLS "Build the tools" ON) + project(mxl VERSION ${mxl_VERSION} LANGUAGES CXX C @@ -54,8 +57,10 @@ if(APPLE) endif() add_subdirectory(lib) -add_subdirectory(tools) add_subdirectory(utils) +if (BUILD_TOOLS) + add_subdirectory(tools) +endif() find_package(Doxygen) @@ -132,4 +137,4 @@ set(CPACK_PACKAGE_CONTACT "DMF MXL ") set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") # Include CPack -include(CPack) \ No newline at end of file +include(CPack) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 14bcdb74..d716dcbd 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -89,7 +89,9 @@ target_link_libraries(mxl # Alias trace to libtrace::libtrace so that this library can be used # in lieu of a module from the local source tree add_library(${PROJECT_NAME}::mxl ALIAS mxl) -add_subdirectory(tests) +if (BUILD_TESTS) + add_subdirectory(tests) +endif() # Install targets install(TARGETS mxl EXPORT ${PROJECT_NAME}-targets @@ -162,4 +164,4 @@ install(EXPORT ${PROJECT_NAME}-targets NAMESPACE ${PROJECT_NAME}:: DESTINATION ${MXL_CMAKE_CONFIG_DESTINATION} COMPONENT ${PROJECT_NAME}-dev - ) \ No newline at end of file + ) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 6a731e57..eda5e2d4 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -60,6 +60,15 @@ version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +[[package]] +name = "cc" +version = "1.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2352e5597e9c544d5e6d9c95190d5d27738ade584fa8db0a16e130e5c2b5296e" +dependencies = [ + "shlex", +] + [[package]] name = "cexpr" version = "0.6.0" @@ -124,6 +133,15 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" +[[package]] +name = "cmake" +version = "0.1.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7caa3f9de89ddbe2c607f4101924c5abec803763ae9534e4f4d7d8f84aa81f0" +dependencies = [ + "cc", +] + [[package]] name = "dlopen2" version = "0.8.0" @@ -251,6 +269,7 @@ name = "mxl-sys" version = "0.1.0" dependencies = [ "bindgen", + "cmake", ] [[package]] diff --git a/rust/flake.lock b/rust/flake.lock new file mode 100644 index 00000000..e69de29b diff --git a/rust/flake.nix b/rust/flake.nix new file mode 100644 index 00000000..a219b532 --- /dev/null +++ b/rust/flake.nix @@ -0,0 +1,70 @@ +{ + description = "Flake for MXL dev"; + + inputs = { + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + self, + nixpkgs, + rust-overlay + }: let + overlays = [ + (import rust-overlay) + (self: super: { + rustStable = super.rust-bin.stable."1.88.0".default; + rustNightly = super.rust-bin.nightly."2025-06-26".default; + }) + ]; + + allSystems = [ + "x86_64-linux" # 64-bit Intel/AMD Linux + "aarch64-linux" # 64-bit ARM Linux + "x86_64-darwin" # 64-bit Intel macOS + "aarch64-darwin" # 64-bit ARM macOS + ]; + + forAllSystems = f: + nixpkgs.lib.genAttrs allSystems (system: + f { + pkgs = import nixpkgs { + inherit overlays system; + }; + } + ); + in { + devShells = forAllSystems ({pkgs}: { + default = pkgs.mkShell { + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [pkgs.llvmPackages_latest.libclang.lib]; + packages = + (with pkgs; [ + rustStable + rust-analyzer + clang + cmake + pkg-config + ]); + }; + } + ); + nightly = forAllSystems ({pkgs}: { + default = pkgs.mkShell { + LIBCLANG_PATH = pkgs.lib.makeLibraryPath [pkgs.llvmPackages_latest.libclang.lib]; + packages = + (with pkgs; [ + rustNightly + rust-analyzer + clang + cmake + pkg-config + ]); + }; + } + ); + }; +} diff --git a/rust/mxl-sys/.gitignore b/rust/mxl-sys/.gitignore new file mode 100644 index 00000000..8d6e3400 --- /dev/null +++ b/rust/mxl-sys/.gitignore @@ -0,0 +1 @@ +mxl/version.h diff --git a/rust/mxl-sys/Cargo.toml b/rust/mxl-sys/Cargo.toml index 6bbb0ffd..0e4fa65a 100644 --- a/rust/mxl-sys/Cargo.toml +++ b/rust/mxl-sys/Cargo.toml @@ -8,6 +8,7 @@ version.workspace = true [build-dependencies] bindgen.workspace = true +cmake = "0.1.54" [features] mxl-not-built = [] diff --git a/rust/mxl-sys/build.rs b/rust/mxl-sys/build.rs index 0d76aff0..390ce970 100644 --- a/rust/mxl-sys/build.rs +++ b/rust/mxl-sys/build.rs @@ -1,4 +1,5 @@ use std::env; +use std::fs; use std::path::PathBuf; #[cfg(debug_assertions)] @@ -27,8 +28,7 @@ fn get_bindgen_specs() -> BindgenSpecs { .to_string_lossy() .to_string(), ]; - #[cfg(not(feature = "mxl-not-built"))] - { + if cfg!(not(feature = "mxl-not-built")) { let build_dir = repo_root.join("build").join(BUILD_VARIANT); let build_version_dir = build_dir .join("lib") @@ -37,6 +37,34 @@ fn get_bindgen_specs() -> BindgenSpecs { .to_string(); includes_dirs.push(build_version_dir); + + let mxl_version_out_path = manifest_dir.join("mxl"); + if !fs::exists(&mxl_version_out_path) + .expect("Error checking if out path for version header file exists") + { + fs::create_dir(&mxl_version_out_path) + .expect("Failed to create out path for version header file"); + } + let mxl_version_header = mxl_version_out_path.join("version.h"); + println!("cargo:rerun-if-changed={}", mxl_version_header.display()); + // TODO: re-run on build_dir changing? + + let dst = cmake::Config::new(repo_root) + .out_dir(build_dir) + .generator("Unix Makefiles") + .define("BUILD_TESTS", "OFF") + .define("BUILD_TOOLS", "OFF") + // .configure_arg(format!("--preset={BUILD_VARIANT}")) + .build(); + + let mxl_version_location = dst.join("include").join("mxl").join("version.h"); + assert!(matches!(std::fs::exists(&mxl_version_location), Ok(true))); + + fs::copy(&mxl_version_location, &mxl_version_header) + .expect("Could copy mxl version header"); + + println!("cargo:rustc-link-search={}", dst.join("lib64").display()); + println!("cargo:rustc-link-lib=mxl"); } BindgenSpecs {