Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: system header confusion when compiling C code (current Zig 0.8.0 head) #8360

Closed
floooh opened this issue Mar 25, 2021 · 3 comments
Closed
Labels
arch-x86_64 64-bit x86 bug Observed behavior contradicts documented or intended behavior os-macos zig cc Zig as a drop-in C compiler feature
Milestone

Comments

@floooh
Copy link
Contributor

floooh commented Mar 25, 2021

Update 31-Mar-2021: I have renamed the repro-branch to zig-0.8.0-issue8360, and I've added a workaround to my C headers to make it work regardless by not including the problematic macOS system header, but instead embedding the required declarations in the sokol_audio.h header, not great not terrible - I think the underlying problem should still be investigated and fixed - the "workaround version" is in branch "zig-0.8.0").

  • macOS version: 11.3 Beta (20E5210c)
  • Xcode version: Version 12.4 (12D4e)
  • clang: Apple clang version 12.0.0 (clang-1200.0.32.29)
    Target: x86_64-apple-darwin20.4.0
  • zig: 0.8.0 (installed via brew install --HEAD, last commit: df0f7f4)

Error terminal output attachment: error.txt

To reproduce:

On macOS:

git clone https://github.com/floooh/sokol-zig/
cd sokol-zig
git checkout zig-0.8.0-issue8360
zig build

Description

This is a followup to #7697 (@mikdusan, @kubkon)

I'm now in the process of preparing the sokol-zig bindings for zig 0.8.0, and in general the fixes in this comment (#7697 (comment)) work very well (thanks!) with one exception:

One of the sokol C headers is including the macOS framework header AudioToolbox.h, during the C compilation step an error occurs which seems to be some sort of confusion between the header x86_64-macos-gnu/os/workgroup.h that's coming with Zig, and the actual macOS system headers which include this workgroup.h header:

Here's the first relevant snippet of the error:

error(compilation): clang failed with stderr: In file included from /Users/floh/projects/sokol-zig/src/sokol/c/sokol_audio.c:5:
In file included from /Users/floh/projects/sokol-zig/src/sokol/c/sokol_audio.h:518:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioToolbox.h:19:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AUGraph.h:30:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioUnit.h:21:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioUnitProperties.h:55:
In file included from /usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup.h:30:
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_object.h:48:19: error: a parameter list without types is only allowed in a function definition
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_object.h:93:24: error: unknown type name 'os_workgroup_t'
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_object.h:116:1: error: unknown type name 'os_workgroup_t'
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_object.h:116:16: error: nullability specifier '_Nullable' cannot be applied to non-pointer type 'int'
...

...and further down below:

In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AudioToolbox.framework/Headers/AudioUnitProperties.h:55:
In file included from /usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup.h:31:
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_interval.h:41:28: error: redefinition of parameter 'os_workgroup_interval'
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_interval.h:41:28: error: a parameter list without types is only allowed in a function definition
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_interval.h:94:29: error: unknown type name 'os_workgroup_interval_t'
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_interval.h:123:30: error: unknown type name 'os_workgroup_interval_t'
/usr/local/Cellar/zig/HEAD-df0f7f4/lib/zig/libc/include/x86_64-macos-gnu/os/workgroup_interval.h:148:30: error: unknown type name 'os_workgroup_interval_t'
fatal error: too many errors emitted, stopping now [-ferror-limit=]

The 'verbose' command is:

/usr/local/Cellar/zig/HEAD-df0f7f4/bin/zig build-lib -lc -cflags -ObjC -DIMPL -- /Users/floh/projects/sokol-zig/src/sokol/c/sokol_app.c -cflags -ObjC -DIMPL -- /Users/floh/projects/sokol-zig/src/sokol/c/sokol_gfx.c -cflags -ObjC -DIMPL -- /Users/floh/projects/sokol-zig/src/sokol/c/sokol_time.c -cflags -ObjC -DIMPL -- /Users/floh/projects/sokol-zig/src/sokol/c/sokol_audio.c -cflags -ObjC -DIMPL -- /Users/floh/projects/sokol-zig/src/sokol/c/sokol_gl.c -cflags -ObjC -DIMPL -- /Users/floh/projects/sokol-zig/src/sokol/c/sokol_debugtext.c -cflags -ObjC -DIMPL -- /Users/floh/projects/sokol-zig/src/sokol/c/sokol_shape.c --cache-dir /Users/floh/projects/sokol-zig/zig-cache --global-cache-dir /Users/floh/.cache/zig --name sokol -framework Cocoa -framework AudioToolbox -framework QuartzCore -framework MetalKit -framework Metal --enable-cache 

(the entire output is also attached to the ticket, see attachment link at the start of the ticket).

Any ideas what's going wrong here? It seems to me that the C runtime headers which are bundled with Zig are somehow confused by being included from macOS framework headers. It's also interesting to note that this is only happening in one case with the AudioToolbox framework headers.

If you out-comment the sokol_audio.c file in build.zig here:

https://github.com/floooh/sokol-zig/blob/72c8cb0745cf10414b6a331733a9e57b63a17d7b/build.zig#L15

...the C compilation step works, even though the other headers also include plenty of Mac frameworks (most notable all of Cocoa, Metal and MetalKit).

The compilation also used to work in Zig 0.7.1 with the various "system headers hacks" here (this is the main branch that's still on 0.7.1):

https://github.com/floooh/sokol-zig/blob/b058340b38a376b7af3581b4b5306059b3b817e2/build.zig#L6-L12

Ok, I guess that's all the info I have.

Cheers :)

@kubkon kubkon added arch-x86_64 64-bit x86 bug Observed behavior contradicts documented or intended behavior os-macos zig cc Zig as a drop-in C compiler feature labels Apr 19, 2021
@kubkon kubkon added this to the 0.8.0 milestone Apr 19, 2021
@andrewrk andrewrk modified the milestones: 0.8.0, 0.8.1 Jun 4, 2021
@kubkon
Copy link
Member

kubkon commented Aug 2, 2021

@floooh could you confirm that with latest master everything works as expected since zig ld gained the ability to link against frameworks and correctly link Obj-C? (Just remember to remove any mention of ZIG_SYSTEM_LINKER_HACK since no longer need it! ;-))

@kubkon
Copy link
Member

kubkon commented Aug 2, 2021

BTW, I've built sokol-zig successfully with latest master on arm64 macOS and can happily stare at the generated cubes on my screen.

@kubkon kubkon modified the milestones: 0.8.1, 0.9.0 Aug 2, 2021
@andrewrk
Copy link
Member

andrewrk commented Nov 26, 2021

I'm pretty sure this is solved with 2006add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86_64 64-bit x86 bug Observed behavior contradicts documented or intended behavior os-macos zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

No branches or pull requests

3 participants