Skip to content

Commit

Permalink
Merge pull request #621 from tweag/mp/remove_nixpkgs_cc_configure_dep…
Browse files Browse the repository at this point in the history
…recated

remove nixpkgs_cc_configure_deprecated
  • Loading branch information
mergify[bot] authored Dec 2, 2024
2 parents ed6f740 + a6040b0 commit ad1e338
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 276 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

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

### Removed

- `nixpkgs_cc_configure_deprecated` was removed since it depended on Bazel's `cc_autoconf_impl`, which [was removed from `@bazel_tools`](https://github.com/bazelbuild/bazel/commit/1c4e78a9ceab9794140324d64833c628e382a3da) and moved into a private package in `rules_cc` in Bazel 8.

## [0.12.0] - 2024-07-12

[0.12.0]: https://github.com/tweag/rules_nixpkgs/compare/v0.11.1...v0.12.0
Expand Down
132 changes: 0 additions & 132 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ See [examples](/examples/toolchains) for how to use `rules_nixpkgs` with differe
* [nixpkgs_package](#nixpkgs_package)
* [nixpkgs_flake_package](#nixpkgs_flake_package)
* [nixpkgs_cc_configure](#nixpkgs_cc_configure)
* [nixpkgs_cc_configure_deprecated](#nixpkgs_cc_configure_deprecated)
* [nixpkgs_java_configure](#nixpkgs_java_configure)
* [nixpkgs_python_configure](#nixpkgs_python_configure)
* [nixpkgs_python_repository](#nixpkgs_python_repository)
Expand Down Expand Up @@ -415,137 +414,6 @@ string, `""` by default. Used if you want to add a cross compilation C/C++ toolc
</table>


<a id="#nixpkgs_cc_configure_deprecated"></a>

### nixpkgs_cc_configure_deprecated

<pre>
nixpkgs_cc_configure_deprecated(<a href="#nixpkgs_cc_configure_deprecated-repository">repository</a>, <a href="#nixpkgs_cc_configure_deprecated-repositories">repositories</a>, <a href="#nixpkgs_cc_configure_deprecated-nix_file">nix_file</a>, <a href="#nixpkgs_cc_configure_deprecated-nix_file_deps">nix_file_deps</a>, <a href="#nixpkgs_cc_configure_deprecated-nix_file_content">nix_file_content</a>,
<a href="#nixpkgs_cc_configure_deprecated-nixopts">nixopts</a>)
</pre>

Use a CC toolchain from Nixpkgs. No-op if not a nix-based platform.

Tells Bazel to use compilers and linkers from Nixpkgs for the CC toolchain.
By default, Bazel auto-configures a CC toolchain from commands available in
the environment (e.g. `gcc`). Overriding this autodetection makes builds
more hermetic and is considered a best practice.

#### Example

```bzl
nixpkgs_cc_configure(repository = "@nixpkgs//:default.nix")
```


#### Parameters

<table class="params-table">
<colgroup>
<col class="col-param" />
<col class="col-description" />
</colgroup>
<tbody>
<tr id="nixpkgs_cc_configure_deprecated-repository">
<td><code>repository</code></td>
<td>

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

<p>

A repository label identifying which Nixpkgs to use.
Equivalent to `repositories = { "nixpkgs": ...}`.

</p>
</td>
</tr>
<tr id="nixpkgs_cc_configure_deprecated-repositories">
<td><code>repositories</code></td>
<td>

optional.
default is <code>{}</code>

<p>

A dictionary mapping `NIX_PATH` entries to repository labels.

Setting it to
```
repositories = { "myrepo" : "//:myrepo" }
```
for example would replace all instances of `<myrepo>` in the called nix code by the path to the target `"//:myrepo"`. See the [relevant section in the nix manual](https://nixos.org/nix/manual/#env-NIX_PATH) for more information.

Specify one of `repository` or `repositories`.

</p>
</td>
</tr>
<tr id="nixpkgs_cc_configure_deprecated-nix_file">
<td><code>nix_file</code></td>
<td>

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

<p>

An expression for a Nix environment derivation.
The environment should expose all the commands that make up a CC
toolchain (`cc`, `ld` etc). Exposes all commands in `stdenv.cc` and
`binutils` by default.

</p>
</td>
</tr>
<tr id="nixpkgs_cc_configure_deprecated-nix_file_deps">
<td><code>nix_file_deps</code></td>
<td>

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

<p>

Dependencies of `nix_file` if any.

</p>
</td>
</tr>
<tr id="nixpkgs_cc_configure_deprecated-nix_file_content">
<td><code>nix_file_content</code></td>
<td>

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

<p>

An expression for a Nix environment derivation.

</p>
</td>
</tr>
<tr id="nixpkgs_cc_configure_deprecated-nixopts">
<td><code>nixopts</code></td>
<td>

optional.
default is <code>[]</code>

<p>

Options to forward to the nix command.

</p>
</td>
</tr>
</tbody>
</table>


<a id="#nixpkgs_flake_package"></a>

### nixpkgs_flake_package
Expand Down
1 change: 0 additions & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ generate_documentation(
"nixpkgs_package",
"nixpkgs_flake_package",
"nixpkgs_cc_configure",
"nixpkgs_cc_configure_deprecated",
"nixpkgs_go_configure",
"nixpkgs_java_configure",
"nixpkgs_python_configure",
Expand Down
143 changes: 0 additions & 143 deletions nixpkgs/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ See [examples](/examples/toolchains) for how to use `rules_nixpkgs` with differe
* [nixpkgs_package](#nixpkgs_package)
* [nixpkgs_flake_package](#nixpkgs_flake_package)
* [nixpkgs_cc_configure](#nixpkgs_cc_configure)
* [nixpkgs_cc_configure_deprecated](#nixpkgs_cc_configure_deprecated)
* [nixpkgs_java_configure](#nixpkgs_java_configure)
* [nixpkgs_python_configure](#nixpkgs_python_configure)
* [nixpkgs_python_repository](#nixpkgs_python_repository)
Expand Down Expand Up @@ -113,7 +112,6 @@ nixpkgs_package(
```
"""

load("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_autoconf_impl")
load(
"@rules_nixpkgs_core//:private/get_cpu_value.bzl",
"get_cpu_value",
Expand Down Expand Up @@ -173,144 +171,3 @@ nixpkgs_rust_configure = _nixpkgs_rust_configure
nixpkgs_sh_posix_configure = _nixpkgs_sh_posix_configure
nixpkgs_nodejs_configure = _nixpkgs_nodejs_configure
nixpkgs_nodejs_configure_platforms = _nixpkgs_nodejs_configure_platforms

def nixpkgs_cc_autoconf_impl(repository_ctx):
cpu_value = get_cpu_value(repository_ctx)
if not is_supported_platform(repository_ctx):
cc_autoconf_impl(repository_ctx)
return

# Calling repository_ctx.path() on anything but a regular file
# fails. So the roundabout way to do the same thing is to find
# a regular file we know is in the workspace (i.e. the WORKSPACE
# file itself) and then use dirname to get the path of the workspace
# root.
workspace_file_path = repository_ctx.path(
Label("@nixpkgs_cc_toolchain//:WORKSPACE"),
)
workspace_root = execute_or_fail(
repository_ctx,
["dirname", workspace_file_path],
).stdout.rstrip()

# Make a list of all available tools in the Nix derivation. Override
# the Bazel autoconfiguration with the tools we found.
bin_contents = find_children(repository_ctx, workspace_root + "/bin")
overriden_tools = {
tool: repository_ctx.path(entry).realpath
for entry in bin_contents
for tool in [entry.rpartition("/")[-1]] # Compute basename
}
cc_autoconf_impl(repository_ctx, overriden_tools = overriden_tools)

nixpkgs_cc_autoconf = repository_rule(
implementation = nixpkgs_cc_autoconf_impl,
# Copied from
# https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl.
# Keep in sync.
environ = [
"ABI_LIBC_VERSION",
"ABI_VERSION",
"BAZEL_COMPILER",
"BAZEL_HOST_SYSTEM",
"BAZEL_LINKOPTS",
"BAZEL_PYTHON",
"BAZEL_SH",
"BAZEL_TARGET_CPU",
"BAZEL_TARGET_LIBC",
"BAZEL_TARGET_SYSTEM",
"BAZEL_USE_CPP_ONLY_TOOLCHAIN",
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN",
"BAZEL_USE_LLVM_NATIVE_COVERAGE",
"BAZEL_VC",
"BAZEL_VS",
"BAZEL_LLVM",
"USE_CLANG_CL",
"CC",
"CC_CONFIGURE_DEBUG",
"CC_TOOLCHAIN_NAME",
"CPLUS_INCLUDE_PATH",
"GCOV",
"HOMEBREW_RUBY_PATH",
"SYSTEMROOT",
"VS90COMNTOOLS",
"VS100COMNTOOLS",
"VS110COMNTOOLS",
"VS120COMNTOOLS",
"VS140COMNTOOLS",
],
)

def nixpkgs_cc_configure_deprecated(
repository = None,
repositories = {},
nix_file = None,
nix_file_deps = None,
nix_file_content = None,
nixopts = []):
"""Use a CC toolchain from Nixpkgs. No-op if not a nix-based platform.
Tells Bazel to use compilers and linkers from Nixpkgs for the CC toolchain.
By default, Bazel auto-configures a CC toolchain from commands available in
the environment (e.g. `gcc`). Overriding this autodetection makes builds
more hermetic and is considered a best practice.
#### Example
```bzl
nixpkgs_cc_configure(repository = "@nixpkgs//:default.nix")
```
Args:
repository: A repository label identifying which Nixpkgs to use.
Equivalent to `repositories = { "nixpkgs": ...}`.
repositories: A dictionary mapping `NIX_PATH` entries to repository labels.
Setting it to
```
repositories = { "myrepo" : "//:myrepo" }
```
for example would replace all instances of `<myrepo>` in the called nix code by the path to the target `"//:myrepo"`. See the [relevant section in the nix manual](https://nixos.org/nix/manual/#env-NIX_PATH) for more information.
Specify one of `repository` or `repositories`.
nix_file: An expression for a Nix environment derivation.
The environment should expose all the commands that make up a CC
toolchain (`cc`, `ld` etc). Exposes all commands in `stdenv.cc` and
`binutils` by default.
nix_file_deps: Dependencies of `nix_file` if any.
nix_file_content: An expression for a Nix environment derivation.
nixopts: Options to forward to the nix command.
Deprecated:
Use `nixpkgs_cc_configure` instead.
While this improves upon Bazel's autoconfigure toolchain by picking tools
from a Nix derivation rather than the environment, it is still not fully
hermetic as it is affected by the environment. In particular, system
include directories specified in the environment can leak in and affect
the cache keys of targets depending on the cc toolchain leading to cache
misses.
"""
if not nix_file and not nix_file_content:
nix_file_content = """
with import <nixpkgs> { config = {}; overlays = []; }; buildEnv {
name = "bazel-cc-toolchain";
paths = [ stdenv.cc binutils ];
}
"""
nixpkgs_package(
name = "nixpkgs_cc_toolchain",
repository = repository,
repositories = repositories,
nix_file = nix_file,
nix_file_deps = nix_file_deps,
nix_file_content = nix_file_content,
build_file_content = """exports_files(glob(["bin/*"]))""",
nixopts = nixopts,
)

# Following lines should match
# https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl#L93.
nixpkgs_cc_autoconf(name = "local_config_cc")
native.bind(name = "cc_toolchain", actual = "@local_config_cc//:toolchain")
native.register_toolchains("@local_config_cc//:all")

0 comments on commit ad1e338

Please sign in to comment.