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

(regression) building macOS binary without XCode / Command Line Tools installed fails #10217

Closed
slimsag opened this issue Nov 25, 2021 · 8 comments · Fixed by #10226
Closed
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Milestone

Comments

@slimsag
Copy link
Contributor

slimsag commented Nov 25, 2021

Zig Version

0.9.0-dev.1696+ff9a44a9f

Steps to Reproduce

  1. On a Mac machine without XCode / XCode Command Line Tools installed
  2. zig build any Zig project without cross-compilation
  3. zig build -D=target=aarch64-macos with cross-compilation (to the same target as the host)

Expected Behavior

Both commands should successfully build a macOS binary without XCode / Command Line Tools being installed.

Given that Zig can cross-compile for macOS without those being installed on other targets, I think it is a super nice property to maintain that if you don't have those installed on a mac host that you don't have to install them - specifically because they are multi-GB downloads that can often take a half hour to install.

In prior versions of Zig (several months after 0.8 was released) both commands would succeed without XCode / Command Line Tools being installed. After the introduction of calling xcrun in Zig, however, these began to fail. I've been meaning to file this for a while now. @kubkon

Actual Behavior

Both commands fail with the following:

Zig attempted to find the path to native system libc headers by executing this command:
cc -E -Wp,-v -xc /dev/null
Output:
==========
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.

After running, the xcrun dialog box prompting to install XCode pops up. If you dismiss it and re-run the zig command multiple times, it eventually succeeds in producing the binary without XCode.

@slimsag slimsag added the bug Observed behavior contradicts documented or intended behavior label Nov 25, 2021
@andrewrk andrewrk added this to the 0.9.0 milestone Nov 25, 2021
@andrewrk
Copy link
Member

andrewrk commented Nov 25, 2021

I just want to confirm that this is indeed a regression from intended behavior, and we should be sure to resolve it before tagging 0.9.0.

@kubkon
Copy link
Member

kubkon commented Nov 25, 2021

@slimsag Oh I see now. The issue does not seem to be with xcrun but rather with the fact that we incorrectly try to detect native libc include dirs in Compilation.detectLibCIncludeDirs. I'll need to investigate further if #10215 is a full fix, as I think a slight additional change to the detectLibCIncludeDirs might be required.

@slimsag
Copy link
Contributor Author

slimsag commented Nov 26, 2021

@andrewrk It is definitely a regression in behavior since the 0.8 release, yes. That said, it is fairly minor behavior (most people have XCode installed) and it has a straightforward workaround (install XCode), so not the end of the world if we tag 0.9 without a fix for it.

@kubkon thanks for the investigation and PR, I will test+review today!

@kubkon
Copy link
Member

kubkon commented Nov 26, 2021

@andrewrk It is definitely a regression in behavior since the 0.8 release, yes. That said, it is fairly minor behavior (most people have XCode installed) and it has a straightforward workaround (install XCode), so not the end of the world if we tag 0.9 without a fix for it.

@kubkon thanks for the investigation and PR, I will test+review today!

Actually, it's a huge regression from our perspective, since we really want zig to be a true, bare system replacement on macOS too :-) So I very much appreciate you noting it and submitting a ticket - thank you!

@kubkon
Copy link
Member

kubkon commented Nov 26, 2021

(BTW, I actually nuked my Xcode and CLT testing the fix in the linked PR hahaha)

@slimsag
Copy link
Contributor Author

slimsag commented Nov 26, 2021

Super glad to hear you share that perspective ❤️

Haha, wow. FWIW, in the future if you ever need to test the same thing, I think moving your XCode.app to elsewhere (desktop, trash, etc.) and /Library/Developer/CommandLineTools (CLT) to elsewhere is sufficient - then you can just move them back to avoid the pain of reinstalling :)

@kubkon
Copy link
Member

kubkon commented Nov 26, 2021

Super glad to hear you share that perspective ❤️

Haha, wow. FWIW, in the future if you ever need to test the same thing, I think moving your XCode.app to elsewhere (desktop, trash, etc.) and /Library/Developer/CommandLineTools (CLT) to elsewhere is sufficient - then you can just move them back to avoid the pain of reinstalling :)

So I actually thought about moving Xcode.app but then I noticed it takes 34GB (!!!), so it took me less time to just nuke it. I actually don't need it per se at the moment as I only need macOS SDK for now :-)

@joethephish
Copy link

joethephish commented Dec 16, 2023

Is it possible this has regressed again? I just tried to get set up with zig on a Mac with Sonoma:

  1. brew install zig
  2. zig version --> 0.11.0
  3. zig init-exe
  4. zig build run --> error: unable to create compilation: DarwinSdkNotFound
  5. zig build run again --> error: Unexpected.
  6. If I delete zig-cache it goes back to step 4.

One possible weirdness is that I had an old version incompatible version of Xcode installed. I tried deleting it and the command line tools and still see the same issue though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-macos
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants