bazel: use prebuilt Go toolchain (go.dev/dl) (#2796)

We had to switch to a Go toolchain from nixpkgs,
since prebuilt Go toolchain versions were not usable on NixOS.
Since Go 1.21, the prebuilt Go toolchain is statically linked
and works out of the box.

Reference: https://github.com/golang/go/issues/57007
This commit is contained in:
Malte Poll 2024-01-05 11:52:22 +01:00 committed by GitHub
parent c23aef344d
commit 3a4f6ef9d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 39 deletions

View File

@ -131,16 +131,11 @@ load("//bazel/toolchains:go_module_deps.bzl", "go_dependencies")
# gazelle:repository_macro bazel/toolchains/go_module_deps.bzl%go_dependencies
go_dependencies()
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
load("@io_tweag_rules_nixpkgs//nixpkgs:toolchains/go.bzl", "nixpkgs_go_configure")
nixpkgs_go_configure(
nix_file = "//bazel/go:go.nix",
repository = "@nixpkgs",
)
go_register_toolchains(version = "1.21.5")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

View File

@ -1,21 +0,0 @@
let
pkgs = import <nixpkgs> { };
goAttr = pkgs.go_1_21.overrideAttrs (_: rec {
version = "1.21.5";
src = pkgs.fetchurl {
url = "https://go.dev/dl/go${version}.src.tar.gz";
hash = "sha256-KFy730tubmLtWPNw8/bYwwgl1uVsWFPGbTwjvNsJ2xk=";
};
});
in
pkgs.buildEnv
{
name = "bazel-go-toolchain";
paths = [ goAttr ];
postBuild = ''
touch $out/ROOT
ln -s $out/share/go/{api,doc,lib,misc,pkg,src,go.env} $out/
'';
} // {
version = goAttr.version;
}

View File

@ -3,15 +3,8 @@
## Steps
1. Replace "1.xx.x" with the new version (see [example](https://github.com/edgelesssys/constellation/commit/9e1a0c06bfda0171958f0776633a9a53f521144d))
2. Update the nix hash
Replace "1.xx.x" with the new version in [WORKSPACE.bazel](/WORKSPACE.bazel):
Once updated run `bazel run //:tidy` and you will see a failure such as:
```
> error: hash mismatch in fixed-output derivation '/nix/store/r85bdj6vrim7m5vlybdmzgca7d0kcb4n-go1.21.4.src.tar.gz.drv':
> specified: sha256-GG8rb4yLcE5paCGwmrIEGlwe4T3LwxVqE63PdZMe5Ig=
> got: sha256-R7Jqg9K2WjwcG8rOJztpvuSaentRaKdgTe09JqN714c=
```
Simple replace the hash with the got value.
3. Ask @katexochen to build the thing and push it into his cache.
```starlark
go_register_toolchains(version = "1.xx.x")
```