This commit is contained in:
@@ -34,15 +34,24 @@ fn find_static_lib(dir: &Path, base_name: &str, target_is_windows: bool) -> Opti
|
||||
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
|
||||
.file_stem()
|
||||
.ok_or(Error::msg("cannot get file stem"))?
|
||||
.to_str()
|
||||
.ok_or(Error::msg("cannot into string"))?;
|
||||
// cargo::rustc-link-lib=static=NAME tells the linker to find libNAME.a / NAME.lib,
|
||||
// so strip any leading "lib" prefix to avoid liblibNAME.
|
||||
Ok(file_name.strip_prefix("lib").unwrap_or(file_name).to_string())
|
||||
// On Unix, `cargo::rustc-link-lib=static=NAME` makes the linker search for libNAME.a,
|
||||
// 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())
|
||||
}
|
||||
}
|
||||
|
||||
struct Error(String);
|
||||
@@ -124,6 +133,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut cmake_config = cmake::Config::new(&libczi_dir);
|
||||
cmake_config
|
||||
.cxxflag("-fms-extensions")
|
||||
.define(
|
||||
"ADDITIONAL_LIBS_REQUIRED_FOR_ATOMIC",
|
||||
"",
|
||||
)
|
||||
.define("LIBCZI_BUILD_UNITTESTS", "OFF")
|
||||
.define("LIBCZI_BUILD_CZICMD", "OFF")
|
||||
.define("LIBCZI_BUILD_DYNLIB", "OFF")
|
||||
@@ -139,8 +152,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if is_windows {
|
||||
cmake_config
|
||||
.define("CMAKE_SYSTEM_NAME", "Windows")
|
||||
.define("CRASH_ON_UNALIGNED_ACCESS", "FALSE")
|
||||
.define("ADDITIONAL_LIBS_REQUIRED_FOR_ATOMIC", "");
|
||||
.define("CRASH_ON_UNALIGNED_ACCESS", "FALSE");
|
||||
|
||||
let has_toolchain_file = env::var("TARGET_CMAKE_TOOLCHAIN_FILE").is_ok()
|
||||
|| env::var(format!(
|
||||
@@ -161,7 +173,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else if target.contains("apple") {
|
||||
cmake_config
|
||||
.define("CMAKE_SYSTEM_NAME", "Darwin")
|
||||
.define("ADDITIONAL_LIBS_REQUIRED_FOR_ATOMIC", "")
|
||||
.define("CRASH_ON_UNALIGNED_ACCESS", "OFF");
|
||||
if target.contains("aarch64") {
|
||||
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)
|
||||
.or_else(|| find_static_lib(&libcziapi_dir2, "libCZIAPIStatic", is_windows))
|
||||
.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 libczi_base = match profile.as_str() {
|
||||
@@ -249,7 +260,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
"cannot find {} for linking",
|
||||
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() {
|
||||
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)
|
||||
.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());
|
||||
println!("cargo::rustc-link-lib=static={}", zstd_name);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user