mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-23 02:41:14 -03:00
Rust has multiple sanitizers available (with llvm integration). -Zsanitizer=address catches the most likely culprits but we may want to set up a separate job w/ -Zsanitizer=memory to catch uninitialized reads. It might be necessary to execute `cargo build` as `cargo build -Zbuild-std` to get full coverage. When we're linking against the hybrid C++ codebase, the sanitizer library is injected into the binary by also include `-fsanitize=address` in CXXFLAGS - we do *not* want to manually opt-into `-lasan`. We also need to manually specify the desired target triple as a CMake variable and then explicitly pass it to all `cargo` invocations if building with ASAN. Corrosion has been patched to make sure it follows these rules. The `cargo-test` target is failing to link under ASAN. For some reason it has autocxx/ffi dependencies even though only rust-native, ffi-free code should be tested (and one would think the situation wouldn't change depending on the presence of the sanitizer flag). It's been disabled under ASAN for now.
50 lines
1.6 KiB
CMake
50 lines
1.6 KiB
CMake
include(FetchContent)
|
|
|
|
# Don't let Corrosion's tests interfere with ours.
|
|
set(CORROSION_TESTS OFF CACHE BOOL "" FORCE)
|
|
|
|
FetchContent_Declare(
|
|
Corrosion
|
|
GIT_REPOSITORY https://github.com/mqudsi/corrosion
|
|
GIT_TAG fish
|
|
)
|
|
|
|
FetchContent_MakeAvailable(Corrosion)
|
|
|
|
set(fish_rust_target "fish-rust")
|
|
|
|
set(fish_autocxx_gen_dir "${CMAKE_BINARY_DIR}/fish-autocxx-gen/")
|
|
|
|
corrosion_import_crate(
|
|
MANIFEST_PATH "${CMAKE_SOURCE_DIR}/fish-rust/Cargo.toml"
|
|
FEATURES "fish-ffi-tests"
|
|
)
|
|
|
|
# We need the build dir because cxx puts our headers in there.
|
|
# Corrosion doesn't expose the build dir, so poke where we shouldn't.
|
|
if (Rust_CARGO_TARGET)
|
|
set(rust_target_dir "${CMAKE_BINARY_DIR}/cargo/build/${_CORROSION_RUST_CARGO_TARGET}")
|
|
else()
|
|
set(rust_target_dir "${CMAKE_BINARY_DIR}/cargo/build/${_CORROSION_RUST_CARGO_HOST_TARGET}")
|
|
corrosion_set_hostbuild(${fish_rust_target})
|
|
endif()
|
|
|
|
# Tell Cargo where our build directory is so it can find config.h.
|
|
corrosion_set_env_vars(${fish_rust_target} "FISH_BUILD_DIR=${CMAKE_BINARY_DIR}" "FISH_AUTOCXX_GEN_DIR=${fish_autocxx_gen_dir}" "FISH_RUST_TARGET_DIR=${rust_target_dir}")
|
|
|
|
target_include_directories(${fish_rust_target} INTERFACE
|
|
"${rust_target_dir}/cxxbridge/${fish_rust_target}/src/"
|
|
"${fish_autocxx_gen_dir}/include/"
|
|
)
|
|
|
|
# Tell fish what extra C++ files to compile.
|
|
define_property(
|
|
TARGET PROPERTY fish_extra_cpp_files
|
|
BRIEF_DOCS "Extra C++ files to compile for fish."
|
|
FULL_DOCS "Extra C++ files to compile for fish."
|
|
)
|
|
|
|
set_property(TARGET ${fish_rust_target} PROPERTY fish_extra_cpp_files
|
|
"${fish_autocxx_gen_dir}/cxx/gen0.cxx"
|
|
)
|