2024-11-28 19:00:34 +00: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 11:58:50 +00:00
|
|
|
include(FindRust)
|
|
|
|
find_package(Rust REQUIRED)
|
2023-03-30 04:01:23 +00:00
|
|
|
|
2024-01-25 11:58:50 +00:00
|
|
|
set(FISH_RUST_BUILD_DIR "${CMAKE_BINARY_DIR}/cargo/build")
|
2023-01-14 22:56:24 +00:00
|
|
|
|
2023-03-07 18:47:30 +00:00
|
|
|
if(DEFINED ASAN)
|
|
|
|
list(APPEND CARGO_FLAGS "-Z" "build-std")
|
2024-01-25 11:58:50 +00:00
|
|
|
list(APPEND FISH_CRATE_FEATURES "asan")
|
2023-03-07 18:47:30 +00:00
|
|
|
endif()
|
2024-08-04 08:18:06 +00:00
|
|
|
if(DEFINED TSAN)
|
|
|
|
list(APPEND CARGO_FLAGS "-Z" "build-std")
|
|
|
|
list(APPEND FISH_CRATE_FEATURES "tsan")
|
|
|
|
endif()
|
2023-03-07 18:47:30 +00:00
|
|
|
|
2024-01-12 07:25:06 +00:00
|
|
|
if (Rust_CARGO_TARGET)
|
2024-01-25 11:58:50 +00:00
|
|
|
set(rust_target_dir "${FISH_RUST_BUILD_DIR}/${Rust_CARGO_TARGET}")
|
2024-01-12 07:25:06 +00:00
|
|
|
else()
|
2024-01-25 11:58:50 +00:00
|
|
|
set(rust_target_dir "${FISH_RUST_BUILD_DIR}/${Rust_CARGO_HOST_TARGET}")
|
2024-01-12 07:25:06 +00:00
|
|
|
endif()
|
|
|
|
|
2024-01-25 11:58:50 +00:00
|
|
|
set(rust_profile $<IF:$<CONFIG:Debug>,debug,release>)
|
2024-08-04 11:00:00 +00:00
|
|
|
set(rust_debugflags "$<$<CONFIG:Debug>:-g>$<$<CONFIG:RelWithDebInfo>:-g>")
|
2024-02-07 16:28:28 +00:00
|
|
|
|
2024-01-25 11:58:50 +00:00
|
|
|
|
2023-05-16 18:02:22 +00: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 11:58:50 +00: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-07 22:50:58 +00:00
|
|
|
# Tell Cargo where our build directory is so it can find Cargo.toml.
|
2024-01-12 11:00:38 +00:00
|
|
|
set(VARS_FOR_CARGO
|
2024-08-04 08:18:06 +00:00
|
|
|
"FISH_BUILD_DIR=${CMAKE_BINARY_DIR}"
|
2023-04-09 12:33:20 +00:00
|
|
|
"PREFIX=${CMAKE_INSTALL_PREFIX}"
|
2023-05-16 18:02:22 +00:00
|
|
|
# Temporary hack to propogate CMake flags/options to build.rs.
|
|
|
|
"CMAKE_WITH_GETTEXT=${CMAKE_WITH_GETTEXT}"
|
2023-09-06 07:35:56 +00:00
|
|
|
"DOCDIR=${CMAKE_INSTALL_FULL_DOCDIR}"
|
|
|
|
"DATADIR=${CMAKE_INSTALL_FULL_DATADIR}"
|
|
|
|
"SYSCONFDIR=${CMAKE_INSTALL_FULL_SYSCONFDIR}"
|
|
|
|
"BINDIR=${CMAKE_INSTALL_FULL_BINDIR}"
|
2024-01-01 19:39:38 +00:00
|
|
|
"LOCALEDIR=${CMAKE_INSTALL_FULL_LOCALEDIR}"
|
2024-01-25 11:58:50 +00:00
|
|
|
"CARGO_TARGET_DIR=${FISH_RUST_BUILD_DIR}"
|
|
|
|
"CARGO_BUILD_RUSTC=${RUSTC_EXECUTABLE}"
|
2024-10-06 03:15:29 +00:00
|
|
|
"${FISH_PCRE2_BUILDFLAG}"
|
2024-02-07 16:28:28 +00:00
|
|
|
"RUSTFLAGS=$ENV{RUSTFLAGS} ${rust_debugflags}"
|
2023-04-19 14:45:25 +00:00
|
|
|
)
|