From 38cfab7d5dd2f294ce36493ad02f26bfd26cef33 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 4 Dec 2024 17:41:02 +0200 Subject: [PATCH 1/2] Revert "Revert "Merge pull request #1791 from awakecoding/libsql-ffi-build-cp-fix"" This reverts commit 9499c3c40aa299b0ce5221b53f000f69462f8d8c. The real problem is not Windows, but build on macOS. Let's revert this revert and fix macOS instead. --- libsql-ffi/build.rs | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/libsql-ffi/build.rs b/libsql-ffi/build.rs index f6be344c1a..730478ae47 100644 --- a/libsql-ffi/build.rs +++ b/libsql-ffi/build.rs @@ -1,7 +1,7 @@ use std::env; use std::ffi::OsString; use std::fs::{self, OpenOptions}; -use std::io::Write; +use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::Command; @@ -39,13 +39,8 @@ fn main() { let dir = env!("CARGO_MANIFEST_DIR"); - Command::new("cp") - .arg("--no-preserve=mode,ownership") - .arg("-R") - .arg(format!("{dir}/{bindgen_rs_path}")) - .arg(&out_path) - .output() - .unwrap(); + let full_src_path = Path::new(dir).join(bindgen_rs_path); + copy_with_cp(full_src_path, &out_path).unwrap(); println!("cargo:lib_dir={out_dir}"); @@ -61,6 +56,31 @@ fn main() { build_bundled(&out_dir, &out_path); } +#[cfg(target_os = "windows")] +fn copy_with_cp(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { + fs::copy(src, dst)?; // do a regular file copy on Windows + Ok(()) +} + +#[cfg(not(target_os = "windows"))] +fn copy_with_cp(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { + let status = Command::new("cp") + .arg("--no-preserve=mode,ownership") + .arg("-R") + .arg(src.as_ref().to_str().unwrap()) + .arg(dst.as_ref().to_str().unwrap()) + .status()?; + + if !status.success() { + Err(io::Error::new( + io::ErrorKind::Other, + "Failed to copy using cp", + )) + } else { + Ok(()) + } +} + fn make_amalgamation() { let flags = ["-DSQLITE_ENABLE_COLUMN_METADATA=1"]; From 13385969d1ffcc8e2e81e09dd9feb296a77ca946 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 4 Dec 2024 17:44:02 +0200 Subject: [PATCH 2/2] libsql-ffi: Fix build on macOS The `cp` command does not support `--no-preserve` on macOS. --- libsql-ffi/build.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libsql-ffi/build.rs b/libsql-ffi/build.rs index 730478ae47..55f25ec5cf 100644 --- a/libsql-ffi/build.rs +++ b/libsql-ffi/build.rs @@ -62,7 +62,7 @@ fn copy_with_cp(src: impl AsRef, dst: impl AsRef) -> io::Result<()> Ok(()) } -#[cfg(not(target_os = "windows"))] +#[cfg(target_os = "linux")] fn copy_with_cp(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { let status = Command::new("cp") .arg("--no-preserve=mode,ownership") @@ -81,6 +81,24 @@ fn copy_with_cp(src: impl AsRef, dst: impl AsRef) -> io::Result<()> } } +#[cfg(target_os = "macos")] +fn copy_with_cp(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { + let status = Command::new("cp") + .arg("-R") + .arg(src.as_ref().to_str().unwrap()) + .arg(dst.as_ref().to_str().unwrap()) + .status()?; + + if !status.success() { + Err(io::Error::new( + io::ErrorKind::Other, + "Failed to copy using cp", + )) + } else { + Ok(()) + } +} + fn make_amalgamation() { let flags = ["-DSQLITE_ENABLE_COLUMN_METADATA=1"];