at 23.11-beta 111 lines 3.7 kB view raw
1{ buildBazelPackage 2, bazel_5 3, fetchFromGitHub 4, git 5, go 6, python3 7, lib, stdenv 8}: 9 10let 11 patches = [ 12 ./use-go-in-path.patch 13 ./fix-rules-go-3408.patch 14 ]; 15 16 # Patch the protoc alias so that it always builds from source. 17 rulesProto = fetchFromGitHub { 18 owner = "bazelbuild"; 19 repo = "rules_proto"; 20 rev = "4.0.0-3.19.2"; 21 sha256 = "sha256-wdmp+Tmf63PPr7G4X5F7rDas45WEETU3eKb47PFVI6o="; 22 postFetch = '' 23 sed -i 's|name = "protoc"|name = "_protoc_original"|' $out/proto/private/BUILD.release 24 cat <<EOF >>$out/proto/private/BUILD.release 25 alias(name = "protoc", actual = "@com_github_protocolbuffers_protobuf//:protoc", visibility = ["//visibility:public"]) 26 EOF 27 ''; 28 }; 29 30in 31buildBazelPackage rec { 32 pname = "bazel-watcher"; 33 version = "0.21.2"; 34 35 src = fetchFromGitHub { 36 owner = "bazelbuild"; 37 repo = "bazel-watcher"; 38 rev = "v${version}"; 39 sha256 = "sha256-wigrE9u1VuFnqLWyVJK3M7xsjyme2dDG6YTcD9whKnw="; 40 }; 41 42 nativeBuildInputs = [ go git python3 ]; 43 removeRulesCC = false; 44 45 bazel = bazel_5; 46 bazelFlags = [ "--override_repository=rules_proto=${rulesProto}" ]; 47 bazelBuildFlags = lib.optionals stdenv.cc.isClang [ "--cxxopt=-x" "--cxxopt=c++" "--host_cxxopt=-x" "--host_cxxopt=c++" ]; 48 bazelTargets = [ "//cmd/ibazel" ]; 49 50 fetchConfigured = false; # we want to fetch all dependencies, regardless of the current system 51 fetchAttrs = { 52 inherit patches; 53 54 preBuild = '' 55 patchShebangs . 56 57 echo ${bazel_5.version} > .bazelversion 58 ''; 59 60 preInstall = '' 61 # Remove the go_sdk (it's just a copy of the go derivation) and all 62 # references to it from the marker files. Bazel does not need to download 63 # this sdk because we have patched the WORKSPACE file to point to the one 64 # currently present in PATH. Without removing the go_sdk from the marker 65 # file, the hash of it will change anytime the Go derivation changes and 66 # that would lead to impurities in the marker files which would result in 67 # a different sha256 for the fetch phase. 68 rm -rf $bazelOut/external/{go_sdk,\@go_sdk.marker} 69 sed -e '/^FILE:@go_sdk.*/d' -i $bazelOut/external/\@*.marker 70 71 # Retains go build input markers 72 chmod -R 755 $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker} 73 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_cache,@\bazel_gazelle_go_repository_cache.marker} 74 75 # Remove the gazelle tools, they contain go binaries that are built 76 # non-deterministically. As long as the gazelle version matches the tools 77 # should be equivalent. 78 rm -rf $bazelOut/external/{bazel_gazelle_go_repository_tools,\@bazel_gazelle_go_repository_tools.marker} 79 sed -e '/^FILE:@bazel_gazelle_go_repository_tools.*/d' -i $bazelOut/external/\@*.marker 80 81 # remove com_google_protobuf because it had files with different permissions on linux and darwin 82 rm -rf $bazelOut/external/com_google_protobuf 83 ''; 84 85 sha256 = "sha256-lC9e5Z2cxLAeWXkiFGmcB6aOaurMvwrP/k5jl3gCfAc="; 86 }; 87 88 buildAttrs = { 89 inherit patches; 90 91 preBuild = '' 92 patchShebangs . 93 94 substituteInPlace cmd/ibazel/BUILD.bazel --replace '{STABLE_GIT_VERSION}' ${version} 95 echo ${bazel_5.version} > .bazelversion 96 ''; 97 98 installPhase = '' 99 install -Dm755 bazel-bin/cmd/ibazel/ibazel_/ibazel $out/bin/ibazel 100 ''; 101 }; 102 103 meta = with lib; { 104 homepage = "https://github.com/bazelbuild/bazel-watcher"; 105 description = "Tools for building Bazel targets when source files change"; 106 license = licenses.asl20; 107 maintainers = with maintainers; [ kalbasit ]; 108 mainProgram = "ibazel"; 109 platforms = platforms.all; 110 }; 111}