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

195 views Asked by At

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"

1

There are 1 answers

0
Jonas Bojesen On BEST ANSWER

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());
}