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

buildBazelPackage: autodetect nix toolchain instead of Xcode on Darwin #65308

Merged
merged 4 commits into from Jul 25, 2019

Conversation

kalbasit
Copy link
Member

@kalbasit kalbasit commented Jul 23, 2019

Motivation for this change

buildBazelPackage is autodetecting Xcode clang as opposed to using Nix's clang. This was originally submitted in #56033 by @uri-canva, and removed in #64904 by @abbradar.

closes #65268

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added the 6.topic: darwin Running or building packages on Darwin label Jul 23, 2019
@kalbasit
Copy link
Member Author

@GrahamcOfBorg build bazel-watcher

@uri-canva
Copy link
Contributor

Ah right, now I remember why this was necessary on darwin but not on Linux: the darwin derivations don't have the right hooks to set the environment variables (see #41914 for example), so the derivations that use them need to set the right flags.

@Profpatsch
Copy link
Member

So is this only required on Darwin? If yes, we should special-case.

@kalbasit
Copy link
Member Author

@Profpatsch done! Although the PR should be rebased or squased-merged.

@GrahamcOfBorg build bazel-watcher

@@ -109,13 +113,44 @@ in stdenv.mkDerivation (fBuildAttrs // {
buildPhase = fBuildAttrs.buildPhase or ''
runHook preBuild

'' + lib.optionalString stdenv.isDarwin ''
# Bazel sandboxes the execution of the tools it invokes, so even though we are
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is not accurate because Bazel for buildBazelPackage is built with Nix hacks. Sorry, I didn't fully get why doesn't this work on Darwin - can you re-explain so that we can put this in a comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Darwin packages don't always take advantage of the nix environment variables, see #41914 for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I'll update the comment then as this is already merged.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I realized I'm still missing something while writing a comment. For example in #41914 you set such a variable. If I reason correctly it means that our cc-wrapper works the same for Darwin and can interpret these variables. The code in this PR explicitly converts Nix envvars into additional flags for Bazel. This should only be needed if Nix envvars do not work for Darwin at all, because otherwise they would be passed thanks to Nix hacks.

What am I missing here? Sorry, I don't know anything about Darwin so please bear with me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That PR I did for a separate issue, not related to this change in buildBazelPackage. It's just an example of how the wrappers don't forward flags on Darwin. I'm not sure where in the chain of wrappers the forwarding isn't implemented correctly, last time I tried to find all the spots I found a couple of them, then assumed it wasn't supposed to work on Darwin to begin with (a lot of derivations set compiler and linker flags for Darwin explicitly).

So rather than trying to fix the Darwin wrappers to work like the Linux wrappers I implemented this mechanism of specifying the flags explicitly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I understand the problem now - so the flags are broken somewhere down the line (perhaps in cc-wrapper) and this is a workaround for it. This sounds unfortunate, maybe our Darwin maintainers should take a look?

@NixOS/darwin-maintainers

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the merge okay or should we revert?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should wait and see what the Darwin maintainers have to say. Either we revert and fix it for the whole Darwin or we just update a comment (we can do that without a revert).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were a lot of packages that specify flags for Darwin explicitly last time I checked, I don't think we should keep a regression in buildBazelPackage around (it used to work before #64904) just because of that.

Copy link
Member

@abbradar abbradar Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; what I mean is that if someone has an idea how to fix this globally we could go for that instead.

EDIT: Phone keyboard

@Profpatsch Profpatsch merged commit a8f174f into NixOS:master Jul 25, 2019
@kalbasit kalbasit deleted the nixpkgs_fix-bazel-watcher-darwin branch July 25, 2019 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bazel-watcher is broken on Darwin
4 participants