fix(bindings): update zig template files (#4637)

This commit is contained in:
Ronald T. Casili 2025-08-09 15:18:07 +08:00 committed by GitHub
parent f7838748df
commit d87921bb9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 99 additions and 59 deletions

View file

@ -98,6 +98,7 @@ const TESTS_SWIFT_TEMPLATE: &str = include_str!("./templates/tests.swift");
const BUILD_ZIG_TEMPLATE: &str = include_str!("./templates/build.zig");
const BUILD_ZIG_ZON_TEMPLATE: &str = include_str!("./templates/build.zig.zon");
const ROOT_ZIG_TEMPLATE: &str = include_str!("./templates/root.zig");
const TEST_ZIG_TEMPLATE: &str = include_str!("./templates/test.zig");
const TREE_SITTER_JSON_SCHEMA: &str =
"https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json";
@ -749,17 +750,39 @@ pub fn generate_grammar_files(
// Generate Zig bindings
if tree_sitter_config.bindings.zig {
missing_path(repo_path.join("build.zig"), |path| {
generate_file(path, BUILD_ZIG_TEMPLATE, language_name, &generate_opts)
})?;
missing_path_else(
repo_path.join("build.zig"),
allow_update,
|path| generate_file(path, BUILD_ZIG_TEMPLATE, language_name, &generate_opts),
|path| {
eprintln!("Replacing build.zig");
generate_file(path, BUILD_ZIG_TEMPLATE, language_name, &generate_opts)
},
)?;
missing_path(repo_path.join("build.zig.zon"), |path| {
generate_file(path, BUILD_ZIG_ZON_TEMPLATE, language_name, &generate_opts)
})?;
missing_path_else(
repo_path.join("build.zig.zon"),
allow_update,
|path| generate_file(path, BUILD_ZIG_ZON_TEMPLATE, language_name, &generate_opts),
|path| {
eprintln!("Replacing build.zig.zon");
generate_file(path, BUILD_ZIG_ZON_TEMPLATE, language_name, &generate_opts)
},
)?;
missing_path(bindings_dir.join("zig"), create_dir)?.apply(|path| {
missing_path(path.join("root.zig"), |path| {
generate_file(path, ROOT_ZIG_TEMPLATE, language_name, &generate_opts)
missing_path_else(
path.join("root.zig"),
allow_update,
|path| generate_file(path, ROOT_ZIG_TEMPLATE, language_name, &generate_opts),
|path| {
eprintln!("Replacing root.zig");
generate_file(path, ROOT_ZIG_TEMPLATE, language_name, &generate_opts)
},
)?;
missing_path(path.join("test.zig"), |path| {
generate_file(path, TEST_ZIG_TEMPLATE, language_name, &generate_opts)
})?;
Ok(())