Skip to content

Commit

Permalink
Merge pull request #179 from layus/no-registration
Browse files Browse the repository at this point in the history
Make toolchain registration optional
  • Loading branch information
mergify[bot] authored Feb 9, 2022
2 parents e3176e3 + ce1a031 commit de066d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

[Unreleased]: https://github.com/tweag/rules_nixpkgs/compare/v0.8.0...HEAD

### Added

- nixpkgs_cc_configure gained a flag to disable automatic registration of the
toolchain it creates.
See [#179][#179]

## [0.8.0] - 2021-02-11

[0.8.0]: https://github.com/tweag/rules_nixpkgs/compare/v0.7.0...v0.8.0
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ Dependencies of `nix_file` if any.
<pre>
nixpkgs_cc_configure(<a href="#nixpkgs_cc_configure-name">name</a>, <a href="#nixpkgs_cc_configure-attribute_path">attribute_path</a>, <a href="#nixpkgs_cc_configure-nix_file">nix_file</a>, <a href="#nixpkgs_cc_configure-nix_file_content">nix_file_content</a>, <a href="#nixpkgs_cc_configure-nix_file_deps">nix_file_deps</a>, <a href="#nixpkgs_cc_configure-repositories">repositories</a>,
<a href="#nixpkgs_cc_configure-repository">repository</a>, <a href="#nixpkgs_cc_configure-nixopts">nixopts</a>, <a href="#nixpkgs_cc_configure-quiet">quiet</a>, <a href="#nixpkgs_cc_configure-fail_not_supported">fail_not_supported</a>, <a href="#nixpkgs_cc_configure-exec_constraints">exec_constraints</a>,
<a href="#nixpkgs_cc_configure-target_constraints">target_constraints</a>)
<a href="#nixpkgs_cc_configure-target_constraints">target_constraints</a>, <a href="#nixpkgs_cc_configure-register">register</a>)
</pre>

Use a CC toolchain from Nixpkgs. No-op if not a nix-based platform.
Expand Down Expand Up @@ -429,6 +429,20 @@ default is <code>None</code>

Constraints for the target platform.

</p>
</td>
</tr>
<tr id="nixpkgs_cc_configure-register">
<td><code>register</code></td>
<td>

optional.
default is <code>True</code>

<p>

bool, enabled by default, Whether to register (with `register_toolchains`) the generated toolchain and install it as the default cc_toolchain.

</p>
</td>
</tr>
Expand Down
17 changes: 10 additions & 7 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,8 @@ def nixpkgs_cc_configure(
quiet = False,
fail_not_supported = True,
exec_constraints = None,
target_constraints = None):
target_constraints = None,
register = True):
"""Use a CC toolchain from Nixpkgs. No-op if not a nix-based platform.
By default, Bazel auto-configures a CC toolchain from commands (e.g.
Expand Down Expand Up @@ -653,6 +654,7 @@ def nixpkgs_cc_configure(
fail_not_supported: bool, Whether to fail if `nix-build` is not available.
exec_constraints: Constraints for the execution platform.
target_constraints: Constraints for the target platform.
register: bool, enabled by default, Whether to register (with `register_toolchains`) the generated toolchain and install it as the default cc_toolchain.
"""

nixopts = list(nixopts)
Expand Down Expand Up @@ -727,12 +729,13 @@ def nixpkgs_cc_configure(
target_constraints = target_constraints,
)

maybe(
native.bind,
name = "cc_toolchain",
actual = "@{}//:toolchain".format(name),
)
native.register_toolchains("@{}_toolchains//:all".format(name))
if register:
maybe(
native.bind,
name = "cc_toolchain",
actual = "@{}//:toolchain".format(name),
)
native.register_toolchains("@{}_toolchains//:all".format(name))

def _readlink(repository_ctx, path):
return repository_ctx.path(path).realpath
Expand Down

0 comments on commit de066d5

Please sign in to comment.