Skip to content

Commit 333029e

Browse files
authored
Merge pull request #1864 from tursodatabase/fix-windows-build
Fix Windows build
2 parents 9241b00 + 1338596 commit 333029e

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

libsql-ffi/build.rs

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::env;
22
use std::ffi::OsString;
33
use std::fs::{self, OpenOptions};
4-
use std::io::Write;
4+
use std::io::{self, Write};
55
use std::path::{Path, PathBuf};
66
use std::process::Command;
77

@@ -39,13 +39,8 @@ fn main() {
3939

4040
let dir = env!("CARGO_MANIFEST_DIR");
4141

42-
Command::new("cp")
43-
.arg("--no-preserve=mode,ownership")
44-
.arg("-R")
45-
.arg(format!("{dir}/{bindgen_rs_path}"))
46-
.arg(&out_path)
47-
.output()
48-
.unwrap();
42+
let full_src_path = Path::new(dir).join(bindgen_rs_path);
43+
copy_with_cp(full_src_path, &out_path).unwrap();
4944

5045
println!("cargo:lib_dir={out_dir}");
5146

@@ -61,6 +56,49 @@ fn main() {
6156
build_bundled(&out_dir, &out_path);
6257
}
6358

59+
#[cfg(target_os = "windows")]
60+
fn copy_with_cp(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
61+
fs::copy(src, dst)?; // do a regular file copy on Windows
62+
Ok(())
63+
}
64+
65+
#[cfg(target_os = "linux")]
66+
fn copy_with_cp(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
67+
let status = Command::new("cp")
68+
.arg("--no-preserve=mode,ownership")
69+
.arg("-R")
70+
.arg(src.as_ref().to_str().unwrap())
71+
.arg(dst.as_ref().to_str().unwrap())
72+
.status()?;
73+
74+
if !status.success() {
75+
Err(io::Error::new(
76+
io::ErrorKind::Other,
77+
"Failed to copy using cp",
78+
))
79+
} else {
80+
Ok(())
81+
}
82+
}
83+
84+
#[cfg(target_os = "macos")]
85+
fn copy_with_cp(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
86+
let status = Command::new("cp")
87+
.arg("-R")
88+
.arg(src.as_ref().to_str().unwrap())
89+
.arg(dst.as_ref().to_str().unwrap())
90+
.status()?;
91+
92+
if !status.success() {
93+
Err(io::Error::new(
94+
io::ErrorKind::Other,
95+
"Failed to copy using cp",
96+
))
97+
} else {
98+
Ok(())
99+
}
100+
}
101+
64102
fn make_amalgamation() {
65103
let flags = ["-DSQLITE_ENABLE_COLUMN_METADATA=1"];
66104

0 commit comments

Comments
 (0)