Skip to content

A fast, helpful, and open-source document parser

move lib

Logan Markewichf9c5d901b22c
diff --git a/crates/pdfium-sys/build.rs b/crates/pdfium-sys/build.rs
index 40d1b77..a9bd2fc 100644
--- a/crates/pdfium-sys/build.rs
+++ b/crates/pdfium-sys/build.rs
@@ -22,7 +22,6 @@ fn main() {
)
});
- let _target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
println!("cargo:rustc-link-search=native={}", lib_dir.display());
@@ -49,6 +48,20 @@ fn main() {
// so the runtime loader knows where to find the shared library.
println!("cargo:lib_path={}", lib_dir.display());
println!("cargo:rustc-env=PDFIUM_LIB_DIR={}", lib_dir.display());
+
+ // Copy the dylib into target/<profile>/deps/ so that CI scripts and
+ // packaging tools (copy-pdfium.sh, maturin wheel bundling) can find it
+ // in the build tree. This is NOT for linking — just discoverability.
+ let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
+ let dll_dir = if target_os == "windows" {
+ lib_dir
+ .parent()
+ .map(|p| p.join("bin"))
+ .unwrap_or(lib_dir.clone())
+ } else {
+ lib_dir.clone()
+ };
+ copy_dylib_to_target_deps(&dll_dir);
}
run_bindgen(&include_dir);
@@ -197,6 +210,41 @@ fn fix_dylib_install_name(dir: &Path) {
}
}
+/// Copy the pdfium shared library into `target/<profile>/deps/` so that
+/// CI scripts and packaging tools can find it in the build tree.
+/// This is NOT for linking — pdfium is loaded at runtime via libloading.
+fn copy_dylib_to_target_deps(lib_dir: &Path) {
+ let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
+
+ let dylib_name = match target_os.as_str() {
+ "macos" => "libpdfium.dylib",
+ "windows" => "pdfium.dll",
+ _ => "libpdfium.so",
+ };
+
+ let src = lib_dir.join(dylib_name);
+ if !src.exists() {
+ return;
+ }
+
+ // OUT_DIR is typically target/<profile>/build/<pkg>-<hash>/out
+ // We want target/<profile>/deps which is 3 levels up then into deps
+ let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
+ if let Some(build_dir) = out_dir
+ .parent()
+ .and_then(|p| p.parent())
+ .and_then(|p| p.parent())
+ {
+ let deps_dir = build_dir.join("deps");
+ if deps_dir.is_dir() {
+ let dst = deps_dir.join(dylib_name);
+ fs::copy(&src, &dst).unwrap_or_else(|e| {
+ panic!("failed to copy {} to {}: {e}", src.display(), dst.display())
+ });
+ }
+ }
+}
+
fn run_bindgen(include_dir: &Path) {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let out_file = out_path.join("bindings.rs");