Search code examples
wasm-bindgenwasm-pack

wasm-bindgen - possible to identify build version / date?


With webapplications the dev loop [change -> build -> deploy -> test] is very iterative. Due to browser caches easy to mistake the build version. Hence very often neccesary to identify the build version.

Does wasm-bindgen/wasm-pack provide some macro with e.g. Timestamp to dump in the logfile, in order to identify the version of the build?

Something like: log(BUILD_DATE) => "2020:09:12 09:37:12"


Solution

  • Here wasm-bindgen/wasm-pack is actually nice integrated with cargo build tool chain.

    So works with no tweaks.

    https://doc.rust-lang.org/cargo/reference/build-scripts.html

    Passing symbol values to the Rust compiler during build

    With just the raw epoch-secs build.rs becomes

    use std::time;
    
    fn main() {
        let now = time::SystemTime::now()
            .duration_since(time::UNIX_EPOCH).unwrap();
    
        println!("cargo:rustc-env=BUILD_INFO={}", now.as_secs());
    }