mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-16 18:32:13 +00:00
Implement a version string
Add a `--version` and `-V` to the command to print out the version
This commit is contained in:
parent
36f064bed0
commit
1c8061e675
@ -9,6 +9,7 @@ parity-wasm = "0.27"
|
|||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
wasm-bindgen-cli-support = { path = "../wasm-bindgen-cli-support" }
|
wasm-bindgen-cli-support = { path = "../wasm-bindgen-cli-support" }
|
||||||
|
wasm-bindgen-shared = { path = "../wasm-bindgen-shared" }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "wasm-bindgen"
|
name = "wasm-bindgen"
|
||||||
|
@ -2,6 +2,7 @@ extern crate wasm_bindgen_cli_support;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate docopt;
|
extern crate docopt;
|
||||||
|
extern crate wasm_bindgen_shared;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ Generating JS bindings for a wasm file
|
|||||||
Usage:
|
Usage:
|
||||||
wasm-bindgen [options] <input>
|
wasm-bindgen [options] <input>
|
||||||
wasm-bindgen -h | --help
|
wasm-bindgen -h | --help
|
||||||
|
wasm-bindgen -V | --version
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h --help Show this screen.
|
-h --help Show this screen.
|
||||||
@ -21,6 +23,7 @@ Options:
|
|||||||
--nodejs Generate output for node.js, not the browser
|
--nodejs Generate output for node.js, not the browser
|
||||||
--typescript Output a TypeScript definition file
|
--typescript Output a TypeScript definition file
|
||||||
--debug Include otherwise-extraneous debug checks in output
|
--debug Include otherwise-extraneous debug checks in output
|
||||||
|
-V --version Print the version number of wasm-bindgen
|
||||||
";
|
";
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
@ -29,7 +32,8 @@ struct Args {
|
|||||||
flag_typescript: bool,
|
flag_typescript: bool,
|
||||||
flag_out_dir: Option<PathBuf>,
|
flag_out_dir: Option<PathBuf>,
|
||||||
flag_debug: bool,
|
flag_debug: bool,
|
||||||
arg_input: PathBuf,
|
flag_version: bool,
|
||||||
|
arg_input: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -37,8 +41,18 @@ fn main() {
|
|||||||
.and_then(|d| d.deserialize())
|
.and_then(|d| d.deserialize())
|
||||||
.unwrap_or_else(|e| e.exit());
|
.unwrap_or_else(|e| e.exit());
|
||||||
|
|
||||||
|
if args.flag_version {
|
||||||
|
println!("wasm-bindgen {}", wasm_bindgen_shared::version());
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let input = match args.arg_input {
|
||||||
|
Some(s) => s,
|
||||||
|
None => panic!("input file expected"),
|
||||||
|
};
|
||||||
|
|
||||||
let mut b = Bindgen::new();
|
let mut b = Bindgen::new();
|
||||||
b.input_path(&args.arg_input)
|
b.input_path(&input)
|
||||||
.nodejs(args.flag_nodejs)
|
.nodejs(args.flag_nodejs)
|
||||||
.debug(args.flag_debug)
|
.debug(args.flag_debug)
|
||||||
.typescript(args.flag_typescript);
|
.typescript(args.flag_typescript);
|
||||||
|
14
crates/wasm-bindgen-shared/build.rs
Normal file
14
crates/wasm-bindgen-shared/build.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let rev = Command::new("git")
|
||||||
|
.arg("rev-parse")
|
||||||
|
.arg("HEAD")
|
||||||
|
.output()
|
||||||
|
.ok()
|
||||||
|
.map(|s| s.stdout)
|
||||||
|
.and_then(|s| String::from_utf8(s).ok());
|
||||||
|
if let Some(rev) = rev {
|
||||||
|
println!("cargo:rustc-env=WBG_VERSION={}", &rev[..9]);
|
||||||
|
}
|
||||||
|
}
|
@ -134,3 +134,13 @@ pub fn name_to_descriptor(name: &str) -> char {
|
|||||||
}
|
}
|
||||||
char::from_u32(ret).unwrap()
|
char::from_u32(ret).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn version() -> String {
|
||||||
|
let mut v = env!("CARGO_PKG_VERSION").to_string();
|
||||||
|
if let Some(s) = option_env!("WBG_VERSION") {
|
||||||
|
v.push_str(" (");
|
||||||
|
v.push_str(s);
|
||||||
|
v.push_str(")");
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user