diff --git a/pkgs/development/tools/bazel-watcher/default.nix b/pkgs/development/tools/bazel-watcher/default.nix index 5b0dd0349439..816326489d8c 100644 --- a/pkgs/development/tools/bazel-watcher/default.nix +++ b/pkgs/development/tools/bazel-watcher/default.nix @@ -1,4 +1,5 @@ { buildBazelPackage +, bazel_5 , fetchFromGitHub , git , go @@ -10,28 +11,49 @@ let patches = [ ./use-go-in-path.patch ]; + + # Patch the protoc alias so that it always builds from source. + rulesProto = fetchFromGitHub { + owner = "bazelbuild"; + repo = "rules_proto"; + rev = "4.0.0-3.19.2"; + sha256 = "sha256-wdmp+Tmf63PPr7G4X5F7rDas45WEETU3eKb47PFVI6o="; + postFetch = '' + sed -i 's|name = "protoc"|name = "_protoc_original"|' $out/proto/private/BUILD.release + cat <>$out/proto/private/BUILD.release + alias(name = "protoc", actual = "@com_github_protocolbuffers_protobuf//:protoc", visibility = ["//visibility:public"]) + EOF + ''; + }; + in buildBazelPackage rec { pname = "bazel-watcher"; - version = "0.14.0"; + version = "0.17.0"; src = fetchFromGitHub { owner = "bazelbuild"; repo = "bazel-watcher"; rev = "v${version}"; - sha256 = "0gigl1lg8sb4bj5crvj54329ws4yirldbncs15f96db6vhp0ig7r"; + sha256 = "sha256-aK18Q2nYxYajk9f/EEmtV7YJ8cYqbamR7vh3BTgu53Q="; }; nativeBuildInputs = [ go git python3 ]; removeRulesCC = false; + bazel = bazel_5; + bazelFlags = [ "--override_repository=rules_proto=${rulesProto}" ]; + bazelBuildFlags = lib.optionals stdenv.cc.isClang [ "--cxxopt=-x" "--cxxopt=c++" "--host_cxxopt=-x" "--host_cxxopt=c++" ]; bazelTarget = "//ibazel"; + fetchConfigured = false; # we want to fetch all dependencies, regardless of the current system fetchAttrs = { inherit patches; preBuild = '' patchShebangs . + + echo ${bazel_5.version} > .bazelversion ''; preInstall = '' @@ -54,9 +76,12 @@ buildBazelPackage rec { # should be equivalent. rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker} sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker + + # remove com_google_protobuf because it had files with different permissions on linux and darwin + rm -rf $bazelOut/external/com_google_protobuf ''; - sha256 = "1j175z3d4fbi4pl35py7yjq7ywrvwin6id131jv32hx0ck4g1m46"; + sha256 = "sha256-R+Hc9ldYcKgAXETKr2+Hk7IrjJ93WkrjyJ1SQRoM9V4="; }; buildAttrs = { @@ -66,10 +91,11 @@ buildBazelPackage rec { patchShebangs . substituteInPlace ibazel/BUILD --replace '{STABLE_GIT_VERSION}' ${version} + echo ${bazel_5.version} > .bazelversion ''; installPhase = '' - install -Dm755 bazel-bin/ibazel/*_pure_stripped/ibazel $out/bin/ibazel + install -Dm755 bazel-bin/ibazel/ibazel_/ibazel $out/bin/ibazel ''; }; @@ -78,8 +104,7 @@ buildBazelPackage rec { description = "Tools for building Bazel targets when source files change"; license = licenses.asl20; maintainers = with maintainers; [ kalbasit ]; + mainProgram = "ibazel"; platforms = platforms.all; - # broken on darwin, see https://github.com/NixOS/nixpkgs/issues/105573 - broken = stdenv.isDarwin; }; } diff --git a/pkgs/development/tools/bazel-watcher/use-go-in-path.patch b/pkgs/development/tools/bazel-watcher/use-go-in-path.patch index 010ba56165d9..d9d90c9127f0 100644 --- a/pkgs/development/tools/bazel-watcher/use-go-in-path.patch +++ b/pkgs/development/tools/bazel-watcher/use-go-in-path.patch @@ -6,7 +6,7 @@ index 51273b6..fcf9ffb 100644 go_rules_dependencies() --go_register_toolchains() +-go_register_toolchains(version = "1.17.6") +go_register_toolchains(go_version = "host") load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") diff --git a/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix index 2cb085a4c01d..6544db85a7f3 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_3/default.nix @@ -110,7 +110,9 @@ let # and libraries path. # We prefetch it, patch it, and override it in a global bazelrc. system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux"; - arch = stdenv.hostPlatform.parsed.cpu.name; + + # on aarch64 Darwin, `uname -m` returns "arm64" + arch = with stdenv.hostPlatform; if isDarwin && isAarch64 then "arm64" else parsed.cpu.name; remote_java_tools = stdenv.mkDerivation { name = "remote_java_tools_${system}"; diff --git a/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix index aa9794b5869c..511234a1e595 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_4/default.nix @@ -135,7 +135,9 @@ let # and libraries path. # We prefetch it, patch it, and override it in a global bazelrc. system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux"; - arch = stdenv.hostPlatform.parsed.cpu.name; + + # on aarch64 Darwin, `uname -m` returns "arm64" + arch = with stdenv.hostPlatform; if isDarwin && isAarch64 then "arm64" else parsed.cpu.name; remote_java_tools = stdenv.mkDerivation { name = "remote_java_tools_${system}"; diff --git a/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix b/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix index 9e2685091ddd..0c06d6128317 100644 --- a/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix +++ b/pkgs/development/tools/build-managers/bazel/bazel_5/default.nix @@ -126,7 +126,9 @@ let platforms = lib.platforms.linux ++ lib.platforms.darwin; system = if stdenv.hostPlatform.isDarwin then "darwin" else "linux"; - arch = stdenv.hostPlatform.parsed.cpu.name; + + # on aarch64 Darwin, `uname -m` returns "arm64" + arch = with stdenv.hostPlatform; if isDarwin && isAarch64 then "arm64" else parsed.cpu.name; bazelRC = writeTextFile { name = "bazel-rc"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index b9c4d651ba5f..ce94bb7392ea 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15398,7 +15398,9 @@ with pkgs; bazel-remote = callPackage ../development/tools/build-managers/bazel/bazel-remote { }; - bazel-watcher = callPackage ../development/tools/bazel-watcher { }; + bazel-watcher = callPackage ../development/tools/bazel-watcher { + go = go_1_18; + }; bazel-gazelle = callPackage ../development/tools/bazel-gazelle { };