feat(bindings): generate zig fingerprint
This commit is contained in:
parent
422866a437
commit
d86e1b4f5e
5 changed files with 20 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1909,6 +1909,7 @@ dependencies = [
|
|||
"clap",
|
||||
"clap_complete",
|
||||
"clap_complete_nushell",
|
||||
"crc32fast",
|
||||
"ctor",
|
||||
"ctrlc",
|
||||
"dialoguer",
|
||||
|
|
|
|||
|
|
@ -117,6 +117,7 @@ clap = { version = "4.5.45", features = [
|
|||
] }
|
||||
clap_complete = "4.5.57"
|
||||
clap_complete_nushell = "4.5.8"
|
||||
crc32fast = "1.5.0"
|
||||
ctor = "0.2.9"
|
||||
ctrlc = { version = "3.5.0", features = ["termination"] }
|
||||
dialoguer = { version = "0.11.0", features = ["fuzzy-select"] }
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ bstr.workspace = true
|
|||
clap.workspace = true
|
||||
clap_complete.workspace = true
|
||||
clap_complete_nushell.workspace = true
|
||||
crc32fast.workspace = true
|
||||
ctor.workspace = true
|
||||
ctrlc.workspace = true
|
||||
dialoguer.workspace = true
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ use std::{
|
|||
};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use crc32fast::hash as crc32;
|
||||
use heck::{ToKebabCase, ToShoutySnakeCase, ToSnakeCase, ToUpperCamelCase};
|
||||
use indoc::{formatdoc, indoc};
|
||||
use log::warn;
|
||||
use rand::{thread_rng, Rng};
|
||||
use semver::Version;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
|
|
@ -33,6 +35,7 @@ const PARSER_LICENSE_PLACEHOLDER: &str = "PARSER_LICENSE";
|
|||
const PARSER_URL_PLACEHOLDER: &str = "PARSER_URL";
|
||||
const PARSER_URL_STRIPPED_PLACEHOLDER: &str = "PARSER_URL_STRIPPED";
|
||||
const PARSER_VERSION_PLACEHOLDER: &str = "PARSER_VERSION";
|
||||
const PARSER_FINGERPRINT_PLACEHOLDER: &str = "PARSER_FINGERPRINT";
|
||||
|
||||
const AUTHOR_NAME_PLACEHOLDER: &str = "PARSER_AUTHOR_NAME";
|
||||
const AUTHOR_EMAIL_PLACEHOLDER: &str = "PARSER_AUTHOR_EMAIL";
|
||||
|
|
@ -154,7 +157,7 @@ impl JsonConfigOpts {
|
|||
authors: Some(vec![Author {
|
||||
name: self.author,
|
||||
email: self.email,
|
||||
url: self.url.map(|url| url.to_string()),
|
||||
url: self.url,
|
||||
}]),
|
||||
links: Some(Links {
|
||||
repository: self.repository.unwrap_or_else(|| {
|
||||
|
|
@ -1153,6 +1156,18 @@ fn generate_file(
|
|||
}
|
||||
}
|
||||
|
||||
if filename == "build.zig.zon" {
|
||||
let id = thread_rng().gen_range(1u32..0xFFFF_FFFFu32);
|
||||
let checksum = crc32(format!("tree_sitter_{language_name}").as_bytes());
|
||||
replacement = replacement.replace(
|
||||
PARSER_FINGERPRINT_PLACEHOLDER,
|
||||
#[cfg(target_endian = "little")]
|
||||
&format!("0x{checksum:x}{id:x}"),
|
||||
#[cfg(target_endian = "big")]
|
||||
&format!("0x{id:x}{checksum:x}"),
|
||||
);
|
||||
}
|
||||
|
||||
write_file(path, replacement)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
.{
|
||||
.name = .tree_sitter_PARSER_NAME,
|
||||
.fingerprint = PARSER_FINGERPRINT,
|
||||
.version = "PARSER_VERSION",
|
||||
.dependencies = .{
|
||||
.tree_sitter = .{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue