@@ -150,6 +150,64 @@ async function consolidate_lib64(pkg_prefix: Path) {
150150 Deno . symlinkSync ( "lib" , lib64 . string )
151151}
152152
153+ // headers that must not be flattened into include/ as they would shadow
154+ // system/libc headers (compared case-insensitively for macOS HFS+/APFS)
155+ const SYSTEM_HEADERS = new Set ( [
156+ "assert.h" ,
157+ "complex.h" ,
158+ "ctype.h" ,
159+ "errno.h" ,
160+ "fenv.h" ,
161+ "float.h" ,
162+ "inttypes.h" ,
163+ "iso646.h" ,
164+ "limits.h" ,
165+ "locale.h" ,
166+ "math.h" ,
167+ "setjmp.h" ,
168+ "signal.h" ,
169+ "stdalign.h" ,
170+ "stdarg.h" ,
171+ "stdatomic.h" ,
172+ "stdbool.h" ,
173+ "stddef.h" ,
174+ "stdint.h" ,
175+ "stdio.h" ,
176+ "stdlib.h" ,
177+ "stdnoreturn.h" ,
178+ "string.h" ,
179+ "tgmath.h" ,
180+ "threads.h" ,
181+ "time.h" ,
182+ "uchar.h" ,
183+ "wchar.h" ,
184+ "wctype.h" ,
185+ // POSIX
186+ "dirent.h" ,
187+ "fcntl.h" ,
188+ "glob.h" ,
189+ "grp.h" ,
190+ "netdb.h" ,
191+ "poll.h" ,
192+ "pthread.h" ,
193+ "pwd.h" ,
194+ "regex.h" ,
195+ "sched.h" ,
196+ "search.h" ,
197+ "semaphore.h" ,
198+ "spawn.h" ,
199+ "strings.h" ,
200+ "syslog.h" ,
201+ "termios.h" ,
202+ "unistd.h" ,
203+ "utime.h" ,
204+ "wordexp.h" ,
205+ // common C++ / platform headers that cause trouble
206+ "memory.h" ,
207+ "version.h" ,
208+ "module.h" ,
209+ ] )
210+
153211async function flatten_headers ( pkg_prefix : Path ) {
154212 // if include/ contains exactly one subdirectory and no loose files, flatten it
155213 // eg. include/foo/*.h → include/*.h with include/foo → symlink to .
@@ -168,6 +226,19 @@ async function flatten_headers(pkg_prefix: Path) {
168226 const subdir = subdirs [ 0 ]
169227 const name = subdir . basename ( )
170228
229+ // check for headers that would shadow system headers (case-insensitive for macOS)
230+ const dominated : string [ ] = [ ]
231+ for await ( const [ path ] of subdir . ls ( ) ) {
232+ const lower = path . basename ( ) . toLowerCase ( )
233+ if ( SYSTEM_HEADERS . has ( lower ) ) {
234+ dominated . push ( path . basename ( ) )
235+ }
236+ }
237+ if ( dominated . length > 0 ) {
238+ console . log ( { skipping_flatten : name , would_shadow : dominated } )
239+ return
240+ }
241+
171242 // move all contents up
172243 for await ( const [ path ] of subdir . ls ( ) ) {
173244 Deno . renameSync ( path . string , include . join ( path . basename ( ) ) . string )
0 commit comments