This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
/target
|
/target
|
||||||
/Cargo.lock
|
/Cargo.lock
|
||||||
|
/build-test
|
||||||
|
*.o
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
|||||||
@@ -34,16 +34,25 @@ fn find_static_lib(dir: &Path, base_name: &str, target_is_windows: bool) -> Opti
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lib_name_from_path(lib_path: &Path) -> Result<String, Box<dyn std::error::Error>> {
|
fn lib_name_from_path(
|
||||||
|
lib_path: &Path,
|
||||||
|
target_is_windows: bool,
|
||||||
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let file_name = lib_path
|
let file_name = lib_path
|
||||||
.file_stem()
|
.file_stem()
|
||||||
.ok_or(Error::msg("cannot get file stem"))?
|
.ok_or(Error::msg("cannot get file stem"))?
|
||||||
.to_str()
|
.to_str()
|
||||||
.ok_or(Error::msg("cannot into string"))?;
|
.ok_or(Error::msg("cannot into string"))?;
|
||||||
// cargo::rustc-link-lib=static=NAME tells the linker to find libNAME.a / NAME.lib,
|
// On Unix, `cargo::rustc-link-lib=static=NAME` makes the linker search for libNAME.a,
|
||||||
// so strip any leading "lib" prefix to avoid liblibNAME.
|
// so strip any leading "lib" prefix to avoid liblibNAME.a.
|
||||||
|
// On MSVC, the linker searches for NAME.lib directly, so keep the full name
|
||||||
|
// (e.g. libCZIAPIStatic.lib needs link-lib=static=libCZIAPIStatic).
|
||||||
|
if target_is_windows {
|
||||||
|
Ok(file_name.to_string())
|
||||||
|
} else {
|
||||||
Ok(file_name.strip_prefix("lib").unwrap_or(file_name).to_string())
|
Ok(file_name.strip_prefix("lib").unwrap_or(file_name).to_string())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Error(String);
|
struct Error(String);
|
||||||
|
|
||||||
@@ -124,6 +133,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let mut cmake_config = cmake::Config::new(&libczi_dir);
|
let mut cmake_config = cmake::Config::new(&libczi_dir);
|
||||||
cmake_config
|
cmake_config
|
||||||
.cxxflag("-fms-extensions")
|
.cxxflag("-fms-extensions")
|
||||||
|
.define(
|
||||||
|
"ADDITIONAL_LIBS_REQUIRED_FOR_ATOMIC",
|
||||||
|
"",
|
||||||
|
)
|
||||||
.define("LIBCZI_BUILD_UNITTESTS", "OFF")
|
.define("LIBCZI_BUILD_UNITTESTS", "OFF")
|
||||||
.define("LIBCZI_BUILD_CZICMD", "OFF")
|
.define("LIBCZI_BUILD_CZICMD", "OFF")
|
||||||
.define("LIBCZI_BUILD_DYNLIB", "OFF")
|
.define("LIBCZI_BUILD_DYNLIB", "OFF")
|
||||||
@@ -139,8 +152,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
if is_windows {
|
if is_windows {
|
||||||
cmake_config
|
cmake_config
|
||||||
.define("CMAKE_SYSTEM_NAME", "Windows")
|
.define("CMAKE_SYSTEM_NAME", "Windows")
|
||||||
.define("CRASH_ON_UNALIGNED_ACCESS", "FALSE")
|
.define("CRASH_ON_UNALIGNED_ACCESS", "FALSE");
|
||||||
.define("ADDITIONAL_LIBS_REQUIRED_FOR_ATOMIC", "");
|
|
||||||
|
|
||||||
let has_toolchain_file = env::var("TARGET_CMAKE_TOOLCHAIN_FILE").is_ok()
|
let has_toolchain_file = env::var("TARGET_CMAKE_TOOLCHAIN_FILE").is_ok()
|
||||||
|| env::var(format!(
|
|| env::var(format!(
|
||||||
@@ -161,7 +173,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
} else if target.contains("apple") {
|
} else if target.contains("apple") {
|
||||||
cmake_config
|
cmake_config
|
||||||
.define("CMAKE_SYSTEM_NAME", "Darwin")
|
.define("CMAKE_SYSTEM_NAME", "Darwin")
|
||||||
.define("ADDITIONAL_LIBS_REQUIRED_FOR_ATOMIC", "")
|
|
||||||
.define("CRASH_ON_UNALIGNED_ACCESS", "OFF");
|
.define("CRASH_ON_UNALIGNED_ACCESS", "OFF");
|
||||||
if target.contains("aarch64") {
|
if target.contains("aarch64") {
|
||||||
cmake_config.define("NEON_INTRINSICS_CAN_BE_USED", "ON");
|
cmake_config.define("NEON_INTRINSICS_CAN_BE_USED", "ON");
|
||||||
@@ -235,7 +246,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let libcziapi_lib = find_static_lib(&libcziapi_dir, "libCZIAPIStatic", is_windows)
|
let libcziapi_lib = find_static_lib(&libcziapi_dir, "libCZIAPIStatic", is_windows)
|
||||||
.or_else(|| find_static_lib(&libcziapi_dir2, "libCZIAPIStatic", is_windows))
|
.or_else(|| find_static_lib(&libcziapi_dir2, "libCZIAPIStatic", is_windows))
|
||||||
.ok_or(Error::msg("cannot find libCZIAPIStatic for linking"))?;
|
.ok_or(Error::msg("cannot find libCZIAPIStatic for linking"))?;
|
||||||
let libcziapi_name = lib_name_from_path(&libcziapi_lib)?;
|
let libcziapi_name = lib_name_from_path(&libcziapi_lib, is_windows)?;
|
||||||
|
|
||||||
let profile = env::var("PROFILE")?;
|
let profile = env::var("PROFILE")?;
|
||||||
let libczi_base = match profile.as_str() {
|
let libczi_base = match profile.as_str() {
|
||||||
@@ -249,7 +260,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
"cannot find {} for linking",
|
"cannot find {} for linking",
|
||||||
libczi_base
|
libczi_base
|
||||||
)))?;
|
)))?;
|
||||||
let libczi_name = lib_name_from_path(&libczi_lib)?;
|
let libczi_name = lib_name_from_path(&libczi_lib, is_windows)?;
|
||||||
|
|
||||||
if libcziapi_dir.exists() {
|
if libcziapi_dir.exists() {
|
||||||
println!(
|
println!(
|
||||||
@@ -304,7 +315,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
let zstd_name = find_static_lib(&zstd_dir, "zstd_static", is_windows)
|
let zstd_name = find_static_lib(&zstd_dir, "zstd_static", is_windows)
|
||||||
.or_else(|| find_static_lib(&zstd_dir2, "zstd_static", is_windows))
|
.or_else(|| find_static_lib(&zstd_dir2, "zstd_static", is_windows))
|
||||||
.map(|p| lib_name_from_path(&p).unwrap_or_else(|_| "zstd_static".to_string()))
|
.map(|p| lib_name_from_path(&p, is_windows).unwrap_or_else(|_| "zstd_static".to_string()))
|
||||||
.unwrap_or_else(|| "zstd_static".to_string());
|
.unwrap_or_else(|| "zstd_static".to_string());
|
||||||
println!("cargo::rustc-link-lib=static={}", zstd_name);
|
println!("cargo::rustc-link-lib=static={}", zstd_name);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user