bazel: make environment compatible with more operating systems.#7086
Conversation
When running the compilation on NixOS, it is not possible currently
to use the llvm_toolchain mentioned in the MODULE.bazel, but necessary
to run the local toolchain (`clangStdenv`). That in turn is strict and
only allows to compile C files when invoked with `clang` and
requires `clang++` or `clang -xc++` to compile C++ files - unlike a typical clang
installation that attempts to auto-detect. But Bazel is lazy and
invokes c++ compilation with `clang` ...
Another issue: the latest rules_cc version has hardcoded paths to
`/bin/bash` while the correct way to use that on Posix systems is to
call it via `/usr/bin/env`.
So, this PR solves both these issues:
* Add `-xc++` to the compiler invocation for cxx compilation.
* Use a rules_cc that has the fix to use /usr/bin/env
(bazelbuild/rules_cc#306), but that
is not released yet on BCR (once 0.1.2 is out we can probably
use that directly).
Signed-off-by: Henner Zeller <hzeller@google.com>
|
clang-tidy review says "All clean, LGTM! 👍" |
|
|
||
| # The current rules_cc 0.1.1 hardcodes script locations to `#!/bin/bash` | ||
| # instead of using `#!/usr/bin/env bash`. | ||
| # This is fixed by https://github.com/bazelbuild/rules_cc/pull/306 but |
There was a problem hiding this comment.
This is closed as of three weeks ago. Is it going to be released?
There was a problem hiding this comment.
it is in the repo, but they have not cut a release yet.
There was a problem hiding this comment.
Weird - it says closed not merged.
|
I'm curious why nix can't use the toolchain compiler. Is it supposed to be self-contained. |
The llvm toolchain repo actually is only self-contained on the surface. It has some shell script that attempts to match the operating system and then downloads the relevant binary from the llvm download site. This mostly works for some more common OSes. However, it doesn't have a match for NixOS. And even if it would download, say the 'debian' version, the binaries are not self-contained as they are dynamically linked which makes it hard to run on Nix because it is very strict what and where libraries are. A proper self-containment would be if it would download llvm sources itself, then boostrap compile it first with the local compiler then again with itself... |
|
I didn't realize it isn't statically linked, that is a hole in the method but I suppose it works on most OSes |
When running the compilation on NixOS, it is not possible currently to use the llvm_toolchain mentioned in the MODULE.bazel, but necessary to run the local toolchain (
clangStdenv). That in turn is strict and only allows to compile C files when invoked withclangand requiresclang++orclang -xc++to compile C++ files - unlike a typical clang installation that attempts to auto-detect. But Bazel is lazy and invokes c++ compilation withclang...Another issue: the latest rules_cc version has hardcoded paths to
/bin/bashwhile the correct way to use that on Posix systems is to call it via/usr/bin/env.So, this PR solves both these issues:
Add
-xc++to the compiler invocation for cxx compilation.Use a rules_cc that has the fix to use
/usr/bin/env(shebang: changed scripts shebang to better support systems like bsd and nixos bazelbuild/rules_cc#306), but that is not released yet on BCR (once 0.1.2 is out we can probably use that directly).