- do not edit source files in build.rs
This commit is contained in:
@@ -74,46 +74,6 @@ impl Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn restore_importexport(libcziapi_inc: &Path) -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let header = libcziapi_inc.join("importexport.h");
|
|
||||||
let relative = header.strip_prefix("libczi").unwrap_or(&header);
|
|
||||||
let status = std::process::Command::new("git")
|
|
||||||
.args(["checkout", "HEAD", "--", relative.to_str().unwrap()])
|
|
||||||
.current_dir("libczi")
|
|
||||||
.status()?;
|
|
||||||
if !status.success() {
|
|
||||||
return Err(Error::msg("failed to restore importexport.h"));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ImportExportGuard<'a> {
|
|
||||||
libcziapi_inc: &'a Path,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for ImportExportGuard<'a> {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
if let Err(e) = restore_importexport(self.libcziapi_inc) {
|
|
||||||
eprintln!("warning: failed to restore importexport.h: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn patch_importexport(
|
|
||||||
libcziapi_inc: &Path,
|
|
||||||
) -> Result<ImportExportGuard<'_>, Box<dyn std::error::Error>> {
|
|
||||||
let path = libcziapi_inc.join("importexport.h");
|
|
||||||
let original = std::fs::read_to_string(&path)?;
|
|
||||||
let patched = original.replace(
|
|
||||||
"#define EXTERNALLIBCZIAPI_API(_returntype_) _returntype_",
|
|
||||||
"#define EXTERNALLIBCZIAPI_API(_returntype_) extern \"C\" _returntype_",
|
|
||||||
);
|
|
||||||
if patched != original {
|
|
||||||
std::fs::write(&path, &patched)?;
|
|
||||||
}
|
|
||||||
Ok(ImportExportGuard { libcziapi_inc })
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fix_xwin_lib_case() -> Result<(), Box<dyn std::error::Error>> {
|
fn fix_xwin_lib_case() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let toolchain_key = format!(
|
let toolchain_key = format!(
|
||||||
"CMAKE_TOOLCHAIN_FILE_{}",
|
"CMAKE_TOOLCHAIN_FILE_{}",
|
||||||
@@ -174,6 +134,7 @@ 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")
|
||||||
|
.cxxflag("-DLIBCZIAPI_EXPORTS_SHARED")
|
||||||
.define("ADDITIONAL_LIBS_REQUIRED_FOR_ATOMIC", "")
|
.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")
|
||||||
@@ -226,13 +187,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
cmake_config.build_target("libCZIAPIStatic");
|
cmake_config.build_target("libCZIAPIStatic");
|
||||||
}
|
}
|
||||||
|
|
||||||
let _importexport_guard = patch_importexport(&libcziapi_inc)?;
|
|
||||||
let dst = cmake_config.build();
|
let dst = cmake_config.build();
|
||||||
|
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
.merge_extern_blocks(true)
|
.merge_extern_blocks(true)
|
||||||
.clang_args([
|
.clang_args([
|
||||||
"-fms-extensions",
|
"-fms-extensions",
|
||||||
|
"-DLIBCZIAPI_EXPORTS_SHARED",
|
||||||
"-x",
|
"-x",
|
||||||
"c++",
|
"c++",
|
||||||
"-std=c++14",
|
"-std=c++14",
|
||||||
|
|||||||
Reference in New Issue
Block a user