Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version & add a function to report the commit sha used to create the binary #417

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ $(shell.c):
$(sqlite3.c):
cd $(sqlite_src) && make sqlite3.c

$(rs_lib_dbg_static_cpy): FORCE $(dbg_prefix)
$(rs_lib_dbg_static_cpy): FORCE write_sha $(dbg_prefix)
cd ./rs/$(bundle) && cargo rustc $(RS_TARGET) --features static,omit_load_extension$(libsql_feature) $(rs_build_flags)
cp $(rs_lib_dbg_static) $(rs_lib_dbg_static_cpy)

$(rs_lib_static_cpy): FORCE $(prefix)
$(rs_lib_static_cpy): FORCE write_sha $(prefix)
cd ./rs/$(bundle) && cargo rustc $(RS_TARGET) --release --features static,omit_load_extension$(libsql_feature) $(rs_build_flags)
cp $(rs_lib_static) $(rs_lib_static_cpy)

$(rs_lib_loadable_cpy): FORCE $(prefix)
$(rs_lib_loadable_cpy): FORCE write_sha $(prefix)
cd ./rs/$(bundle) && cargo $(rs_ndk) build $(RS_TARGET) --release --features loadable_extension$(libsql_feature) $(rs_build_flags)
cp $(rs_lib_loadable) $(rs_lib_loadable_cpy)

$(rs_lib_dbg_loadable_cpy): FORCE $(dbg_prefix)
$(rs_lib_dbg_loadable_cpy): FORCE write_sha $(dbg_prefix)
cd ./rs/$(bundle) && cargo rustc $(RS_TARGET) --features loadable_extension$(libsql_feature) $(rs_build_flags)
cp $(rs_lib_dbg_loadable) $(rs_lib_dbg_loadable_cpy)

Expand Down Expand Up @@ -281,3 +281,8 @@ $(TARGET_FUZZ): $(prefix) $(TARGET_SQLITE3_EXTRA_C) src/fuzzer.cc $(ext_files)
ubsan analyzer fuzz asan static

FORCE: ;

write_sha:
@COMMIT_SHA=`git rev-parse HEAD` && \
sed -i.bak "s/\"[^\"]*\"/\"$$COMMIT_SHA\"/" ./rs/core/src/sha.rs && \
rm -f ./rs/core/src/sha.rs.bak
4 changes: 2 additions & 2 deletions core/nodejs-install-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ if (process.env.CRSQLITE_NOPREBUILD) {
} else {
// todo: check msys?
if (["win32", "cygwin"].includes(process.platform)) {
os = "windows";
os = "win";
}

// manual ovverides for testing
Expand All @@ -36,7 +36,7 @@ if (process.env.CRSQLITE_NOPREBUILD) {
case "linux":
ext = "so";
break;
case "windows":
case "win":
ext = "dll";
break;
}
Expand Down
3 changes: 2 additions & 1 deletion core/rs/core/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ pub const TBL_SCHEMA: &'static str = "crsql_master";
// 00_05_01_00
// and, if we ever need it, we can track individual builds of a patch release
// 00_05_01_01
pub const CRSQLITE_VERSION: i32 = 15_00_00;
pub const CRSQLITE_VERSION: i32 = 16_01_00;
pub const CRSQLITE_VERSION_STR: &'static str = "0.16.1";
pub const SITE_ID_LEN: i32 = 16;
pub const ROWID_SLAB_SIZE: i64 = 10000000000000;
// db version is a signed 64bit int since sqlite doesn't support saving and
Expand Down
54 changes: 54 additions & 0 deletions core/rs/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod local_writes;
pub mod pack_columns;
#[cfg(not(feature = "test"))]
mod pack_columns;
mod sha;
mod stmt_cache;
#[cfg(feature = "test")]
pub mod tableinfo;
Expand Down Expand Up @@ -266,6 +267,40 @@ pub extern "C" fn sqlite3_crsqlcore_init(
return null_mut();
}

let rc = db
.create_function_v2(
"crsql_sha",
0,
sqlite::UTF8 | sqlite::INNOCUOUS | sqlite::DETERMINISTIC,
None,
Some(x_crsql_sha),
None,
None,
None,
)
.unwrap_or(ResultCode::ERROR);
if rc != ResultCode::OK {
unsafe { crsql_freeExtData(ext_data) };
return null_mut();
}

let rc = db
.create_function_v2(
"crsql_version",
0,
sqlite::UTF8 | sqlite::INNOCUOUS | sqlite::DETERMINISTIC,
None,
Some(x_crsql_version),
None,
None,
None,
)
.unwrap_or(ResultCode::ERROR);
if rc != ResultCode::OK {
unsafe { crsql_freeExtData(ext_data) };
return null_mut();
}

let rc = db
.create_function_v2(
"crsql_increment_and_get_seq",
Expand Down Expand Up @@ -697,6 +732,25 @@ unsafe extern "C" fn x_crsql_next_db_version(
ctx.result_int64(ret);
}

/**
* The sha of the commit that this version of crsqlite was built from.
*/
unsafe extern "C" fn x_crsql_sha(
ctx: *mut sqlite::context,
argc: i32,
argv: *mut *mut sqlite::value,
) {
ctx.result_text_static(sha::SHA);
}

unsafe extern "C" fn x_crsql_version(
ctx: *mut sqlite::context,
argc: i32,
argv: *mut *mut sqlite::value,
) {
ctx.result_int64(consts::CRSQLITE_VERSION as i64);
}

unsafe extern "C" fn x_free_connection_ext_data(data: *mut c_void) {
let ext_data = data as *mut c::crsql_ExtData;
crsql_freeExtData(ext_data);
Expand Down
2 changes: 2 additions & 0 deletions core/rs/core/src/sha.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// The sha of the commit that this version of crsqlite was built from.
pub const SHA: &'static str = "";