zig icon indicating copy to clipboard operation
zig copied to clipboard

compiler/macOS: Pass framework paths from `-F` through to compiler

Open Tyrubias opened this issue 2 years ago • 3 comments

Changes

  • When build-exe is called with framework paths through -F option, pass the framework paths to compiler too. Reopen of PR #14151. Closes #7838
  • Fixes one of the macOS header discrepancies noticed by @mikdusan. Now, when using the cc driver on macOS, /usr/local/include is included in the list of include paths.

Remarks

  • I looked into the other issue where build-obj uses Zig's bundled macOS headers (rather than the SDK headers) even when not in cross-compilation mode. I believe the reason is because of the following:
    • want_native_include_dirs is set to false here in buildOutputType in src/main.zig when the cc or cpp driver is not used.
    • Therefore, there is no attempt to detect the macOS SDK, and when Compilation.detectLibCIncludeDirs is called by Compilation.create, it defaults to the included headers because of this line
  • I would like to also fix the above issue but I'm not sure if my reasoning is correct or which part of the behavior to fix. I would be very grateful for suggestions as this is my first time contributing to this codebase.

Tyrubias avatar May 23 '23 06:05 Tyrubias

Fixes one of the macOS header discrepancies noticed by @mikdusan. Now, when using the cc driver on macOS, /usr/local/include is included in the list of include paths.

Using MacOS does not imply it should include system headers.

Zig has 2 modes:

  • native compiling iff -target is present.
  • cross-compiling iff -target is absent.

Note that "cross-compiling" to the same architecture is possible (and done often). So I believe the system include paths should be added only when cross-compiling in the "zig" terms.

I cannot comment on other changes.

motiejus avatar May 23 '23 08:05 motiejus

Re your second point, the status quo is that we always want to link against bundled libSystem headers unless a system lib (other than libc, libc++ and libSystem) or framework have been requested. This makes it more consistent if the user is compiling natively or cross-compiling.

kubkon avatar May 23 '23 09:05 kubkon

@motiejus I kind of understand what you're saying but I'm still a little confused. Currently if I run zig cc -c <file>.c -v I get the following include paths:

$ZIG_DIR/lib/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/System/Library/Frameworks (framework directory)

Which scenario does this fall under and should system include paths be present?

Tyrubias avatar May 24 '23 06:05 Tyrubias

comp.framework_dirs is how these things are modeled in the frontend. This PR is not mergeable as is. I suggest making an issue instead of a pull request to explain the problem.

andrewrk avatar Jan 23 '24 20:01 andrewrk