- make the build self-contained and cross-compile friendly: vendor the Eigen 3.4.0 headers (instead of the flaky gitlab clone / a system libeigen3-dev package), align the msvc C runtime with the dynamic one used by the rest of cross builds (xwin), and pass the -D_LIBCPP_* macros to bindgen so it parses zig's bundled libc++ regardless of ziglang/cargo-zigbuild versions
This commit is contained in:
1 parent
3860af8815
commit
d6fe6ec733
342 files changed
+149037
-3
No files matched your search
@@ -133,6 +133,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let libcziapi_src = libczi_dir.join("Src/libCZIAPI/src");
|
||||
let libcziapi_h = libcziapi_inc.join("libCZIApi.h");
|
||||
|
||||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
|
||||
let mut cmake_config = cmake::Config::new(&libczi_dir);
|
||||
cmake_config
|
||||
.cxxflag("-fms-extensions")
|
||||
@@ -141,19 +142,32 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.define("LIBCZI_BUILD_UNITTESTS", "OFF")
|
||||
.define("LIBCZI_BUILD_CZICMD", "OFF")
|
||||
.define("LIBCZI_BUILD_DYNLIB", "OFF")
|
||||
.define("LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_EIGEN3", "OFF")
|
||||
.define("LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_ZSTD", "OFF")
|
||||
.define("LIBCZI_BUILD_CURL_BASED_STREAM", "OFF")
|
||||
.define("LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_LIBCURL", "OFF")
|
||||
.define("LIBCZI_BUILD_AZURESDK_BASED_STREAM", "OFF")
|
||||
.define("LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_RAPIDJSON", "OFF")
|
||||
.define("LIBCZI_BUILD_LIBCZIAPI", "ON");
|
||||
.define("LIBCZI_BUILD_LIBCZIAPI", "ON")
|
||||
// vendored Eigen 3.4.0 headers (eigen/, see its README) so neither a
|
||||
// network clone (libCZI's gitlab ExternalProject) nor a system
|
||||
// libeigen3-dev package is required; Eigen3_DIR finds the package
|
||||
// via eigen/Eigen3Config.cmake
|
||||
.define("LIBCZI_BUILD_PREFER_EXTERNALPACKAGE_EIGEN3", "ON")
|
||||
.define("Eigen3_DIR", manifest_dir.join("eigen"));
|
||||
|
||||
if is_cross {
|
||||
if is_windows {
|
||||
cmake_config
|
||||
.define("CMAKE_SYSTEM_NAME", "Windows")
|
||||
.define("CRASH_ON_UNALIGNED_ACCESS", "FALSE");
|
||||
.define("CRASH_ON_UNALIGNED_ACCESS", "FALSE")
|
||||
// the rest of the cross build (Rust std, cc-rs-compiled
|
||||
// vendored code) uses the dynamic C runtime (/MD), but
|
||||
// libCZI hardwires the static one (/MT); the MSVC linker
|
||||
// (lld-link) rejects the mix. Use libCZI's upstream option
|
||||
// to leave the runtime choice to CMake, aligned with
|
||||
// the dynamic runtime (only affects the msvc target)
|
||||
.define("LIBCZI_DO_NOT_SET_MSVC_RUNTIME_LIBRARY", "ON")
|
||||
.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreadedDLL$<$<CONFIG:Debug>:Debug>");
|
||||
|
||||
let has_toolchain_file = env::var("TARGET_CMAKE_TOOLCHAIN_FILE").is_ok()
|
||||
|| env::var(format!("CMAKE_TOOLCHAIN_FILE_{}", target.replace('-', "_")))
|
||||
@@ -212,6 +226,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.to_str()
|
||||
.ok_or(Error::msg("cannot into string"))?,
|
||||
])
|
||||
// cargo-zigbuild puts zig's bundled libc++ on the include path
|
||||
// (CPATH); its hardening.h requires the -D_LIBCPP_* config macros.
|
||||
// Pass them ourselves so parsing works with any ziglang /
|
||||
// cargo-zigbuild version (they are ignored by other stdlibs)
|
||||
.clang_args([
|
||||
"-D_LIBCPP_ASSERTION_SEMANTIC_DEFAULT=_LIBCPP_ASSERTION_SEMANTIC_ENFORCE",
|
||||
"-D_LIBCPP_PSTL_BACKEND_SERIAL",
|
||||
"-D_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS=0",
|
||||
"-D_LIBCPP_HAS_TERMINAL",
|
||||
"-D_LIBCPP_HAS_RANDOM_DEVICE",
|
||||
"-D_LIBCPP_HAS_NO_STD_MODULES",
|
||||
"-D_LIBCPP_HAS_FILESYSTEM=1",
|
||||
])
|
||||
.header(
|
||||
libcziapi_h
|
||||
.to_str()
|
||||
|
||||
Reference in new issue
Block a user