Skip to content

Commit

Permalink
change: version logic
Browse files Browse the repository at this point in the history
  • Loading branch information
macjuul committed Aug 28, 2024
1 parent bac4040 commit f02b1ea
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ wasm-bindgen = "0.2.92"
wasm-bindgen-futures = "0.4.42"
wasm-streams = "0.4.0"
web-sys = { version = "0.3.69", features = ["console"] }
once_cell = "1.19.0"
cargo-lock = "9.0.0"

[dev-dependencies]
wasm-bindgen-test = "0.3.41"

[build-dependencies]
cargo-lock = "9.0.0"
21 changes: 21 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use std::fs;

fn main() {
let cargo_lock = fs::read_to_string("Cargo.lock").expect("Unable to read Cargo.toml");
let lock: cargo_lock::Lockfile = cargo_lock.parse().expect("Failed to parse Cargo.lock");
let package = lock
.packages
.iter()
.find(|p| {
let name = p.name.as_str();

name == "surrealdb" ||
name == "surrealdb-beta" ||
name == "surrealdb-alpha"
})
.expect("Failed to find surrealdb in Cargo.lock");

let version = format!("{}.{}.{}", package.version.major, package.version.minor, package.version.patch);

println!("cargo:rustc-env=SURREALDB_VERSION={}", version);
}
20 changes: 3 additions & 17 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod types;

use cbor::Cbor;
use futures::StreamExt;
use once_cell::sync::Lazy;
use opt::endpoint::Options;
use serde_wasm_bindgen::from_value;
use surrealdb::dbs::Notification;
Expand Down Expand Up @@ -99,7 +98,7 @@ impl SurrealWasmEngine {
}

pub fn version() -> Result<String, Error> {
Ok(SURREALDB_VERSION.clone())
Ok(env!("SURREALDB_VERSION").into())
}
}

Expand Down Expand Up @@ -131,7 +130,7 @@ impl RpcContext for SurrealWasmEngineInner {
}

fn version_data(&self) -> Data {
Value::Strand(format!("surrealdb-{}", *SURREALDB_VERSION).into()).into()
Value::Strand(format!("surrealdb-{}", env!("SURREALDB_VERSION")).into()).into()
}

const LQ_SUPPORT: bool = true;
Expand All @@ -141,17 +140,4 @@ impl RpcContext for SurrealWasmEngineInner {
fn handle_kill(&self, _lqid: &Uuid) -> impl std::future::Future<Output = ()> + Send {
async { () }
}
}

static LOCK_FILE: &str = include_str!("../../Cargo.lock");

pub static SURREALDB_VERSION: Lazy<String> = Lazy::new(|| {
let lock: cargo_lock::Lockfile = LOCK_FILE.parse().expect("Failed to parse Cargo.lock");
let package = lock
.packages
.iter()
.find(|p| p.name.as_str() == "surrealdb")
.expect("Failed to find surrealdb in Cargo.lock");

format!("{}.{}.{}", package.version.major, package.version.minor, package.version.patch)
});
}

0 comments on commit f02b1ea

Please sign in to comment.