Only blacklist highlighters with conflicts during statically linked builds
Diff
tree-sitter-grammar-repository/build.rs | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)
@@ -29,6 +29,9 @@
"wren",
"gemini",
];
static BLACKLISTED_FOR_STATIC_LINKING: &[&str] = &[
@@ -110,8 +113,8 @@
let mut grammar_defs = Vec::new();
for grammar in &config.grammar {
let name = &grammar.name;
if let Some(tokens) =
build_language_module(name, query_path.as_path()).with_context(|| name.to_string())?
if let Some(tokens) = build_language_module(name, query_path.as_path(), dylib)
.with_context(|| name.to_string())?
{
grammar_defs.push(tokens);
}
@@ -124,14 +127,14 @@
)
.context("failed to write grammar defs")?;
let registry = build_grammar_registry(config.grammar.iter().map(|v| v.name.clone()));
let registry = build_grammar_registry(config.grammar.iter().map(|v| v.name.clone()), dylib);
fs::write(
out_dir.join("grammar.registry.rs"),
prettyplease::unparse(&syn::parse2(registry).context("failed to parse grammar registry")?),
)
.context("failed to write grammar registry")?;
let language = build_language_registry(config.language)?;
let language = build_language_registry(config.language, dylib)?;
fs::write(
out_dir.join("language.registry.rs"),
prettyplease::unparse(&syn::parse2(language)?),
@@ -142,6 +145,7 @@
fn build_language_registry(
language_definition: Vec<LanguageDefinition>,
dylib: bool,
) -> anyhow::Result<proc_macro2::TokenStream> {
let mut camel = Vec::new();
let mut grammars = Vec::new();
@@ -154,7 +158,9 @@
let mut regex_to_camel = Vec::new();
for language in &language_definition {
if BLACKLISTED_MODULES.contains(&language.name.as_str()) {
if BLACKLISTED_MODULES.contains(&language.name.as_str())
|| (!dylib && BLACKLISTED_FOR_STATIC_LINKING.contains(&language.name.as_str()))
{
continue;
}
@@ -267,9 +273,15 @@
})
}
fn build_grammar_registry(names: impl Iterator<Item = String>) -> proc_macro2::TokenStream {
fn build_grammar_registry(
names: impl Iterator<Item = String>,
dylib: bool,
) -> proc_macro2::TokenStream {
let (ids, plain, camel, snake) = names
.filter(|name| !BLACKLISTED_MODULES.contains(&name.as_str()))
.filter(|name| {
!BLACKLISTED_MODULES.contains(&name.as_str())
&& (dylib || !BLACKLISTED_FOR_STATIC_LINKING.contains(&name.as_str()))
})
.enumerate()
.fold(
(Vec::new(), Vec::new(), Vec::new(), Vec::new()),
@@ -324,8 +336,11 @@
fn build_language_module(
name: &str,
query_path: &Path,
dylib: bool,
) -> anyhow::Result<Option<proc_macro2::TokenStream>> {
if BLACKLISTED_MODULES.contains(&name) {
if BLACKLISTED_MODULES.contains(&name)
|| (!dylib && BLACKLISTED_FOR_STATIC_LINKING.contains(&name))
{
return Ok(None);
}
@@ -393,7 +408,9 @@
let pool = ThreadPool::new(std::thread::available_parallelism()?.get());
for grammar in grammars {
if BLACKLISTED_MODULES.contains(&grammar.name.as_str()) {
if BLACKLISTED_MODULES.contains(&grammar.name.as_str())
|| BLACKLISTED_FOR_STATIC_LINKING.contains(&grammar.name.as_str())
{
continue;
}