Skip to content

Commit

Permalink
Merge pull request #547 from tursodatabase/lucio/pregen
Browse files Browse the repository at this point in the history
libsql-sys: pregenerate bindings
  • Loading branch information
LucioFranco authored Nov 1, 2023
2 parents c032b9f + 1c25d4b commit 983871c
Show file tree
Hide file tree
Showing 4 changed files with 7,386 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/golang-bindings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- name: configure
working-directory: libsql-sqlite3
run: ./configure
run: CFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1" ./configure --enable-all --enable-releasemode

- name: Build
working-directory: libsql-sqlite3
Expand Down
25 changes: 25 additions & 0 deletions libsql-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,34 @@ fn run_make() {
.unwrap();
}

fn precompiled() -> bool {
std::fs::metadata(Path::new(SQLITE_DIR).join(".libs").join("liblibsql.a")).is_ok()
}

fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir).join("bindgen.rs");

// Fast path: liblibsql.a exists and bindings are ready
println!("cargo:rerun-if-env-changed=LIBSQL_REGENERATE_BINDINGS");
if precompiled() && env::var("LIBSQL_REGENERATE_BINDINGS").is_err() {
let bindgen_rs_path = if cfg!(feature = "session") {
"bundled/bindings/session_bindgen.rs"
} else {
"bundled/bindings/bindgen.rs"
};
std::fs::copy(Path::new(bindgen_rs_path), &out_path).unwrap();
std::fs::copy(
Path::new(SQLITE_DIR).join(".libs").join("liblibsql.a"),
Path::new(&out_dir).join("liblibsql.a"),
)
.unwrap();
println!("cargo:lib_dir={out_dir}");
println!("cargo:rustc-link-search={out_dir}");
println!("cargo:rustc-link-lib=static={LIB_NAME}");
return;
}

println!("cargo:rerun-if-changed={SQLITE_DIR}/src/");
run_make();
build_bundled(&out_dir, &out_path);
Expand Down
Loading

0 comments on commit 983871c

Please sign in to comment.