From 1bdb7dffaf6c50f969ed7a057e40f101c5bd3b5f Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 7 Mar 2023 12:47:30 -0600 Subject: [PATCH] Use `cargo build -Z build-std` for ASAN This is recommended and increases coverage. --- .github/workflows/main.yml | 2 ++ cmake/Rust.cmake | 10 ++++++++++ cmake/Tests.cmake | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 20b63e142..addedb616 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -89,6 +89,8 @@ jobs: with: # All -Z options require running nightly rust-version: nightly + # ASAN uses `cargo build -Zbuild-std` which requires the rust-src component + components: rust-src - name: Install deps run: | sudo apt install gettext libncurses5-dev libpcre2-dev python3-pip tmux diff --git a/cmake/Rust.cmake b/cmake/Rust.cmake index 8ff46cdb5..b6137d812 100644 --- a/cmake/Rust.cmake +++ b/cmake/Rust.cmake @@ -15,9 +15,19 @@ set(fish_rust_target "fish-rust") set(fish_autocxx_gen_dir "${CMAKE_BINARY_DIR}/fish-autocxx-gen/") +if(NOT DEFINED CARGO_FLAGS) + # Corrosion doesn't like an empty string as FLAGS. This is basically a no-op alternative. + # See https://github.com/corrosion-rs/corrosion/issues/356 + set(CARGO_FLAGS "--config" "foo=0") +endif() +if(DEFINED ASAN) + list(APPEND CARGO_FLAGS "-Z" "build-std") +endif() + corrosion_import_crate( MANIFEST_PATH "${CMAKE_SOURCE_DIR}/fish-rust/Cargo.toml" FEATURES "fish-ffi-tests" + FLAGS "${CARGO_FLAGS}" ) # We need the build dir because cxx puts our headers in there. diff --git a/cmake/Tests.cmake b/cmake/Tests.cmake index 68d87c6b1..5e900741e 100644 --- a/cmake/Tests.cmake +++ b/cmake/Tests.cmake @@ -193,7 +193,7 @@ endif() if(NOT DEFINED ASAN) add_test( NAME "cargo-test" - COMMAND cargo test --target-dir target ${cargo_target_opt} + COMMAND cargo test ${CARGO_FLAGS} --target-dir target ${cargo_target_opt} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/fish-rust" ) set_tests_properties("cargo-test" PROPERTIES SKIP_RETURN_CODE ${SKIP_RETURN_CODE}) @@ -202,7 +202,7 @@ endif() add_test( NAME "cargo-test-widestring" - COMMAND cargo test --target-dir target ${cargo_target_opt} + COMMAND cargo test ${CARGO_FLAGS} --target-dir target ${cargo_target_opt} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/fish-rust/widestring-suffix/" ) add_test_target("cargo-test-widestring")