Skip to content

Commit 65d046c

Browse files
authored
Merge branch 'main' into feat-add-list-namespaces-admin-endpoint
2 parents be2ca7b + 9cbba77 commit 65d046c

11 files changed

Lines changed: 219 additions & 177 deletions

File tree

Cargo.lock

Lines changed: 17 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ exclude = [
2525
]
2626

2727
[workspace.package]
28-
version = "0.9.9"
28+
version = "0.9.11"
2929
authors = ["the libSQL authors"]
3030
edition = "2021"
3131
license = "MIT"
3232
repository = "https://github.com/tursodatabase/libsql"
3333

3434
[workspace.dependencies]
35-
libsql-ffi = { path = "libsql-ffi", version = "0.9.9" }
36-
libsql-sys = { path = "libsql-sys", version = "0.9.9", default-features = false }
37-
libsql-hrana = { path = "libsql-hrana", version = "0.9.9" }
38-
libsql_replication = { path = "libsql-replication", version = "0.9.9" }
39-
rusqlite = { package = "libsql-rusqlite", path = "vendored/rusqlite", version = "0.9.9", default-features = false, features = [
35+
libsql-ffi = { path = "libsql-ffi", version = "0.9.11" }
36+
libsql-sys = { path = "libsql-sys", version = "0.9.11", default-features = false }
37+
libsql-hrana = { path = "libsql-hrana", version = "0.9.11" }
38+
libsql_replication = { path = "libsql-replication", version = "0.9.11" }
39+
rusqlite = { package = "libsql-rusqlite", path = "vendored/rusqlite", version = "0.9.11", default-features = false, features = [
4040
"libsql-experimental",
4141
"column_decltype",
4242
"load_extension",

libsql-ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ exclude = [
1818
libsql-wasmtime-bindings = { version = "0.2.1", optional = true }
1919

2020
[build-dependencies]
21+
cmake = "0.1.54"
2122
bindgen = "0.66.1"
2223
cc = "1.0"
2324
glob = "0.3"

libsql-ffi/build.rs

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

@@ -29,7 +29,7 @@ fn main() {
2929

3030
if std::env::var("LIBSQL_DEV").is_ok() {
3131
make_amalgamation();
32-
build_multiple_ciphers(&target, &out_path);
32+
build_multiple_ciphers(&out_path);
3333
}
3434

3535
let bindgen_rs_path = if cfg!(feature = "session") {
@@ -50,7 +50,7 @@ fn main() {
5050
}
5151

5252
if cfg!(feature = "multiple-ciphers") {
53-
copy_multiple_ciphers(&target, &out_dir, &out_path);
53+
copy_multiple_ciphers(&out_path);
5454
return;
5555
}
5656

@@ -76,8 +76,12 @@ fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()>
7676
/// propagate into OUT_DIR. If not present, when trying to rewrite a file, a `Permission denied`
7777
/// error will occur.
7878
fn copy_with_cp(from: impl AsRef<Path>, to: impl AsRef<Path>) -> io::Result<()> {
79-
match Command::new("cp")
80-
.arg("--no-preserve=mode,ownership")
79+
let mut command = Command::new("cp");
80+
// --no-preserve is enabled by default on macos
81+
// preserve must be explicitly enabled with the -p flag
82+
#[cfg(not(target_os = "macos"))]
83+
let command = command.arg("--no-preserve=mode,ownership");
84+
match command
8185
.arg("-R")
8286
.arg(from.as_ref().to_str().unwrap())
8387
.arg(to.as_ref().to_str().unwrap())
@@ -409,18 +413,22 @@ pub fn build_bundled(out_dir: &str, out_path: &Path) {
409413
println!("cargo:lib_dir={out_dir}");
410414
}
411415

412-
fn copy_multiple_ciphers(target: &str, out_dir: &str, out_path: &Path) {
413-
let dylib = format!("{out_dir}/sqlite3mc/libsqlite3mc_static.a");
414-
if !Path::new(&dylib).exists() {
415-
build_multiple_ciphers(target, out_path);
416-
}
416+
fn copy_multiple_ciphers(out_path: &Path) {
417+
let dst = dbg!(build_multiple_ciphers(out_path));
417418

418-
copy_with_cp(dylib, format!("{out_dir}/libsqlite3mc.a")).unwrap();
419-
println!("cargo:rustc-link-lib=static=sqlite3mc");
420-
println!("cargo:rustc-link-search={out_dir}");
419+
println!("cargo:rustc-link-search={}", dst.join("build").display());
420+
println!(
421+
"cargo:rustc-link-search={}",
422+
dst.join("build").join("Release").display()
423+
);
424+
println!(
425+
"cargo:rustc-link-search={}",
426+
dst.join("build").join("Debug").display()
427+
);
428+
println!("cargo:rustc-link-lib=static=sqlite3mc_static");
421429
}
422430

423-
fn build_multiple_ciphers(target: &str, out_path: &Path) {
431+
fn build_multiple_ciphers(out_path: &Path) -> PathBuf {
424432
let bindgen_rs_path = if cfg!(feature = "session") {
425433
"bundled/bindings/session_bindgen.rs"
426434
} else {
@@ -450,112 +458,45 @@ fn build_multiple_ciphers(target: &str, out_path: &Path) {
450458
.unwrap();
451459

452460
let bundled_dir = format!("{out_dir}/sqlite3mc");
453-
let sqlite3mc_build_dir = env::current_dir().unwrap().join(out_dir).join("sqlite3mc");
454-
455-
let mut cmake_opts: Vec<&str> = vec![];
456-
457-
let target_postfix = target.to_string().replace("-", "_");
458-
let cross_cc_var_name = format!("CC_{}", target_postfix);
459-
println!("cargo:warning=CC_var_name={}", cross_cc_var_name);
460-
let cross_cc = env::var(&cross_cc_var_name).ok();
461-
462-
let cross_cxx_var_name = format!("CXX_{}", target_postfix);
463-
let cross_cxx = env::var(&cross_cxx_var_name).ok();
464-
465-
let toolchain_path = sqlite3mc_build_dir.join("toolchain.cmake");
466-
let cmake_toolchain_opt = "-DCMAKE_TOOLCHAIN_FILE=toolchain.cmake".to_string();
467-
468-
let mut toolchain_file = OpenOptions::new()
469-
.create(true)
470-
.write(true)
471-
.append(true)
472-
.open(toolchain_path.clone())
473-
.unwrap();
474-
475-
if let Some(ref cc) = cross_cc {
476-
let system_name = if cc.contains("linux") {
477-
"Linux"
478-
} else if cc.contains("darwin") {
479-
"Darwin"
480-
} else if cc.contains("w64") {
481-
"Windows"
482-
} else {
483-
panic!("Unsupported cross target {}", cc)
484-
};
485461

486-
let system_processor = if cc.contains("x86_64") {
487-
"x86_64"
488-
} else if cc.contains("aarch64") {
489-
"arm64"
490-
} else if cc.contains("arm") {
491-
"arm"
492-
} else {
493-
panic!("Unsupported cross target {}", cc)
494-
};
462+
let mut config = cmake::Config::new(&bundled_dir);
495463

496-
cmake_opts.push(&cmake_toolchain_opt);
497-
writeln!(toolchain_file, "set(CMAKE_SYSTEM_NAME \"{}\")", system_name).unwrap();
498-
writeln!(
499-
toolchain_file,
500-
"set(CMAKE_SYSTEM_PROCESSOR \"{}\")",
501-
system_processor
502-
)
503-
.unwrap();
504-
writeln!(toolchain_file, "set(CMAKE_C_COMPILER {})", cc).unwrap();
505-
}
464+
config
465+
.build_target("sqlite3mc_static")
466+
.define("SQLITE3MC_STATIC", "ON")
467+
.define("CODEC_TYPE", "AES256")
468+
.define("SQLITE3MC_BUILD_SHELL", "OFF")
469+
.define("SQLITE_SHELL_IS_UTF8", "OFF")
470+
.define("SQLITE_USER_AUTHENTICATION", "OFF")
471+
.define("SQLITE_SECURE_DELETE", "OFF")
472+
.define("SQLITE_ENABLE_COLUMN_METADATA", "ON")
473+
.define("SQLITE_USE_URI", "ON")
474+
.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON")
475+
.profile("Release");
506476

507-
if let Some(cxx) = cross_cxx {
508-
writeln!(toolchain_file, "set(CMAKE_CXX_COMPILER {})", cxx).unwrap();
477+
if let Ok(cc) = env::var("CMAKE_C_COMPILER") {
478+
let mut build = cc::Build::new();
479+
build.compiler(cc);
480+
config.init_c_cfg(build);
509481
}
510482

511-
cmake_opts.push("-DCMAKE_BUILD_TYPE=Release");
512-
cmake_opts.push("-DSQLITE3MC_STATIC=ON");
513-
cmake_opts.push("-DCODEC_TYPE=AES256");
514-
cmake_opts.push("-DSQLITE3MC_BUILD_SHELL=OFF");
515-
cmake_opts.push("-DSQLITE_SHELL_IS_UTF8=OFF");
516-
cmake_opts.push("-DSQLITE_USER_AUTHENTICATION=OFF");
517-
cmake_opts.push("-DSQLITE_SECURE_DELETE=OFF");
518-
cmake_opts.push("-DSQLITE_ENABLE_COLUMN_METADATA=ON");
519-
cmake_opts.push("-DSQLITE_USE_URI=ON");
520-
cmake_opts.push("-DCMAKE_POSITION_INDEPENDENT_CODE=ON");
521-
522-
if target.contains("musl") {
523-
cmake_opts.push("-DCMAKE_C_FLAGS=\"-U_FORTIFY_SOURCE\" -D_FILE_OFFSET_BITS=32");
524-
cmake_opts.push("-DCMAKE_CXX_FLAGS=\"-U_FORTIFY_SOURCE\" -D_FILE_OFFSET_BITS=32");
483+
if let Ok(cxx) = env::var("CMAKE_CXX_COMPILER") {
484+
let mut build = cc::Build::new();
485+
build.compiler(cxx);
486+
config.init_cxx_cfg(build);
525487
}
526488

527-
let mut cmake = Command::new("cmake");
528-
cmake.current_dir(sqlite3mc_build_dir.clone());
529-
cmake.args(cmake_opts.clone());
530-
cmake.arg(bundled_dir.clone());
531489
if cfg!(feature = "wasmtime-bindings") {
532-
cmake.arg("-DLIBSQL_ENABLE_WASM_RUNTIME=1");
490+
config.define("LIBSQL_ENABLE_WASM_RUNTIME", "1");
533491
}
492+
534493
if cfg!(feature = "session") {
535-
cmake.arg("-DSQLITE_ENABLE_PREUPDATE_HOOK=ON");
536-
cmake.arg("-DSQLITE_ENABLE_SESSION=ON");
537-
}
538-
println!("Running `cmake` with options: {}", cmake_opts.join(" "));
539-
let status = cmake.status().unwrap();
540-
if !status.success() {
541-
panic!("Failed to run cmake with options: {}", cmake_opts.join(" "));
542-
}
543-
544-
let mut make = Command::new("cmake");
545-
make.current_dir(sqlite3mc_build_dir.clone());
546-
make.args(["--build", "."]);
547-
make.args(["--config", "Release"]);
548-
if !make.status().unwrap().success() {
549-
panic!("Failed to run make");
550-
}
551-
// The `msbuild` tool puts the output in a different place so let's move it.
552-
if Path::exists(&sqlite3mc_build_dir.join("Release/sqlite3mc_static.lib")) {
553-
fs::rename(
554-
sqlite3mc_build_dir.join("Release/sqlite3mc_static.lib"),
555-
sqlite3mc_build_dir.join("libsqlite3mc_static.a"),
556-
)
557-
.unwrap();
494+
config
495+
.define("SQLITE_ENABLE_PREUPDATE_HOOK", "ON")
496+
.define("SQLITE_ENABLE_SESSION", "ON");
558497
}
498+
499+
config.build()
559500
}
560501

561502
fn env(name: &str) -> Option<OsString> {

libsql/src/database.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ enum DbType {
8484
path: String,
8585
flags: OpenFlags,
8686
encryption_config: Option<EncryptionConfig>,
87-
skip_saftey_assert: bool,
87+
skip_safety_assert: bool,
8888
},
8989
#[cfg(feature = "replication")]
9090
Sync {
@@ -166,7 +166,7 @@ cfg_core! {
166166
path: db_path.into(),
167167
flags,
168168
encryption_config: None,
169-
skip_saftey_assert: false,
169+
skip_safety_assert: false,
170170
},
171171
max_write_replication_index: Default::default(),
172172
})
@@ -458,7 +458,7 @@ cfg_replication! {
458458
DbType::Sync { db, .. } => {
459459
let path = db.path().to_string();
460460
Ok(Database {
461-
db_type: DbType::File { path, flags: OpenFlags::default(), encryption_config: None, skip_saftey_assert: false },
461+
db_type: DbType::File { path, flags: OpenFlags::default(), encryption_config: None, skip_safety_assert: false },
462462
max_write_replication_index: Default::default(),
463463
})
464464
}
@@ -580,11 +580,11 @@ impl Database {
580580
path,
581581
flags,
582582
encryption_config,
583-
skip_saftey_assert,
583+
skip_safety_assert,
584584
} => {
585585
use crate::local::impls::LibsqlConnection;
586586

587-
let db = if !skip_saftey_assert {
587+
let db = if !skip_safety_assert {
588588
crate::local::Database::open(path, *flags)?
589589
} else {
590590
unsafe { crate::local::Database::open_raw(path, *flags)? }
@@ -712,6 +712,7 @@ impl Database {
712712
read_your_writes: *read_your_writes,
713713
context: db.sync_ctx.clone().unwrap(),
714714
state: std::sync::Arc::new(Mutex::new(State::Init)),
715+
needs_pull: std::sync::atomic::AtomicBool::new(false).into(),
715716
};
716717

717718
let conn = std::sync::Arc::new(synced);

0 commit comments

Comments
 (0)