Skip to content

Commit

Permalink
Merge pull request #1864 from tursodatabase/fix-windows-build
Browse files Browse the repository at this point in the history
Fix Windows build
  • Loading branch information
penberg authored Dec 4, 2024
2 parents 9241b00 + 1338596 commit 333029e
Showing 1 changed file with 46 additions and 8 deletions.
54 changes: 46 additions & 8 deletions libsql-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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}");

Expand All @@ -61,6 +56,49 @@ fn main() {
build_bundled(&out_dir, &out_path);
}

#[cfg(target_os = "windows")]
fn copy_with_cp(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
fs::copy(src, dst)?; // do a regular file copy on Windows
Ok(())
}

#[cfg(target_os = "linux")]
fn copy_with_cp(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> 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(())
}
}

#[cfg(target_os = "macos")]
fn copy_with_cp(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> 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"];

Expand Down

0 comments on commit 333029e

Please sign in to comment.