Commit 4955487f authored by Malte Poll's avatar Malte Poll Committed by Paul Meyer
Browse files

bazel-watcher: 0.25.2 -> 0.25.3

parent 2c7cfbb8
Loading
Loading
Loading
Loading
+18 −86
Original line number Diff line number Diff line
{ buildBazelPackage
, bazel_5
, fetchFromGitHub
, git
, go_1_21
, python3
, lib, stdenv
{
  lib,
  fetchFromGitHub,
  buildGoModule,
  testers,
  bazel-watcher,
}:

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";
    hash = "sha256-WVPZx14thneAC4PdiDhBibnPwlCKEF9c93CHR0t1Efo=";
    postFetch = ''
      sed -i 's|name = "protoc"|name = "_protoc_original"|' $out/proto/private/BUILD.release
      cat <<EOF >>$out/proto/private/BUILD.release
      alias(name = "protoc", actual = "@com_github_protocolbuffers_protobuf//:protoc", visibility = ["//visibility:public"])
      EOF
    '';
  };

in
buildBazelPackage rec {
buildGoModule rec {
  pname = "bazel-watcher";
  version = "0.25.2";
  version = "0.25.3";

  src = fetchFromGitHub {
    owner = "bazelbuild";
    repo = "bazel-watcher";
    rev = "v${version}";
    hash = "sha256-lreGKA0DZiOd1bJq8NNQ+80cyDwiughoXCkKu1RaZmc=";
    hash = "sha256-5cRj04e5VVG4NSe4LOLkZIrerT4laLEDeXCqTiJj6MM=";
  };

  nativeBuildInputs = [ go_1_21 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++" ];
  bazelTargets = [ "//cmd/ibazel" ];

  fetchConfigured = false; # we want to fetch all dependencies, regardless of the current system
  fetchAttrs = {
    inherit patches;

    preBuild = ''
      patchShebangs .

      echo ${bazel_5.version} > .bazelversion
    '';
  vendorHash = "sha256-0I/bvuyosN55oNSMuom4C8rVjxneUaqV19l9OMiwWhU=";

    preInstall = ''
      # Remove the go_sdk (it's just a copy of the go derivation) and all
      # references to it from the marker files. Bazel does not need to download
      # this sdk because we have patched the WORKSPACE file to point to the one
      # currently present in PATH. Without removing the go_sdk from the marker
      # file, the hash of it will change anytime the Go derivation changes and
      # that would lead to impurities in the marker files which would result in
      # a different hash for the fetch phase.
      rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker}
      sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker

      # Retains go build input markers
      chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}
      rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker}

      # Remove the gazelle tools, they contain go binaries that are built
      # non-deterministically. As long as the gazelle version matches the tools
      # 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 = "sha256-B2KVD/FmkAa7MNhLaH286gF3uA20qjN3CoA83KRB9E8=";
  };

  buildAttrs = {
    inherit patches;

    preBuild = ''
      patchShebangs .
  CGO_ENABLED = "0";
  ldflags = [
    "-s"
    "-X main.Version=${version}"
  ];

      substituteInPlace cmd/ibazel/BUILD.bazel --replace '{STABLE_GIT_VERSION}' ${version}
      echo ${bazel_5.version} > .bazelversion
    '';
  subPackages = [ "cmd/ibazel" ];

    installPhase = ''
      install -Dm755 bazel-bin/cmd/ibazel/ibazel_/ibazel $out/bin/ibazel
    '';
  passthru = {
    tests.version = testers.testVersion { package = bazel-watcher; };
  };

  meta = with lib; {
+0 −13
Original line number Diff line number Diff line
diff --git a/WORKSPACE b/WORKSPACE
index 51273b6..fcf9ffb 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -61,7 +61,7 @@ load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_depe
 
 go_rules_dependencies()
 
-go_register_toolchains(version = "1.19.4")
+go_register_toolchains(go_version = "host")
 
 load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")