forked from tweag/rules_nixpkgs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces a new repository rule `nixpkgs_cc_configure_hermetic` which is meant to replace `nixpkgs_cc_configure`. The latter is implemented by calling Bazel's builtin CC toolchain autodetection with the binary paths overriden to point to Nix provided tools. This is more hermetic than Bazel's default behavior in that the tools are not just picked from `$PATH`. However, it is not hermetic. Bazel's CC toolchain autodetection is influenced by environment variables, and it shells out to the provided `cc` binary in the context of a repository rule to determine system include paths which is also affected by environment variables. Concretely, this caused cache misses due to include paths provided by a `nix-shell` changing the cache keys of build actions depending on the CC toolchain. `nixpkgs_cc_configure_hermetic` on the other hand uses binaries determined by a Nix derivation and performs additional configuration such as determining system include paths within a Nix build, i.e. within Nix's own sandbox. The results are stored in a text file `CC_TOOLCHAIN_INFO` which is then parsed in a Bazel repository rule. From there on the toolchain configuration follows the example of Bazel's builtin CC toolchain for Unix: https://github.com/bazelbuild/bazel/blob/0f4c498a270f05b3896d57055b6489e824821eda/tools/cpp/unix_cc_configure.bzl#L310. Users can override the Nix provided compiler using the `nix_file` or `nix_file_content` and `attribute_path` arguments. The corresponding Nix derivation should produce the required tools, e.g. `bin/cc`.
- Loading branch information
Showing
8 changed files
with
805 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host | ||
build --crosstool_top=@nixpkgs_config_cc//:toolchain | ||
# Using toolchain resolution can lead to spurious dependencies on | ||
# `@local_config_cc//:builtin_include_directory_paths`. This needs to be | ||
# resolved before `--incompatible_enable_cc_toolchain_resolution` can be | ||
# recommended for `nixpkgs_cc_configure_hermetic`. | ||
# build --incompatible_enable_cc_toolchain_resolution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.