From c23f419af12e94250d1463b090a65352ef19b3dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20H=C3=B8rl=C3=BCck=20Berg?= <36937807+henrikhorluck@users.noreply.github.com> Date: Sun, 13 Aug 2023 15:33:36 +0200 Subject: [PATCH] Use the workspace from CMake - Make CMake use the correct target-path - Make build.rs use the correct target dir Workspaces place it in the project root by default, the alternative to making this change is to add a `.cargo/config.toml` file with ```toml [build] target-dir = "fish-rust/target" ``` Which I think is unnecessary, as we likely want to use the new location anyways. --- cmake/Rust.cmake | 3 ++- cmake/Tests.cmake | 8 ++++---- fish-rust/build.rs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmake/Rust.cmake b/cmake/Rust.cmake index 3ec5482e6..99ceb6b6c 100644 --- a/cmake/Rust.cmake +++ b/cmake/Rust.cmake @@ -37,7 +37,8 @@ if(DEFINED ASAN) endif() corrosion_import_crate( - MANIFEST_PATH "${CMAKE_SOURCE_DIR}/fish-rust/Cargo.toml" + MANIFEST_PATH "${CMAKE_SOURCE_DIR}/Cargo.toml" + CRATES "fish-rust" FEATURES "${FISH_CRATE_FEATURES}" FLAGS "${CARGO_FLAGS}" ) diff --git a/cmake/Tests.cmake b/cmake/Tests.cmake index 5e900741e..4061a6b20 100644 --- a/cmake/Tests.cmake +++ b/cmake/Tests.cmake @@ -193,8 +193,8 @@ endif() if(NOT DEFINED ASAN) add_test( NAME "cargo-test" - COMMAND cargo test ${CARGO_FLAGS} --target-dir target ${cargo_target_opt} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/fish-rust" + COMMAND cargo test ${CARGO_FLAGS} --package fish-rust --target-dir target ${cargo_target_opt} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) set_tests_properties("cargo-test" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE}) add_test_target("cargo-test") @@ -202,7 +202,7 @@ endif() add_test( NAME "cargo-test-widestring" - COMMAND cargo test ${CARGO_FLAGS} --target-dir target ${cargo_target_opt} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/fish-rust/widestring-suffix/" + COMMAND cargo test ${CARGO_FLAGS} --package widestring-suffix --target-dir target ${cargo_target_opt} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" ) add_test_target("cargo-test-widestring") diff --git a/fish-rust/build.rs b/fish-rust/build.rs index 507db90e1..06335c826 100644 --- a/fish-rust/build.rs +++ b/fish-rust/build.rs @@ -6,7 +6,7 @@ fn main() { let rust_dir = std::env::var("CARGO_MANIFEST_DIR").expect("Env var CARGO_MANIFEST_DIR missing"); let target_dir = - std::env::var("FISH_RUST_TARGET_DIR").unwrap_or(format!("{}/{}", rust_dir, "target/")); + std::env::var("FISH_RUST_TARGET_DIR").unwrap_or(format!("{}/../{}", rust_dir, "target/")); let fish_src_dir = format!("{}/{}", rust_dir, "../src/"); // Where cxx emits its header.