From a53f9c38dd0656722d80819d605d7842e201b374 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 23 Nov 2023 18:12:57 +0100 Subject: [PATCH 1/5] Use non-prebuild Java toolchain configuration On NixOS we cannot use the pre-built `ijar` and `singlejar` tools as they are not statically build and fail to find the dynamic linker. Fixes #278 --- toolchains/java/local_java_repository.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toolchains/java/local_java_repository.bzl b/toolchains/java/local_java_repository.bzl index cccc4465f..4b889c819 100644 --- a/toolchains/java/local_java_repository.bzl +++ b/toolchains/java/local_java_repository.bzl @@ -14,7 +14,7 @@ """Rules for importing and registering a local JDK.""" -load(":default_java_toolchain.bzl", "default_java_toolchain") +load(":default_java_toolchain.bzl", "NONPREBUILT_TOOLCHAIN_CONFIGURATION", "default_java_toolchain") def _detect_java_version(repository_ctx, java_bin): properties_out = repository_ctx.execute([java_bin, "-XshowSettings:properties"]).stderr @@ -99,10 +99,10 @@ def local_java_runtime(name, java_home, version, runtime_name = None, visibility for version in range(8, int(version) + 1): default_java_toolchain( name = name + "_toolchain_java" + str(version), + configuration = NONPREBUILT_TOOLCHAIN_CONFIGURATION, source_version = str(version), target_version = str(version), java_runtime = runtime_name, - exec_compatible_with = exec_compatible_with, target_compatible_with = target_compatible_with, ) From 9ab31c50847456832eb9db2535dfa99c705429d2 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Fri, 24 Nov 2023 09:03:51 +0100 Subject: [PATCH 2/5] Update rules_java to 6.5.2 We were still on version 4.0.0 but already got version 5.5.1 in the resolved dependency graph. We need to use at least version 6.1.0 since former versions of rules_java failed to declare a dependency on rules_license which is now referenced. --- testing/cc/MODULE.bazel | 2 +- testing/go-bzlmod/MODULE.bazel | 2 +- testing/java/MODULE.bazel | 2 +- testing/nodejs/MODULE.bazel | 2 +- testing/posix/MODULE.bazel | 2 +- testing/python/MODULE.bazel | 2 +- testing/rust/MODULE.bazel | 2 +- toolchains/java/MODULE.bazel | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/testing/cc/MODULE.bazel b/testing/cc/MODULE.bazel index 177a78136..61f6141f7 100644 --- a/testing/cc/MODULE.bazel +++ b/testing/cc/MODULE.bazel @@ -24,7 +24,7 @@ bazel_dep(name = "rules_cc", version = "0.0.4") # TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has # become a module extension in rules_nixpkgs_java. bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") use_repo(java_toolchains, "remote_java_tools") diff --git a/testing/go-bzlmod/MODULE.bazel b/testing/go-bzlmod/MODULE.bazel index ec6f1bbe9..a2753294b 100644 --- a/testing/go-bzlmod/MODULE.bazel +++ b/testing/go-bzlmod/MODULE.bazel @@ -30,7 +30,7 @@ bazel_dep(name = "rules_cc", version = "0.0.4") # TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has # become a module extension in rules_nixpkgs_java. bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") use_repo(java_toolchains, "remote_java_tools") diff --git a/testing/java/MODULE.bazel b/testing/java/MODULE.bazel index 92818dde6..db203dcc9 100644 --- a/testing/java/MODULE.bazel +++ b/testing/java/MODULE.bazel @@ -17,7 +17,7 @@ bazel_dep(name = "bazel_skylib", version = "1.0.3") # TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has # become a module extension in rules_nixpkgs_java. bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") use_repo(java_toolchains, "remote_java_tools") diff --git a/testing/nodejs/MODULE.bazel b/testing/nodejs/MODULE.bazel index 3a492e48b..34440bcb2 100644 --- a/testing/nodejs/MODULE.bazel +++ b/testing/nodejs/MODULE.bazel @@ -31,7 +31,7 @@ bazel_dep(name = "rules_nodejs", version = "5.5.3") # TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has # become a module extension in rules_nixpkgs_java. bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") use_repo(java_toolchains, "remote_java_tools") diff --git a/testing/posix/MODULE.bazel b/testing/posix/MODULE.bazel index a0ed63f0f..452a6434a 100644 --- a/testing/posix/MODULE.bazel +++ b/testing/posix/MODULE.bazel @@ -24,7 +24,7 @@ bazel_dep(name = "rules_sh", version = "0.3.0") # TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has # become a module extension in rules_nixpkgs_java. bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") use_repo(java_toolchains, "remote_java_tools") diff --git a/testing/python/MODULE.bazel b/testing/python/MODULE.bazel index 8bfbcd180..10f9203a4 100644 --- a/testing/python/MODULE.bazel +++ b/testing/python/MODULE.bazel @@ -30,7 +30,7 @@ bazel_dep(name = "rules_cc", version = "0.0.4") # TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has # become a module extension in rules_nixpkgs_java. bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") use_repo(java_toolchains, "remote_java_tools") diff --git a/testing/rust/MODULE.bazel b/testing/rust/MODULE.bazel index feba4746e..8bbfa8eb4 100644 --- a/testing/rust/MODULE.bazel +++ b/testing/rust/MODULE.bazel @@ -31,7 +31,7 @@ bazel_dep(name = "rules_rust", version = "0.22.0") # TODO[AH] Remove these transitive dependencies once nixpkgs_java_configure has # become a module extension in rules_nixpkgs_java. bazel_dep(name = "platforms", version = "0.0.4") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains") use_repo(java_toolchains, "remote_java_tools") diff --git a/toolchains/java/MODULE.bazel b/toolchains/java/MODULE.bazel index 77a54f3e7..b7b6356ec 100644 --- a/toolchains/java/MODULE.bazel +++ b/toolchains/java/MODULE.bazel @@ -4,5 +4,5 @@ module( ) bazel_dep(name = "rules_nixpkgs_core", version = "0.10.0") -bazel_dep(name = "rules_java", version = "4.0.0") +bazel_dep(name = "rules_java", version = "6.5.2") bazel_dep(name = "bazel_skylib", version = "1.0.3") From a4019ab7f7969d66f486ed7153722d96ffd73a48 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Fri, 24 Nov 2023 09:44:50 +0100 Subject: [PATCH 3/5] Do not use Xcode on MacOS This fixes CI errors for toolchains/java: ``` external/bazel_tools/tools/osx/xcode_configure.bzl:93:14: Invoking xcodebuild failed, developer dir: /Applications/Xcode_12.4.app/Contents/Developer ,return code 1, stderr: src/main/tools/process-wrapper-legacy.cc:80: "execvp(xcrun, ...)": No such file or directory ``` --- nix/flake.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/flake.nix b/nix/flake.nix index e37384c02..e56ac9a84 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -18,6 +18,9 @@ in { devShells.default = with pkgs; mkShell { + # do not use Xcode on macOS + BAZEL_USE_CPP_ONLY_TOOLCHAIN = "1"; + name = "rules_nixpkgs_shell"; packages = [ bazel_6 bazel-buildtools cacert gcc nix git openssh ]; }; From 5c70ff376d10be85d85d99fa5aeadf0503b0867f Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Fri, 24 Nov 2023 11:45:25 +0100 Subject: [PATCH 4/5] Explicitly select C++ as the language for nixpkgs compilers --- nix/flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nix/flake.nix b/nix/flake.nix index e56ac9a84..cecc754ce 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -20,6 +20,8 @@ devShells.default = with pkgs; mkShell { # do not use Xcode on macOS BAZEL_USE_CPP_ONLY_TOOLCHAIN = "1"; + # for nixpkgs cc wrappers, select C++ explicitly (see https://github.com/NixOS/nixpkgs/issues/150655) + BAZEL_CXXOPTS = "-x:c++"; name = "rules_nixpkgs_shell"; packages = [ bazel_6 bazel-buildtools cacert gcc nix git openssh ]; From de6e2b893521d0b327788cc93f9f78cafe409c59 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Fri, 24 Nov 2023 11:51:01 +0100 Subject: [PATCH 5/5] Add `cctools` to build inputs on Darwin Bazel requires `libtool` for creating static archives on Darwin instead of the `ar` tool. --- nix/flake.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/flake.nix b/nix/flake.nix index cecc754ce..2084490e3 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -24,6 +24,7 @@ BAZEL_CXXOPTS = "-x:c++"; name = "rules_nixpkgs_shell"; + buildInputs = lib.optional pkgs.stdenv.isDarwin darwin.cctools; packages = [ bazel_6 bazel-buildtools cacert gcc nix git openssh ]; }; });