fix(cli): actual Rust binding version in generated Cargo.toml
This commit is contained in:
parent
4578e58794
commit
f22d62393b
5 changed files with 35 additions and 2 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -74,3 +74,6 @@ features = ["std"]
|
|||
[dev-dependencies]
|
||||
rand = "0.8"
|
||||
tempfile = "3"
|
||||
|
||||
[build-dependencies]
|
||||
toml = "0.5"
|
||||
|
|
|
|||
17
cli/build.rs
17
cli/build.rs
|
|
@ -9,6 +9,12 @@ fn main() {
|
|||
if wasm_files_present() {
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
fn wasm_files_present() -> bool {
|
||||
|
|
@ -67,3 +73,14 @@ fn read_git_sha() -> Option<String> {
|
|||
|
||||
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::<toml::Value>(text.as_ref()).unwrap();
|
||||
cargo_toml["package"]["version"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.trim_matches('"')
|
||||
.to_string()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
@ -121,7 +123,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),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue