From c474c3aeb4d2400d4cc53c363dfd8b8029d077d6 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Wed, 13 Nov 2024 02:44:43 +0000 Subject: [PATCH] Fix build when passing TREE_SITTER_GRAMMAR_LIB_DIR --- tree-sitter-grammar-repository/build.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tree-sitter-grammar-repository/build.rs b/tree-sitter-grammar-repository/build.rs index af06146..5f6591b 100644 --- a/tree-sitter-grammar-repository/build.rs +++ a/tree-sitter-grammar-repository/build.rs @@ -44,11 +44,19 @@ }; let (config, query_path) = if dylib { - let config: HelixLanguages = basic_toml::from_str( - &fs::read_to_string(root.join("languages.toml")) - .context("failed to read languages.toml")?, - ) - .context("failed to parse helix languages.toml")?; + let config = fs::read_to_string(root.join("languages.toml")) + .context("failed to read helix languages.toml")?; + + // find the start of the language arrays & skip parsing everything before them (primarily because + // `basic_toml` can't handle some of the new syntax used in this file, and `toml` pulls in a lot + // of dependencies) + let language_defs_start = memchr::memmem::find(config.as_bytes(), b"[[language]]") + .context("languages.toml is missing languages")?; + + let config = &config[language_defs_start..]; + + let config: HelixLanguages = + basic_toml::from_str(config).context("failed to parse helix languages.toml")?; println!("cargo::rustc-link-search=native={}", root.display()); -- rgit 0.1.3