From 917cd29646a26278007fbc005156ab73803ac309 Mon Sep 17 00:00:00 2001 From: Brendan Szymanski Date: Wed, 12 Aug 2026 21:24:25 -0400 Subject: [PATCH] Define __GI_SCANNER__ in generated umbrella headers Avoids Clang module conflicts when a NEON/SIMD-gated system header (e.g. Graphene's graphene_simd4f_t backend) is reachable from two different .systemLibrary modules on aarch64 Linux: one pulls in the real _Builtin_intrinsics.arm.acle module, the other re-parses the same header textually, and Clang rejects the resulting conflicting uint32_t/__fsid_t redeclarations. __GI_SCANNER__ is the escape hatch these libraries already ship for exactly this class of consumer (a declaration-only binding generator, same as gobject-introspection's own scanner). --- .../CodeGen+Scaffolding.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/GObjectGeneratorCore/CodeGen+Scaffolding.swift b/Sources/GObjectGeneratorCore/CodeGen+Scaffolding.swift index 949fa6f..6ff97ad 100644 --- a/Sources/GObjectGeneratorCore/CodeGen+Scaffolding.swift +++ b/Sources/GObjectGeneratorCore/CodeGen+Scaffolding.swift @@ -149,6 +149,21 @@ extension CodeGenerator { umbrellaHeader += "\n#include " } + // Every umbrella header defines `__GI_SCANNER__` before pulling in + // the system header. GLib, GTK, and Graphene all gate architecture- + // specific `static inline` fast paths (most notably Graphene's + // SSE/ARM-NEON `graphene_simd4f_t` backend) behind `#ifndef + // __GI_SCANNER__`, falling back to a portable scalar/definition-only + // path when it is set - the same escape hatch upstream ships for + // gobject-introspection's scanner, which (like Clang's ClangImporter + // here) only needs declarations, never compiled SIMD bodies. Without + // it, a NEON-using header reachable from two different `.systemLibrary` + // modules (e.g. both CGraphene and CGsk textually include + // ) is compiled with the real Clang builtin + // `_Builtin_intrinsics.arm.acle` module in one and not the other, + // and Clang's module visibility rules reject the resulting + // conflicting `uint32_t`/`__fsid_t` redeclarations on aarch64 - + // reproducible on every aarch64 Linux target, not distro-specific. // No `link` directives: the `.systemLibrary` target carries // `pkgConfig:`, so pkg-config `--libs` supplies the exact linker // flags. Emitting `link "glib-2"` here both duplicates that and @@ -160,7 +175,7 @@ extension CodeGenerator { } """ files["Sources/\(cName)/module.modulemap"] = moduleMap - files["Sources/\(cName)/\(cName).h"] = umbrellaHeader + "\n" + files["Sources/\(cName)/\(cName).h"] = "#define __GI_SCANNER__ 1\n" + umbrellaHeader + "\n" } // Monorepo Package.swift