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

bazel: fix darwin build on hydra #42832

Merged
merged 1 commit into from Jul 2, 2018

Conversation

uri-canva
Copy link
Contributor

@uri-canva uri-canva commented Jul 1, 2018

Motivation for this change

The bazel accesses a lot of system installed tools, especially on darwin, because the default bazel toolchain hardcodes absolute paths to binaries in /bin and /usr/bin. This adds a separate nix toolchain definition that bazel can use to build C code referencing only nix packages.

Note this doesn't make the whole build sandbox safe, just the C parts, and the resulting bazel binary's default toolchain still hardcodes the same absolute paths.

See https://github.com/bazelbuild/bazel/wiki/Yet-Another-CROSSTOOL-Writing-Tutorial for information on the CROSSTOOL and BUILD file. They have been copied from the default: https://github.com/bazelbuild/bazel/blob/0.13.0/tools/cpp/CROSSTOOL.

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 nox --run "nox-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)
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg GrahamcOfBorg added the 6.topic: darwin Running or building packages on Darwin label Jul 1, 2018
@uri-canva
Copy link
Contributor Author

There has to be a better way of templating files than inlining them in the nix file and editing it with sed.

@uri-canva
Copy link
Contributor Author

cc @matthewbauer

@uri-canva uri-canva mentioned this pull request Jul 2, 2018
8 tasks
zip
python
unzip
makeWrapper
which
customBash
] ++ lib.optionals (stdenv.isDarwin) [ libcxx CoreFoundation CoreServices Foundation ];
] ++ lib.optionals (stdenv.isDarwin) [ cctools clang libcxx CoreFoundation CoreServices Foundation ];
Copy link
Member

Choose a reason for hiding this comment

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

Clang shouldn't be needed - it will be provided by stdenv.

@matthewbauer matthewbauer merged commit b2b6886 into NixOS:master Jul 2, 2018
@uri-canva uri-canva deleted the bazel-hydra-darwin branch July 2, 2018 15:58
@Profpatsch
Copy link
Member

Profpatsch commented Jul 13, 2018

Huh, I’m not sure why this was merged, when it’s just a dump of multiple files directly into the nix expression. Sorry to say, but these changes makes the whole thing completely unmaintainable. 💢

I’d rather revert and have it reworked tbh.

@Profpatsch Profpatsch mentioned this pull request Jul 13, 2018
9 tasks
@Profpatsch
Copy link
Member

I’m sorry, I have to revert this change for now, in consultation with @mboes . We can’t just dump hundreds of lines of external files into our package definitions, this will be unmaintainable in the long run.

I’m sure we can find a better way to fix the build for darwin.

@uri-canva
Copy link
Contributor Author

No problem, I was hoping there would be a better way of templating the files.

#43479 (comment)

@uri-canva If you want, you can open a new pull request and I can review what parts need to be changed.

Can you review this pull request? Then I can update the code and open a new one based on it.

Note that there's so many files that need to be added because we need to define a toolchain to use on macOS, as Nix does not have the default one Bazel includes the definitions for. Linux hasn't had this issue yet because it does not build any embedded c/c++/objc binaries, but if they're ever added it will have the same issue.

@uri-canva
Copy link
Contributor Author

See #43479 (comment) for why I chose this approach.

Copy link
Member

@Profpatsch Profpatsch left a comment

Choose a reason for hiding this comment

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

I left a few comments why I reverted the commit. I honestly don’t see the reason for all this code from the documentation, except that bazel apperently doesn’t work on Darwin (which I cannot check, because I don’t own a machine by Apple).

There should definitely also be a test in place that can test bazel on Darwin automatically (which ofborg can then check).

}
linking_mode_flags { mode: DYNAMIC }
}
'' + lib.optionalString stdenv.isLinux ''
Copy link
Member

Choose a reason for hiding this comment

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

Essentially the same file as above as far as I can see (it’s hard to diff by scrolling, but it looks like it is mostly a duplicate).

)
'';

crosstoolFile = writeText "CROSSTOOL" (''
Copy link
Member

Choose a reason for hiding this comment

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

This should use nix’ importing capabilities, since it’s a quite long file.
It consists mostly of “magic”, which is copied mostly verbatim as snippets from here as far as I can see.

It is also not clear at all from the nix file where the source comes from or what it does. Such a giant unknown code snippet should be documented extraordinarily well, and directly in the code (in order to not be “magic” to everybody but the commiter.)

}
'');

osxCcWrapperFile = writeScript "osx_cc_wrapper.sh" (if stdenv.isDarwin then ''
Copy link
Member

Choose a reason for hiding this comment

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

We can’t seriously copy files verbatim into our package expressions, with legal headers even. It should be put into a (temporary if possible, well documented) file instead.

@uri-canva uri-canva mentioned this pull request Jul 28, 2018
9 tasks
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.

None yet

4 participants