go: use binary bootstrap for all platforms

This mirrors what Rust does and allows us to drop go1.4 from the process.
This commit is contained in:
Ivan Babrou 2021-02-15 12:52:43 -08:00 committed by zowoq
parent 0bff5a7843
commit cf69b3e801
9 changed files with 80 additions and 205 deletions

View file

@ -11,9 +11,9 @@ let
inherit (lib) optionals optionalString;
go_bootstrap = callPackage ./bootstrap.nix {
inherit Security;
};
version = "1.14.15";
go_bootstrap = callPackage ./bootstrap.nix { };
goBootstrap = runCommand "go-bootstrap" {} ''
mkdir $out
@ -41,7 +41,7 @@ in
stdenv.mkDerivation rec {
pname = "go";
version = "1.14.15";
inherit version;
src = fetchurl {
url = "https://dl.google.com/go/go${version}.src.tar.gz";

View file

@ -11,9 +11,9 @@ let
inherit (lib) optionals optionalString;
go_bootstrap = callPackage ./bootstrap.nix {
inherit Security;
};
version = "1.15.8";
go_bootstrap = callPackage ./bootstrap.nix { };
goBootstrap = runCommand "go-bootstrap" {} ''
mkdir $out
@ -41,7 +41,7 @@ in
stdenv.mkDerivation rec {
pname = "go";
version = "1.15.8";
inherit version;
src = fetchurl {
url = "https://dl.google.com/go/go${version}.src.tar.gz";

View file

@ -11,9 +11,9 @@ let
inherit (lib) optionals optionalString;
go_bootstrap = callPackage ./bootstrap.nix {
inherit Security;
};
version = "1.16";
go_bootstrap = callPackage ./bootstrap.nix { };
goBootstrap = runCommand "go-bootstrap" {} ''
mkdir $out
@ -41,7 +41,7 @@ in
stdenv.mkDerivation rec {
pname = "go";
version = "1.16";
inherit version;
src = fetchurl {
url = "https://dl.google.com/go/go${version}.src.tar.gz";

View file

@ -1,93 +0,0 @@
{ stdenv, lib, fetchurl, fetchpatch, tzdata, iana-etc, libcCross
, pkg-config
, pcre
, Security }:
let
libc = if stdenv ? cross then libcCross else stdenv.cc.libc;
in
stdenv.mkDerivation rec {
pname = "go";
version = "1.4-bootstrap-${builtins.substring 0 7 revision}";
revision = "bdd4b9503e47c2c38a9d0a9bb2f5d95ec5ff8ef6";
src = fetchurl {
url = "https://github.com/golang/go/archive/${revision}.tar.gz";
sha256 = "1zdyf883awaqdzm4r3fs76nbpiqx3iswl2p4qxclw2sl5vvynas5";
};
nativeBuildInputs = [ pkg-config ];
buildInputs = [ pcre ];
depsTargetTargetPropagated = lib.optional stdenv.isDarwin Security;
hardeningDisable = [ "all" ];
# The tests try to do stuff with 127.0.0.1 and localhost
__darwinAllowLocalNetworking = true;
# I'm not sure what go wants from its 'src', but the go installation manual
# describes an installation keeping the src.
preUnpack = ''
mkdir -p $out/share
cd $out/share
'';
prePatch = ''
# Ensure that the source directory is named go
cd ..
if [ ! -d go ]; then
mv * go
fi
cd go
patchShebangs ./ # replace /bin/bash
sed -i 's,/etc/protocols,${iana-etc}/etc/protocols,' src/net/lookup_unix.go
'' + lib.optionalString stdenv.isLinux ''
# prepend the nix path to the zoneinfo files but also leave the original value for static binaries
# that run outside a nix server
sed -i 's,\"/usr/share/zoneinfo/,"${tzdata}/share/zoneinfo/\"\,\n\t&,' src/time/zoneinfo_unix.go
# Find the loader dynamically
LOADER="$(find ${lib.getLib libc}/lib -name ld-linux\* | head -n 1)"
# Replace references to the loader
find src/cmd -name asm.c -exec sed -i "s,/lib/ld-linux.*\.so\.[0-9],$LOADER," {} \;
'';
patches = [
./remove-tools-1.4.patch
];
GOOS = if stdenv.isDarwin then "darwin" else "linux";
GOARCH = if stdenv.isDarwin then "amd64"
else if stdenv.hostPlatform.system == "i686-linux" then "386"
else if stdenv.hostPlatform.system == "x86_64-linux" then "amd64"
else if stdenv.isAarch32 then "arm"
else throw "Unsupported system";
GOARM = lib.optionalString (stdenv.hostPlatform.system == "armv5tel-linux") "5";
GO386 = 387; # from Arch: don't assume sse2 on i686
CGO_ENABLED = 0;
# The go build actually checks for CC=*/clang and does something different, so we don't
# just want the generic `cc` here.
CC = if stdenv.isDarwin then "clang" else "cc";
installPhase = ''
mkdir -p "$out/bin"
export GOROOT="$(pwd)/"
export GOBIN="$out/bin"
export PATH="$GOBIN:$PATH"
cd ./src
./all.bash
'';
meta = with lib; {
homepage = "http://golang.org/";
description = "The Go Programming language";
license = licenses.bsd3;
maintainers = with maintainers; [ cstrahan ];
platforms = platforms.linux ++ platforms.darwin;
};
}

View file

@ -11,9 +11,7 @@ let
inherit (lib) optionals optionalString;
go_bootstrap = callPackage ./bootstrap.nix {
inherit Security;
};
go_bootstrap = callPackage ./bootstrap.nix { };
goBootstrap = runCommand "go-bootstrap" {} ''
mkdir $out

View file

@ -0,0 +1,38 @@
{ lib, stdenv, fetchurl, version, hashes }:
let
toGoKernel = platform:
if platform.isDarwin then "darwin"
else platform.parsed.kernel.name;
toGoCPU = platform: {
"i686" = "386";
"x86_64" = "amd64";
"aarch64" = "arm64";
"armv6l" = "arm";
"armv7l" = "arm";
"powerpc64le" = "ppc64le";
}.${platform.parsed.cpu.name} or (throw "Unsupported CPU ${platform.parsed.cpu.name}");
toGoPlatform = platform: "${toGoKernel platform}-${toGoCPU platform}";
platform = toGoPlatform stdenv.hostPlatform;
in
stdenv.mkDerivation rec {
name = "go-${version}-${platform}-bootstrap";
src = fetchurl {
url = "https://golang.org/dl/go${version}.${platform}.tar.gz";
sha256 = hashes.${platform} or (throw "Missing Go bootstrap hash for platform ${platform}");
};
installPhase = ''
mkdir -p $out/share/go $out/bin
mv bin/* $out/bin
cp -r . $out/share/go
${lib.optionalString stdenv.isLinux (''
patchelf \
--set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \
$out/bin/go
'')}
'' ;
}

View file

@ -1,17 +1,15 @@
{ stdenv, srcOnly, fetchurl, callPackage, Security }:
let
go_bootstrap = if stdenv.isAarch64 then
srcOnly {
name = "go-1.8-linux-arm64-bootstrap";
src = fetchurl {
url = "https://cache.xor.us/go-1.8-linux-arm64-bootstrap.tar.xz";
sha256 = "0sk6g03x9gbxk2k1djnrgy8rzw1zc5f6ssw0hbxk6kjr85lpmld6";
};
}
else
callPackage ./1.4.nix {
inherit Security;
{ callPackage }:
callPackage ./binary.nix {
version = "1.16";
hashes = {
# Use `print-hashes.sh ${version}` to generate the list below
darwin-amd64 = "6000a9522975d116bf76044967d7e69e04e982e9625330d9a539a8b45395f9a8";
darwin-arm64 = "4dac57c00168d30bbd02d95131d5de9ca88e04f2c5a29a404576f30ae9b54810";
linux-386 = "ea435a1ac6d497b03e367fdfb74b33e961d813883468080f6e239b3b03bea6aa";
linux-amd64 = "013a489ebb3e24ef3d915abe5b94c3286c070dfe0818d5bca8108f1d6e8440d2";
linux-arm64 = "3770f7eb22d05e25fbee8fb53c2a4e897da043eb83c69b9a14f8d98562cd8098";
linux-armv6l = "d1d9404b1dbd77afa2bdc70934e10fbfcf7d785c372efc29462bb7d83d0a32fd";
linux-ppc64le = "27a1aaa988e930b7932ce459c8a63ad5b3333b3a06b016d87ff289f2a11aacd6";
linux-s390x = "be4c9e4e2cf058efc4e3eb013a760cb989ddc4362f111950c990d1c63b27ccbe";
};
in
go_bootstrap
}

View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
BASEURL=https://golang.org/dl/
VERSION=${1:-}
if [[ -z $VERSION ]]
then
echo "No version supplied"
exit -1
fi
curl -s "${BASEURL}?mode=json&include=all" | \
jq '.[] | select(.version == "go'${VERSION}'")' | \
jq -r '.files[] | select(.kind == "archive" and (.os == "linux" or .os == "darwin")) | (.os + "-" + .arch + " = \"" + .sha256 + "\";")'

View file

@ -1,81 +0,0 @@
diff --git a/misc/makerelease/makerelease.go b/misc/makerelease/makerelease.go
index 3b511b1..a46ebd8 100644
--- a/misc/makerelease/makerelease.go
+++ b/misc/makerelease/makerelease.go
@@ -65,9 +65,6 @@ const (
// These must be the command that cmd/go knows to install to $GOROOT/bin
// or $GOROOT/pkg/tool.
var toolPaths = []string{
- "golang.org/x/tools/cmd/cover",
- "golang.org/x/tools/cmd/godoc",
- "golang.org/x/tools/cmd/vet",
}
var preBuildCleanFiles = []string{
diff --git a/src/cmd/dist/build.c b/src/cmd/dist/build.c
index b6c61b4..2006bc2 100644
--- a/src/cmd/dist/build.c
+++ b/src/cmd/dist/build.c
@@ -210,7 +210,9 @@ init(void)
workdir = xworkdir();
xatexit(rmworkdir);
- bpathf(&b, "%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch);
+ xgetenv(&b, "GOTOOLDIR");
+ if (b.len == 0)
+ bpathf(&b, "%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch);
tooldir = btake(&b);
bfree(&b);
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index b71feb7..8468ea8 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -401,9 +401,9 @@ var goTools = map[string]targetDir{
"cmd/pack": toTool,
"cmd/pprof": toTool,
"cmd/yacc": toTool,
- "golang.org/x/tools/cmd/cover": toTool,
- "golang.org/x/tools/cmd/godoc": toBin,
- "golang.org/x/tools/cmd/vet": toTool,
+ "nixos.org/x/tools/cmd/cover": toTool,
+ "nixos.org/x/tools/cmd/godoc": toBin,
+ "nixos.org/x/tools/cmd/vet": toTool,
"code.google.com/p/go.tools/cmd/cover": stalePath,
"code.google.com/p/go.tools/cmd/godoc": stalePath,
"code.google.com/p/go.tools/cmd/vet": stalePath,
diff --git a/src/go/build/build.go b/src/go/build/build.go
index 311ecb0..f151d8f 100644
--- a/src/go/build/build.go
+++ b/src/go/build/build.go
@@ -1367,7 +1367,7 @@ func init() {
}
// ToolDir is the directory containing build tools.
-var ToolDir = filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
+var ToolDir = runtime.GOTOOLDIR()
// IsLocalImport reports whether the import path is
// a local import path, like ".", "..", "./foo", or "../foo".
diff --git a/src/runtime/extern.go b/src/runtime/extern.go
index 6cc5df8..9a9a964 100644
--- a/src/runtime/extern.go
+++ b/src/runtime/extern.go
@@ -152,6 +152,17 @@ func GOROOT() string {
return defaultGoroot
}
+// GOTOOLDIR returns the root of the Go tree.
+// It uses the GOTOOLDIR environment variable, if set,
+// or else the root used during the Go build.
+func GOTOOLDIR() string {
+ s := gogetenv("GOTOOLDIR")
+ if s != "" {
+ return s
+ }
+ return GOROOT() + "/pkg/tool/" + GOOS + "_" + GOARCH
+}
+
// Version returns the Go tree's version string.
// It is either the commit hash and date at the time of the build or,
// when possible, a release tag like "go1.3".