From 2b5f7ea24240fd15a7ff811c719a7b506c77621c Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Fri, 29 Nov 2024 20:51:47 +0100 Subject: [PATCH] remove nixpkgs_cc_configure_deprecated `nixpkgs_cc_configure_deprecated` depended on Bazel's cc_autoconf_impl, which was removed from @bazel_tools and moved into a private package in rules_cc in Bazel 8. See also: bazelbuild/bazel#23809 --- CHANGELOG.md | 4 ++ README.md | 132 ---------------------------------------- docs/BUILD.bazel | 1 - nixpkgs/nixpkgs.bzl | 143 -------------------------------------------- 4 files changed, 4 insertions(+), 276 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba63ebe66..9a51442f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 7ab72840e..59e43fff8 100644 --- a/README.md +++ b/README.md @@ -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) @@ -415,137 +414,6 @@ string, `""` by default. Used if you want to add a cross compilation C/C++ toolc - - -### nixpkgs_cc_configure_deprecated - -
-nixpkgs_cc_configure_deprecated(repository, repositories, nix_file, nix_file_deps, nix_file_content,
-                                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") - ``` - - -#### Parameters - - ---- - - - - - - - - - - - - - - - - - - - - - - - - - - -
repository - -optional. -default is None - -

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

-
repositories - -optional. -default is {} - -

- -A dictionary mapping `NIX_PATH` entries to repository labels. - -Setting it to -``` -repositories = { "myrepo" : "//:myrepo" } -``` -for example would replace all instances of `` 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 - -optional. -default is None - -

- -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 - -optional. -default is None - -

- -Dependencies of `nix_file` if any. - -

-
nix_file_content - -optional. -default is None - -

- -An expression for a Nix environment derivation. - -

-
nixopts - -optional. -default is [] - -

- -Options to forward to the nix command. - -

-
- - ### nixpkgs_flake_package diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 397762347..c46ee1b06 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -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", diff --git a/nixpkgs/nixpkgs.bzl b/nixpkgs/nixpkgs.bzl index b928383d0..f16aed784 100644 --- a/nixpkgs/nixpkgs.bzl +++ b/nixpkgs/nixpkgs.bzl @@ -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) @@ -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", @@ -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 `` 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 { 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")