From f97c60b5f77c4b9b668ff0b5fd292b41521c72fd Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 25 Oct 2024 10:30:01 -0400 Subject: Prevent building test artifacts on cmake builds For some reason the linker is looking in the target directory of external rust plugins? --- plugins/warp/CMakeLists.txt | 4 +++- plugins/warp/Cargo.toml | 4 ++++ plugins/warp/build.rs | 57 ++++++++++++++++++++++++--------------------- 3 files changed, 37 insertions(+), 28 deletions(-) (limited to 'plugins') diff --git a/plugins/warp/CMakeLists.txt b/plugins/warp/CMakeLists.txt index acfbf41e..9a144270 100644 --- a/plugins/warp/CMakeLists.txt +++ b/plugins/warp/CMakeLists.txt @@ -33,7 +33,9 @@ if(FORCE_COLORED_OUTPUT) set(CARGO_OPTS ${CARGO_OPTS} --color always) endif() -set(CARGO_FEATURES "") +# NOTE: --no-default-features is set to disable building artifacts used for testing +# NOTE: the linker is looking in the target dir and linking on it apparently. +set(CARGO_FEATURES "--no-default-features") set(OUTPUT_FILE_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) set(OUTPUT_PDB_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}.pdb) set(OUTPUT_FILE_PATH ${BN_CORE_PLUGIN_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) diff --git a/plugins/warp/Cargo.toml b/plugins/warp/Cargo.toml index 5527eca3..cf13e34d 100644 --- a/plugins/warp/Cargo.toml +++ b/plugins/warp/Cargo.toml @@ -23,6 +23,10 @@ ar = { git = "https://github.com/mdsteele/rust-ar" } tempdir = "0.3.7" serde_json = "1.0.132" +[features] +default = ["build_artifacts"] +build_artifacts = [] + [build-dependencies] cc = "1.1.28" diff --git a/plugins/warp/build.rs b/plugins/warp/build.rs index fe4d31f8..ac4a413e 100644 --- a/plugins/warp/build.rs +++ b/plugins/warp/build.rs @@ -31,37 +31,40 @@ fn main() { ); } - // Copy all binaries to OUT_DIR for unit tests. - let bin_dir: PathBuf = "fixtures/bin".into(); - if let Ok(entries) = std::fs::read_dir(bin_dir) { - for entry in entries { - let entry = entry.unwrap(); - let path = entry.path(); - if path.is_file() { - let file_name = path.file_name().unwrap(); - let dest_path = out_dir_path.join(file_name); - std::fs::copy(&path, &dest_path).expect("failed to copy binary to OUT_DIR"); + #[cfg(feature = "build_artifacts")] + { + // Copy all binaries to OUT_DIR for unit tests. + let bin_dir: PathBuf = "fixtures/bin".into(); + if let Ok(entries) = std::fs::read_dir(bin_dir) { + for entry in entries { + let entry = entry.unwrap(); + let path = entry.path(); + if path.is_file() { + let file_name = path.file_name().unwrap(); + let dest_path = out_dir_path.join(file_name); + std::fs::copy(&path, &dest_path).expect("failed to copy binary to OUT_DIR"); + } } } - } - // Compile all .c files in fixtures/src directory for unit tests. - let src_dir: PathBuf = "fixtures/src".into(); - if let Ok(entries) = std::fs::read_dir(src_dir) { - for entry in entries { - let entry = entry.unwrap(); - let path = entry.path(); - match path.extension().map(|s| s.to_str().unwrap()) { - Some("c") => { - cc::Build::new() - .file(&path) - .compile(path.file_stem().unwrap().to_str().unwrap()); + // Compile all .c files in fixtures/src directory for unit tests. + let src_dir: PathBuf = "fixtures/src".into(); + if let Ok(entries) = std::fs::read_dir(src_dir) { + for entry in entries { + let entry = entry.unwrap(); + let path = entry.path(); + match path.extension().map(|s| s.to_str().unwrap()) { + Some("c") => { + cc::Build::new() + .file(&path) + .compile(path.file_stem().unwrap().to_str().unwrap()); + } + Some("rs") => { + compile_rust(path); + } + _ => {} } - Some("rs") => { - compile_rust(path); - } - _ => {} } - } + } } } -- cgit v1.3.1