From a2cdf129115d95213b32e43cea78417d6100fb35 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Wed, 19 Jun 2024 20:52:42 -0600 Subject: [PATCH 01/18] WIP on resolving cc build issues --- Cargo.toml | 9 ++------- build.rs | 26 ++++---------------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9b97917..c403c35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", ] @@ -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" fs_extra = "1.3" [dev-dependencies] diff --git a/build.rs b/build.rs index 8dff97f..97e159e 100644 --- a/build.rs +++ b/build.rs @@ -179,29 +179,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"); + .compile("expat"); 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"); - - 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; - } - } - } - assert_eq!( - count, 3, - "Didn't find expected object files from {:?}", - &out_dir - ); + // ^^ Is this still needed? println!( "cargo:include={}/external/xmp_toolkit/public/include", @@ -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) { @@ -454,5 +436,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"); } From a368597e6783719803b08a4ff2bbb970cb1cf67e Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Wed, 19 Jun 2024 21:48:02 -0600 Subject: [PATCH 02/18] Remove no-longer-needed import of std::path::PathBuf --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 97e159e..a497048 100644 --- a/build.rs +++ b/build.rs @@ -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"); From 5c5f505bf753722cc46e24c847137d19e48ce894 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Thu, 20 Jun 2024 12:06:50 -0600 Subject: [PATCH 03/18] Attempt to update to current cc crate and update build process MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (Failing so far …) --- Cargo.toml | 2 +- build.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c403c35..437f0a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ num_enum = "0.7.0" thiserror = "1.0" [build-dependencies] -cc = "1.0" +cc = "1.0.86" fs_extra = "1.3" [dev-dependencies] diff --git a/build.rs b/build.rs index a497048..63b26e1 100644 --- a/build.rs +++ b/build.rs @@ -11,7 +11,7 @@ // specific language governing permissions and limitations under // each license. -use std::{env, ffi::OsStr}; +use std::{env, ffi::OsStr, path::PathBuf}; fn main() { println!("cargo:rerun-if-changed=build.rs"); @@ -45,15 +45,18 @@ 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); copy_external_to_third_party("zlib", "zlib"); } + let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR not defined"); + let out_dir = PathBuf::from(out_dir); + // C vs C++ compilation approach adapted from // https://github.com/rust-lang/rust/blob/7510b0ca45d1204f8f0e9dc1bb2dc7d95b279c9a/library/unwind/build.rs. let mut expat_config = cc::Build::new(); let mut xmp_config = cc::Build::new(); + xmp_config.include(out_dir.join("external/xmp_toolkit")); let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not defined"); match target_os.as_ref() { From 13a9fdc93a1fee97c5cea0f6bcc8bba40af3c3c6 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Thu, 20 Jun 2024 21:55:53 -0600 Subject: [PATCH 04/18] Another approach to resolving public/include path ref --- build.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/build.rs b/build.rs index 63b26e1..6c488b5 100644 --- a/build.rs +++ b/build.rs @@ -48,15 +48,11 @@ fn main() { copy_external_to_third_party("zlib", "zlib"); } - let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR not defined"); - let out_dir = PathBuf::from(out_dir); - // C vs C++ compilation approach adapted from // https://github.com/rust-lang/rust/blob/7510b0ca45d1204f8f0e9dc1bb2dc7d95b279c9a/library/unwind/build.rs. let mut expat_config = cc::Build::new(); let mut xmp_config = cc::Build::new(); - xmp_config.include(out_dir.join("external/xmp_toolkit")); let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not defined"); match target_os.as_ref() { @@ -188,10 +184,10 @@ fn main() { println!("cargo:rustc-link-search=native={}", &out_dir); // ^^ Is this still needed? - println!( - "cargo:include={}/external/xmp_toolkit/public/include", - std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get CARGO_MANIFEST_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) @@ -209,7 +205,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") From d3f56ac51b41bb2f4d085164dd0ae9d7f9211cdb Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Thu, 20 Jun 2024 22:21:41 -0600 Subject: [PATCH 05/18] Argh. Seeing different behavior on local Mac than GH runners --- build.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/build.rs b/build.rs index 6c488b5..627b188 100644 --- a/build.rs +++ b/build.rs @@ -189,6 +189,26 @@ fn main() { // std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get // CARGO_MANIFEST_DIR") ); + if let Ok(output) = std::process::Command::new("pwd").output() { + println!( + "*** pwd foo\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", + String::from_utf8(output.stdout).unwrap(), + String::from_utf8(output.stderr).unwrap() + ); + }; + + if let Ok(output) = std::process::Command::new("ls") + .arg("-al") + .arg("external/xmp-toolkit") + .output() + { + println!( + "*** ls -al foo\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", + String::from_utf8(output.stdout).unwrap(), + String::from_utf8(output.stderr).unwrap() + ); + }; + xmp_config .cpp(true) .define("TXMP_STRING_TYPE", "std::string") From 290cc009198e95537d3b99d293f3a7231658a06d Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Thu, 20 Jun 2024 22:39:22 -0600 Subject: [PATCH 06/18] zlib? zlib? anybody home? zlib --- build.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 627b188..8155c82 100644 --- a/build.rs +++ b/build.rs @@ -199,11 +199,11 @@ fn main() { if let Ok(output) = std::process::Command::new("ls") .arg("-al") - .arg("external/xmp-toolkit") + .arg("/Users/runner/work/xmp-toolkit-rs/xmp-toolkit-rs/external/xmp_toolkit/third-party/zlib") .output() { println!( - "*** ls -al foo\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", + "*** ls -al .../third-party/zlib\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", String::from_utf8(output.stdout).unwrap(), String::from_utf8(output.stderr).unwrap() ); From b4062770bd7e538e7eec74ef8d9c0ff2787da7a6 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Thu, 20 Jun 2024 22:43:54 -0600 Subject: [PATCH 07/18] Moar debugging --- build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.rs b/build.rs index 8155c82..06adf61 100644 --- a/build.rs +++ b/build.rs @@ -45,7 +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(); + 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 From 956f9909865b8addc7f1373c4abe83a059ef404f Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sat, 22 Jun 2024 21:38:44 -0600 Subject: [PATCH 08/18] Remove unnecessary import --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 06adf61..962e38c 100644 --- a/build.rs +++ b/build.rs @@ -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"); From 1e04d3366c15fbe2a5bac431e5a4147a0a991d9e Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sat, 22 Jun 2024 21:38:58 -0600 Subject: [PATCH 09/18] Tweak debug params --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 962e38c..3be4ac1 100644 --- a/build.rs +++ b/build.rs @@ -202,7 +202,7 @@ fn main() { if let Ok(output) = std::process::Command::new("ls") .arg("-al") - .arg("/Users/runner/work/xmp-toolkit-rs/xmp-toolkit-rs/external/xmp_toolkit/third-party/zlib") + .arg("external/xmp_toolkit/third-party/zlib") .output() { println!( From ac64d3a30d7fcb5ceab5921c2878312efe3d03fd Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sat, 22 Jun 2024 21:42:01 -0600 Subject: [PATCH 10/18] zlib.h? zlib.h? Bueller? Bueller? --- build.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 3be4ac1..5948fc7 100644 --- a/build.rs +++ b/build.rs @@ -200,13 +200,14 @@ fn main() { ); }; - if let Ok(output) = std::process::Command::new("ls") - .arg("-al") - .arg("external/xmp_toolkit/third-party/zlib") + if let Ok(output) = std::process::Command::new("find") + .arg(".") + .arg("-name") + .arg("zlib.h") .output() { println!( - "*** ls -al .../third-party/zlib\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", + "*** find . -name zlib.h\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", String::from_utf8(output.stdout).unwrap(), String::from_utf8(output.stderr).unwrap() ); From db7c936fcb040cc15c91af506e7c0f40e6da1c22 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sat, 22 Jun 2024 21:58:06 -0600 Subject: [PATCH 11/18] Huh --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index 5948fc7..de290c9 100644 --- a/build.rs +++ b/build.rs @@ -375,6 +375,8 @@ fn copy_external_to_third_party(from_path: &str, to_path: &str) { let copy_options = CopyOptions::new(); println!("COPYING {} to {}", src_path.display(), dest_path.display()); copy(src_path, dest_path, ©_options).unwrap(); + } else { + eprintln!("Huh. dest_path {destpath} was already a dir -- didn't copy"); } } From 4ee1e4a508dd70026881f09076f805983cdb19fd Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sat, 22 Jun 2024 22:04:12 -0600 Subject: [PATCH 12/18] =?UTF-8?q?My=20kingdom=20for=20a=20well-placed=20un?= =?UTF-8?q?derscore=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index de290c9..04a0fae 100644 --- a/build.rs +++ b/build.rs @@ -376,7 +376,7 @@ fn copy_external_to_third_party(from_path: &str, to_path: &str) { println!("COPYING {} to {}", src_path.display(), dest_path.display()); copy(src_path, dest_path, ©_options).unwrap(); } else { - eprintln!("Huh. dest_path {destpath} was already a dir -- didn't copy"); + eprintln!("Huh. dest_path {dest_path} was already a dir -- didn't copy"); } } From ad729e325be7b0ce91a66eb823687b380aed289e Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sat, 22 Jun 2024 22:06:28 -0600 Subject: [PATCH 13/18] =?UTF-8?q?Details,=20details=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 04a0fae..dc4bc0b 100644 --- a/build.rs +++ b/build.rs @@ -376,7 +376,7 @@ fn copy_external_to_third_party(from_path: &str, to_path: &str) { println!("COPYING {} to {}", src_path.display(), dest_path.display()); copy(src_path, dest_path, ©_options).unwrap(); } else { - eprintln!("Huh. dest_path {dest_path} was already a dir -- didn't copy"); + eprintln!("Huh. dest_path {dest_path:?} was already a dir -- didn't copy"); } } From ae1b151693ebcb2283046fd3f91c8b9dbee8a8a6 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 7 Jul 2024 11:56:54 -0700 Subject: [PATCH 14/18] =?UTF-8?q?That=20works!=20Now=20we=20refine=20?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index dc4bc0b..86bd811 100644 --- a/build.rs +++ b/build.rs @@ -170,7 +170,7 @@ fn main() { } }; - expat_config + let expat_intermediates = expat_config .cpp(false) .define("HAVE_EXPAT_CONFIG_H", "1") .define("NDEBUG", "") @@ -181,7 +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("expat"); + .compile_intermediates(); + + for expat_int in expat_intermediates { + xmp_config.object(expat_int); + } let out_dir = env::var("OUT_DIR").expect("OUT_DIR not defined"); println!("cargo:rustc-link-search=native={}", &out_dir); From d059c9941b0768b37fdad40092abefde3b2960a8 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 7 Jul 2024 11:59:46 -0700 Subject: [PATCH 15/18] Remove items that are no longer needed --- build.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/build.rs b/build.rs index 86bd811..cc90c3c 100644 --- a/build.rs +++ b/build.rs @@ -187,15 +187,6 @@ fn main() { xmp_config.object(expat_int); } - let out_dir = env::var("OUT_DIR").expect("OUT_DIR not defined"); - println!("cargo:rustc-link-search=native={}", &out_dir); - // ^^ Is this still needed? - - // println!( - // "cargo:include={}/external/xmp_toolkit/public/include", - // std::env::var("CARGO_MANIFEST_DIR").expect("Failed to get - // CARGO_MANIFEST_DIR") ); - if let Ok(output) = std::process::Command::new("pwd").output() { println!( "*** pwd foo\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", From ade69f9d27facad5fa42665307fc7c1fa6f149be Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 7 Jul 2024 12:05:32 -0700 Subject: [PATCH 16/18] Force external/xmp_toolkit/third-party dirs to the content we need --- build.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/build.rs b/build.rs index cc90c3c..37df0ed 100644 --- a/build.rs +++ b/build.rs @@ -358,21 +358,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, ©_options).unwrap(); - } else { - eprintln!("Huh. dest_path {dest_path:?} was already a dir -- didn't copy"); - } + dest_path.pop(); + + let copy_options = CopyOptions::new(); + println!("COPYING {} to {}", src_path.display(), dest_path.display()); + copy(src_path, dest_path, ©_options).unwrap(); } fn git_command(args: I) From e837afc500a97339f2050c27156aeea4e0bb7998 Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 7 Jul 2024 12:13:25 -0700 Subject: [PATCH 17/18] Remove some debugging output --- build.rs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/build.rs b/build.rs index 37df0ed..3f22429 100644 --- a/build.rs +++ b/build.rs @@ -187,27 +187,6 @@ fn main() { xmp_config.object(expat_int); } - if let Ok(output) = std::process::Command::new("pwd").output() { - println!( - "*** pwd foo\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", - String::from_utf8(output.stdout).unwrap(), - String::from_utf8(output.stderr).unwrap() - ); - }; - - if let Ok(output) = std::process::Command::new("find") - .arg(".") - .arg("-name") - .arg("zlib.h") - .output() - { - println!( - "*** find . -name zlib.h\n\n--- stdout ---\n{}\n\n--- stderr ---\n{}\n\n", - String::from_utf8(output.stdout).unwrap(), - String::from_utf8(output.stderr).unwrap() - ); - }; - xmp_config .cpp(true) .define("TXMP_STRING_TYPE", "std::string") From e545b9a61a83d10ab09e880e953ab0d407bda0fa Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Sun, 7 Jul 2024 12:13:53 -0700 Subject: [PATCH 18/18] Bump to a fairly recent version of cc crate --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 437f0a7..8fdb623 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ num_enum = "0.7.0" thiserror = "1.0" [build-dependencies] -cc = "1.0.86" +cc = "1.0.101" fs_extra = "1.3" [dev-dependencies]