Skip to content

Commit

Permalink
libsql-ffi: Fix sqlite3mc build output directory
Browse files Browse the repository at this point in the history
Don't build inside the source tree because `cargo clean` won't clean up
after it...
  • Loading branch information
penberg committed Mar 19, 2024
1 parent c77f91c commit 8434682
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions libsql-ffi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ fn main() {
println!("cargo:rerun-if-changed={BUNDLED_DIR}/src/sqlite3.c");

if cfg!(feature = "multiple-ciphers") {
println!(
"cargo:rerun-if-changed={BUNDLED_DIR}/SQLite3MultipleCiphers/build/libsqlite3mc_static.a"
);
println!("cargo:rerun-if-changed={out_dir}/sqlite3mc/libsqlite3mc_static.a");
}

if std::env::var("LIBSQL_DEV").is_ok() {
Expand Down Expand Up @@ -255,7 +253,7 @@ pub fn build_bundled(out_dir: &str, out_path: &Path) {
}

fn copy_multiple_ciphers(out_dir: &str, out_path: &Path) {
let dylib = format!("{BUNDLED_DIR}/SQLite3MultipleCiphers/build/libsqlite3mc_static.a");
let dylib = format!("{out_dir}/sqlite3mc/libsqlite3mc_static.a");
if !Path::new(&dylib).exists() {
build_multiple_ciphers(out_path);
}
Expand Down Expand Up @@ -289,11 +287,14 @@ fn build_multiple_ciphers(out_path: &Path) {
)
.unwrap();

let bundled_dir = fs::canonicalize(BUNDLED_DIR).unwrap();
let bundled_dir = fs::canonicalize(BUNDLED_DIR)
.unwrap()
.join("SQLite3MultipleCiphers");

let build_dir = bundled_dir.join("SQLite3MultipleCiphers").join("build");
let _ = fs::remove_dir_all(build_dir.clone());
fs::create_dir_all(build_dir.clone()).unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let sqlite3mc_build_dir = fs::canonicalize(out_dir.clone()).unwrap().join("sqlite3mc");
let _ = fs::remove_dir_all(sqlite3mc_build_dir.clone());
fs::create_dir_all(sqlite3mc_build_dir.clone()).unwrap();

let mut cmake_opts: Vec<&str> = vec![];

Expand All @@ -304,7 +305,7 @@ fn build_multiple_ciphers(out_path: &Path) {
let cross_cxx_var_name = format!("CXX_{}", cargo_build_target.replace("-", "_"));
let cross_cxx = env::var(&cross_cxx_var_name).ok();

let toolchain_path = build_dir.join("toolchain.cmake");
let toolchain_path = sqlite3mc_build_dir.join("toolchain.cmake");
let cmake_toolchain_opt = format!("-DCMAKE_TOOLCHAIN_FILE=toolchain.cmake");

let mut toolchain_file = OpenOptions::new()
Expand Down Expand Up @@ -345,9 +346,9 @@ fn build_multiple_ciphers(out_path: &Path) {
}

let mut cmake = Command::new("cmake");
cmake.current_dir("bundled/SQLite3MultipleCiphers/build");
cmake.current_dir(sqlite3mc_build_dir.clone());
cmake.args(cmake_opts.clone());
cmake.arg("..");
cmake.arg(bundled_dir.clone());
if cfg!(feature = "wasmtime-bindings") {
cmake.arg("-DLIBSQL_ENABLE_WASM_RUNTIME=1");
}
Expand All @@ -362,17 +363,17 @@ fn build_multiple_ciphers(out_path: &Path) {
}

let mut make = Command::new("cmake");
make.current_dir("bundled/SQLite3MultipleCiphers/build");
make.current_dir(sqlite3mc_build_dir.clone());
make.args(&["--build", "."]);
make.args(&["--config", "Release"]);
if !make.status().unwrap().success() {
panic!("Failed to run make");
}
// The `msbuild` tool puts the output in a different place so let's move it.
if Path::exists(&build_dir.join("Release/sqlite3mc_static.lib")) {
if Path::exists(&sqlite3mc_build_dir.join("Release/sqlite3mc_static.lib")) {
fs::rename(
build_dir.join("Release/sqlite3mc_static.lib"),
build_dir.join("libsqlite3mc_static.a"),
sqlite3mc_build_dir.join("Release/sqlite3mc_static.lib"),
sqlite3mc_build_dir.join("libsqlite3mc_static.a"),
)
.unwrap();
}
Expand Down

0 comments on commit 8434682

Please sign in to comment.