2024-11-29 03:00:34 +08:00
|
|
|
# Trying to build using the resolved toolchain causes all kinds of weird errors
|
|
|
|
# Just let rustup do its job
|
|
|
|
set(Rust_RESOLVE_RUSTUP_TOOLCHAINS Off)
|
|
|
|
|
2024-01-25 19:58:50 +08:00
|
|
|
include(FindRust)
|
|
|
|
find_package(Rust REQUIRED)
|
2023-03-30 12:01:23 +08:00
|
|
|
|
2024-01-25 19:58:50 +08:00
|
|
|
set(FISH_RUST_BUILD_DIR "${CMAKE_BINARY_DIR}/cargo/build")
|
2023-01-15 06:56:24 +08:00
|
|
|
|
2023-03-08 02:47:30 +08:00
|
|
|
if(DEFINED ASAN)
|
|
|
|
list(APPEND CARGO_FLAGS "-Z" "build-std")
|
2024-01-25 19:58:50 +08:00
|
|
|
list(APPEND FISH_CRATE_FEATURES "asan")
|
2023-03-08 02:47:30 +08:00
|
|
|
endif()
|
2024-08-04 16:18:06 +08:00
|
|
|
if(DEFINED TSAN)
|
|
|
|
list(APPEND CARGO_FLAGS "-Z" "build-std")
|
|
|
|
list(APPEND FISH_CRATE_FEATURES "tsan")
|
|
|
|
endif()
|
2023-03-08 02:47:30 +08:00
|
|
|
|
2024-01-12 15:25:06 +08:00
|
|
|
if (Rust_CARGO_TARGET)
|
2024-01-25 19:58:50 +08:00
|
|
|
set(rust_target_dir "${FISH_RUST_BUILD_DIR}/${Rust_CARGO_TARGET}")
|
2024-01-12 15:25:06 +08:00
|
|
|
else()
|
2024-01-25 19:58:50 +08:00
|
|
|
set(rust_target_dir "${FISH_RUST_BUILD_DIR}/${Rust_CARGO_HOST_TARGET}")
|
2024-01-12 15:25:06 +08:00
|
|
|
endif()
|
|
|
|
|
2024-01-25 19:58:50 +08:00
|
|
|
set(rust_profile $<IF:$<CONFIG:Debug>,debug,release>)
|
2024-08-04 19:00:00 +08:00
|
|
|
set(rust_debugflags "$<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g>")
|
2024-02-08 00:28:28 +08:00
|
|
|
|
2024-01-25 19:58:50 +08:00
|
|
|
|
2023-05-17 02:02:22 +08:00
|
|
|
# Temporary hack to propogate CMake flags/options to build.rs. We need to get CMake to evaluate the
|
|
|
|
# truthiness of the strings if they are set.
|
|
|
|
set(CMAKE_WITH_GETTEXT "1")
|
|
|
|
if(DEFINED WITH_GETTEXT AND NOT "${WITH_GETTEXT}")
|
|
|
|
set(CMAKE_WITH_GETTEXT "0")
|
|
|
|
endif()
|
|
|
|
|
2024-01-25 19:58:50 +08:00
|
|
|
if(FISH_CRATE_FEATURES)
|
|
|
|
set(FEATURES_ARG ${FISH_CRATE_FEATURES})
|
|
|
|
list(PREPEND FEATURES_ARG "--features")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_property(
|
|
|
|
RUSTC_EXECUTABLE
|
|
|
|
TARGET Rust::Rustc PROPERTY IMPORTED_LOCATION
|
|
|
|
)
|
|
|
|
|
2024-07-08 06:50:58 +08:00
|
|
|
# Tell Cargo where our build directory is so it can find Cargo.toml.
|
2024-01-12 19:00:38 +08:00
|
|
|
set(VARS_FOR_CARGO
|
2024-08-04 16:18:06 +08:00
|
|
|
"FISH_BUILD_DIR=${CMAKE_BINARY_DIR}"
|
2023-04-09 20:33:20 +08:00
|
|
|
"PREFIX=${CMAKE_INSTALL_PREFIX}"
|
2023-05-17 02:02:22 +08:00
|
|
|
# Temporary hack to propogate CMake flags/options to build.rs.
|
|
|
|
"CMAKE_WITH_GETTEXT=${CMAKE_WITH_GETTEXT}"
|
2023-09-06 15:35:56 +08:00
|
|
|
"DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}"
|
|
|
|
"DATADIR=${CMAKE_INSTALL_FULL_DATADIR}"
|
|
|
|
"SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}"
|
|
|
|
"BINDIR=${CMAKE_INSTALL_FULL_BINDIR}"
|
2024-01-02 03:39:38 +08:00
|
|
|
"LOCALEDIR=${CMAKE_INSTALL_FULL_LOCALEDIR}"
|
2024-01-25 19:58:50 +08:00
|
|
|
"CARGO_TARGET_DIR=${FISH_RUST_BUILD_DIR}"
|
|
|
|
"CARGO_BUILD_RUSTC=${RUSTC_EXECUTABLE}"
|
2024-10-06 11:15:29 +08:00
|
|
|
"${FISH_PCRE2_BUILDFLAG}"
|
2024-02-08 00:28:28 +08:00
|
|
|
"RUSTFLAGS=$ENV{RUSTFLAGS} ${rust_debugflags}"
|
2023-04-19 22:45:25 +08:00
|
|
|
)
|