diff --git a/Cargo.lock b/Cargo.lock index 000e4d56..48ccbce5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -658,6 +658,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "tree-sitter" version = "0.19.5" @@ -691,6 +700,7 @@ dependencies = [ "smallbitvec", "tempfile", "tiny_http", + "toml", "tree-sitter", "tree-sitter-config", "tree-sitter-highlight", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e331e349..85e9b4d1 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -74,3 +74,6 @@ features = ["std"] [dev-dependencies] rand = "0.8" tempfile = "3" + +[build-dependencies] +toml = "0.5" diff --git a/cli/build.rs b/cli/build.rs index 29017e11..83be39a5 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -10,10 +10,16 @@ fn main() { println!("cargo:rustc-cfg={}", "TREE_SITTER_EMBED_WASM_BINDING"); } + let rust_binding_version = read_rust_binding_version(); + println!( + "cargo:rustc-env={}={}", + "RUST_BINDING_VERSION", rust_binding_version, + ); + let emscripten_version = fs::read_to_string("../emscripten-version").unwrap(); println!( "cargo:rustc-env={}={}", - "EMSCRIPTEN_VERSION", emscripten_version + "EMSCRIPTEN_VERSION", emscripten_version, ); } @@ -73,3 +79,14 @@ fn read_git_sha() -> Option { None } + +fn read_rust_binding_version() -> String { + let path = "../lib/Cargo.toml"; + let text = fs::read_to_string(path).unwrap(); + let cargo_toml = toml::from_str::(text.as_ref()).unwrap(); + cargo_toml["package"]["version"] + .as_str() + .unwrap() + .trim_matches('"') + .to_string() +} diff --git a/cli/src/generate/binding_files.rs b/cli/src/generate/binding_files.rs index 9f7980db..4241b616 100644 --- a/cli/src/generate/binding_files.rs +++ b/cli/src/generate/binding_files.rs @@ -13,6 +13,8 @@ const PACKAGE_JSON_TEMPLATE: &'static str = include_str!("./templates/package.js const PARSER_NAME_PLACEHOLDER: &'static str = "PARSER_NAME"; const CLI_VERSION_PLACEHOLDER: &'static str = "CLI_VERSION"; const CLI_VERSION: &'static str = env!("CARGO_PKG_VERSION"); +const RUST_BINDING_VERSION: &'static str = env!("RUST_BINDING_VERSION"); +const RUST_BINDING_VERSION_PLACEHOLDER: &'static str = "RUST_BINDING_VERSION"; pub fn generate_binding_files(repo_path: &Path, language_name: &str) -> Result<()> { let bindings_dir = repo_path.join("bindings"); @@ -116,7 +118,8 @@ fn generate_file(path: &Path, template: &str, language_name: &str) -> Result<()> path, template .replace(PARSER_NAME_PLACEHOLDER, language_name) - .replace(CLI_VERSION_PLACEHOLDER, CLI_VERSION), + .replace(CLI_VERSION_PLACEHOLDER, CLI_VERSION) + .replace(RUST_BINDING_VERSION_PLACEHOLDER, RUST_BINDING_VERSION), ) } diff --git a/cli/src/generate/templates/cargo.toml b/cli/src/generate/templates/cargo.toml index 8a99da9e..ccb72def 100644 --- a/cli/src/generate/templates/cargo.toml +++ b/cli/src/generate/templates/cargo.toml @@ -4,7 +4,7 @@ description = "PARSER_NAME grammar for the tree-sitter parsing library" version = "0.0.1" keywords = ["incremental", "parsing", "PARSER_NAME"] categories = ["parsing", "text-editors"] -repository = "https://github.com/tree-sitter/tree-sitter-javascript" +repository = "https://github.com/tree-sitter/tree-sitter-PARSER_NAME" edition = "2018" license = "MIT" @@ -20,7 +20,7 @@ include = [ path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "0.19.3" +tree-sitter = "~RUST_BINDING_VERSION" [build-dependencies] cc = "1.0"