Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for current cc crate #216

Merged
merged 19 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exclude = [
"external/xmp_toolkit/third-party/zlib/README.md",
"external/xmp_toolkit/third-party/zlib/*.c",
"external/xmp_toolkit/third-party/zlib/*.h",
"external/xmp_toolkit/third-party/expat/lib",
"external/xmp_toolkit/third-party/expat/lib",
"external/xmp_toolkit/XMPFilesPlugins/PDF_Handler",
]

Expand All @@ -37,12 +37,7 @@ num_enum = "0.7.0"
thiserror = "1.0"

[build-dependencies]
cc = "> 1.0.60, <=1.0.83"
# IMPORTANT: We can not upgrade to 1.0.86 or later until
# https://github.com/adobe/xmp-toolkit-rs/issues/197 is resolved.
# If someone has time to address that issue before we get to it,
# a PR would be very welcome.

cc = "1.0.101"
fs_extra = "1.3"

[dev-dependencies]
Expand Down
68 changes: 26 additions & 42 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// specific language governing permissions and limitations under
// each license.

use std::{env, ffi::OsStr, path::PathBuf};
use std::{env, ffi::OsStr};

fn main() {
println!("cargo:rerun-if-changed=build.rs");
Expand Down Expand Up @@ -45,8 +45,10 @@ fn main() {
zlib_adler_c_path.push("external/xmp_toolkit/third-party/zlib/adler.c");
if !zlib_adler_c_path.is_file() {
zlib_adler_c_path.pop();
let _ignore = std::fs::remove_dir_all(zlib_adler_c_path);
println!("Copying zlib to third_party dir ...");
copy_external_to_third_party("zlib", "zlib");
} else {
eprintln!("Huh. zlib already exists. NOT COPYING");
}

// C vs C++ compilation approach adapted from
Expand Down Expand Up @@ -168,7 +170,7 @@ fn main() {
}
};

expat_config
let expat_intermediates = expat_config
.cpp(false)
.define("HAVE_EXPAT_CONFIG_H", "1")
.define("NDEBUG", "")
Expand All @@ -179,34 +181,11 @@ fn main() {
.file("external/xmp_toolkit/third-party/expat/lib/xmlrole.c")
.file("external/xmp_toolkit/third-party/expat/lib/xmltok.c")
.cargo_metadata(false)
.compile("libexpat.a");

let out_dir = env::var("OUT_DIR").expect("OUT_DIR not defined");
println!("cargo:rustc-link-search=native={}", &out_dir);

let mut expat_dir = PathBuf::from(&out_dir);
expat_dir.push("external/xmp_toolkit/third-party/expat/lib");
.compile_intermediates();

let mut count = 0;
for entry in std::fs::read_dir(&expat_dir).unwrap() {
let obj = entry.unwrap().path().canonicalize().unwrap();
if let Some(ext) = obj.extension() {
if ext == "o" {
xmp_config.object(&obj);
count += 1;
}
}
for expat_int in expat_intermediates {
xmp_config.object(expat_int);
}
assert_eq!(
count, 3,
"Didn't find expected object files from {:?}",
&out_dir
);

println!(
"cargo:include={}/external/xmp_toolkit/public/include",
std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get CARGO_MANIFEST_DIR")
);

xmp_config
.cpp(true)
Expand All @@ -224,7 +203,10 @@ fn main() {
.flag_if_supported("-Wno-unused-variable")
.flag_if_supported("-Wnon-virtual-dtor")
.flag_if_supported("-Woverloaded-virtual")
.include("external/xmp_toolkit")
.include(format!(
"{root}/external/xmp_toolkit",
root = std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get CARGO_MANIFEST_DIR")
))
.include("external/xmp_toolkit/build")
.include("external/xmp_toolkit/public/include")
.include("external/xmp_toolkit/XMPFilesPlugins/api/source")
Expand Down Expand Up @@ -345,7 +327,7 @@ fn main() {
.file("external/xmp_toolkit/third-party/zlib/zutil.c")
.file("src/ffi.cpp")
.file("external/xmp_toolkit/third-party/zuid/interfaces/MD5.cpp")
.compile("libxmp.a");
.compile("xmp");
}

fn copy_external_to_third_party(from_path: &str, to_path: &str) {
Expand All @@ -355,19 +337,21 @@ fn copy_external_to_third_party(from_path: &str, to_path: &str) {
dest_path.push("external/xmp_toolkit/third-party");
dest_path.push(to_path);

if !dest_path.is_dir() {
let mut src_path = env::current_dir().unwrap();
src_path.push("external");
src_path.push(from_path);
if dest_path.is_dir() {
std::fs::remove_dir_all(&dest_path).unwrap();
}

assert!(src_path.is_dir());
let mut src_path = env::current_dir().unwrap();
src_path.push("external");
src_path.push(from_path);

dest_path.pop();
assert!(src_path.is_dir());

let copy_options = CopyOptions::new();
println!("COPYING {} to {}", src_path.display(), dest_path.display());
copy(src_path, dest_path, &copy_options).unwrap();
}
dest_path.pop();

let copy_options = CopyOptions::new();
println!("COPYING {} to {}", src_path.display(), dest_path.display());
copy(src_path, dest_path, &copy_options).unwrap();
}

fn git_command<I, S>(args: I)
Expand Down Expand Up @@ -454,5 +438,5 @@ fn compile_for_docs() {
.include("external/xmp_toolkit/public/include")
.include("external/xmp_toolkit/XMPFilesPlugins/api/source")
.file("src/ffi.cpp")
.compile("libxmp.a");
.compile("xmp");
}
Loading