Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-24.05] go: Backport go 1.23 to nixos-24.05 #339654

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pkgs/development/compilers/go/1.21.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
}:

let
useGccGoBootstrap = stdenv.buildPlatform.isMusl;
goBootstrap = if useGccGoBootstrap then buildPackages.gccgo12 else buildPackages.callPackage ./bootstrap121.nix { };
goBootstrap = buildPackages.callPackage ./bootstrap121.nix { };

skopeoTest = skopeo.override { buildGoModule = buildGo121Module; };

Expand Down Expand Up @@ -115,7 +114,7 @@ stdenv.mkDerivation (finalAttrs: {
GO386 = "softfloat"; # from Arch: don't assume sse2 on i686
CGO_ENABLED = 1;

GOROOT_BOOTSTRAP = if useGccGoBootstrap then goBootstrap else "${goBootstrap}/share/go";
GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";

buildPhase = ''
runHook preBuild
Expand Down Expand Up @@ -184,7 +183,7 @@ stdenv.mkDerivation (finalAttrs: {
homepage = "https://go.dev/";
license = licenses.bsd3;
maintainers = teams.golang.members;
platforms = platforms.darwin ++ platforms.linux;
platforms = platforms.darwin ++ platforms.linux ++ platforms.freebsd;
mainProgram = "go";
};
})
7 changes: 3 additions & 4 deletions pkgs/development/compilers/go/1.22.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
}:

let
useGccGoBootstrap = stdenv.buildPlatform.isMusl;
goBootstrap = if useGccGoBootstrap then buildPackages.gccgo12 else buildPackages.callPackage ./bootstrap121.nix { };
goBootstrap = buildPackages.callPackage ./bootstrap121.nix { };

skopeoTest = skopeo.override { buildGoModule = buildGo122Module; };

Expand Down Expand Up @@ -115,7 +114,7 @@ stdenv.mkDerivation (finalAttrs: {
GO386 = "softfloat"; # from Arch: don't assume sse2 on i686
CGO_ENABLED = 1;

GOROOT_BOOTSTRAP = if useGccGoBootstrap then goBootstrap else "${goBootstrap}/share/go";
GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";

buildPhase = ''
runHook preBuild
Expand Down Expand Up @@ -184,7 +183,7 @@ stdenv.mkDerivation (finalAttrs: {
homepage = "https://go.dev/";
license = licenses.bsd3;
maintainers = teams.golang.members;
platforms = platforms.darwin ++ platforms.linux;
platforms = platforms.darwin ++ platforms.linux ++ platforms.freebsd;
mainProgram = "go";
};
})
189 changes: 189 additions & 0 deletions pkgs/development/compilers/go/1.23.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{ lib
, stdenv
, fetchurl
, tzdata
, substituteAll
, iana-etc
, Security
, Foundation
, xcbuild
, mailcap
, buildPackages
, pkgsBuildTarget
, threadsCross
, testers
, skopeo
, buildGo123Module
}:

let
goBootstrap = buildPackages.callPackage ./bootstrap121.nix { };

skopeoTest = skopeo.override { buildGoModule = buildGo123Module; };

goarch = platform: {
"aarch64" = "arm64";
"arm" = "arm";
"armv5tel" = "arm";
"armv6l" = "arm";
"armv7l" = "arm";
"i686" = "386";
"mips" = "mips";
"mips64el" = "mips64le";
"mipsel" = "mipsle";
"powerpc64" = "ppc64";
"powerpc64le" = "ppc64le";
"riscv64" = "riscv64";
"s390x" = "s390x";
"x86_64" = "amd64";
"wasm32" = "wasm";
}.${platform.parsed.cpu.name} or (throw "Unsupported system: ${platform.parsed.cpu.name}");

# We need a target compiler which is still runnable at build time,
# to handle the cross-building case where build != host == target
targetCC = pkgsBuildTarget.targetPackages.stdenv.cc;

isCross = stdenv.buildPlatform != stdenv.targetPlatform;
in
stdenv.mkDerivation (finalAttrs: {
pname = "go";
version = "1.23.0";

src = fetchurl {
url = "https://go.dev/dl/go${finalAttrs.version}.src.tar.gz";
hash = "sha256-Qreo6A2AXaoDAi7T/eQyHUw78smQoUQWXQHu7Nb2mcY=";
};

strictDeps = true;
buildInputs = [ ]
++ lib.optionals stdenv.isLinux [ stdenv.cc.libc.out ]
++ lib.optionals (stdenv.hostPlatform.libc == "glibc") [ stdenv.cc.libc.static ];

depsTargetTargetPropagated = lib.optionals stdenv.targetPlatform.isDarwin [ Foundation Security xcbuild ];

depsBuildTarget = lib.optional isCross targetCC;

depsTargetTarget = lib.optional stdenv.targetPlatform.isWindows threadsCross.package;

postPatch = ''
patchShebangs .
'';

patches = [
(substituteAll {
src = ./iana-etc-1.17.patch;
iana = iana-etc;
})
# Patch the mimetype database location which is missing on NixOS.
# but also allow static binaries built with NixOS to run outside nix
(substituteAll {
src = ./mailcap-1.17.patch;
inherit mailcap;
})
# prepend the nix path to the zoneinfo files but also leave the original value for static binaries
# that run outside a nix server
(substituteAll {
src = ./tzdata-1.19.patch;
inherit tzdata;
})
./remove-tools-1.11.patch
./go_no_vendor_checks-1.22.patch
];

GOOS = if stdenv.targetPlatform.isWasi then "wasip1" else stdenv.targetPlatform.parsed.kernel.name;
GOARCH = goarch stdenv.targetPlatform;
# GOHOSTOS/GOHOSTARCH must match the building system, not the host system.
# Go will nevertheless build a for host system that we will copy over in
# the install phase.
GOHOSTOS = stdenv.buildPlatform.parsed.kernel.name;
GOHOSTARCH = goarch stdenv.buildPlatform;

# {CC,CXX}_FOR_TARGET must be only set for cross compilation case as go expect those
# to be different from CC/CXX
CC_FOR_TARGET =
if isCross then
"${targetCC}/bin/${targetCC.targetPrefix}cc"
else
null;
CXX_FOR_TARGET =
if isCross then
"${targetCC}/bin/${targetCC.targetPrefix}c++"
else
null;

GOARM = toString (lib.intersectLists [ (stdenv.hostPlatform.parsed.cpu.version or "") ] [ "5" "6" "7" ]);
GO386 = "softfloat"; # from Arch: don't assume sse2 on i686
# Wasi does not support CGO
CGO_ENABLED = if stdenv.targetPlatform.isWasi then 0 else 1;

GOROOT_BOOTSTRAP = "${goBootstrap}/share/go";

buildPhase = ''
runHook preBuild
export GOCACHE=$TMPDIR/go-cache

export PATH=$(pwd)/bin:$PATH

${lib.optionalString isCross ''
# Independent from host/target, CC should produce code for the building system.
# We only set it when cross-compiling.
export CC=${buildPackages.stdenv.cc}/bin/cc
''}
ulimit -a

pushd src
./make.bash
popd
runHook postBuild
'';

preInstall = ''
# Contains the wrong perl shebang when cross compiling,
# since it is not used for anything we can deleted as well.
rm src/regexp/syntax/make_perl_groups.pl
'' + (if (stdenv.buildPlatform.system != stdenv.hostPlatform.system) then ''
mv bin/*_*/* bin
rmdir bin/*_*
${lib.optionalString (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) ''
rm -rf pkg/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH} pkg/tool/${finalAttrs.GOHOSTOS}_${finalAttrs.GOHOSTARCH}
''}
'' else lib.optionalString (stdenv.hostPlatform.system != stdenv.targetPlatform.system) ''
rm -rf bin/*_*
${lib.optionalString (!(finalAttrs.GOHOSTARCH == finalAttrs.GOARCH && finalAttrs.GOOS == finalAttrs.GOHOSTOS)) ''
rm -rf pkg/${finalAttrs.GOOS}_${finalAttrs.GOARCH} pkg/tool/${finalAttrs.GOOS}_${finalAttrs.GOARCH}
''}
'');

installPhase = ''
runHook preInstall
mkdir -p $out/share/go
cp -a bin pkg src lib misc api doc go.env $out/share/go
mkdir -p $out/bin
ln -s $out/share/go/bin/* $out/bin
runHook postInstall
'';

disallowedReferences = [ goBootstrap ];

passthru = {
inherit goBootstrap skopeoTest;
tests = {
skopeo = testers.testVersion { package = skopeoTest; };
version = testers.testVersion {
package = finalAttrs.finalPackage;
command = "go version";
version = "go${finalAttrs.version}";
};
};
};

meta = with lib; {
changelog = "https://go.dev/doc/devel/release#go${lib.versions.majorMinor finalAttrs.version}";
description = "Go Programming language";
homepage = "https://go.dev/";
license = licenses.bsd3;
maintainers = teams.golang.members;
platforms = platforms.darwin ++ platforms.linux ++ platforms.wasi ++ platforms.freebsd;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this is failing the cherrypick, is platforms.wasi was added here:

050df1a

which is before go1.23 existed. I opted to not add additional functionality that wasn't part of the strict set of cherrypicks when resolving the merge conflict. Happy to add platforms.wasi to go1.22 if that's desired.

mainProgram = "go";
};
})
4 changes: 1 addition & 3 deletions pkgs/development/compilers/go/binary.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, stdenv, fetchurl, version, hashes, autoPatchelfHook }:
{ lib, stdenv, fetchurl, version, hashes }:
let
toGoKernel = platform:
if platform.isDarwin then "darwin"
Expand Down Expand Up @@ -26,8 +26,6 @@ stdenv.mkDerivation rec {
sha256 = hashes.${platform} or (throw "Missing Go bootstrap hash for platform ${platform}");
};

nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];

# We must preserve the signature on Darwin
dontStrip = stdenv.hostPlatform.isDarwin;

Expand Down
5 changes: 5 additions & 0 deletions pkgs/development/compilers/go/bootstrap121.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ callPackage ./binary.nix {
# Use `print-hashes.sh ${version}` to generate the list below
darwin-amd64 = "b314de9f704ab122c077d2ec8e67e3670affe8865479d1f01991e7ac55d65e70";
darwin-arm64 = "3aca44de55c5e098de2f406e98aba328898b05d509a2e2a356416faacf2c4566";
freebsd-386 = "312a0065714a50862af714e7a5b3fbbd70fe68f905ffb9bcc56d42eadf6bffab";
freebsd-amd64 = "b8eaa36654625df799654f77f4af0ea7bd9e5e760ebe86e68fe7c484748ae995";
freebsd-arm64 = "bca5be1a9934fc522cb1a2e4849bb9f12ee6b480b48949e36a4dfb8e755a4b25";
freebsd-armv6l = "f4c9c91fa9c37d6d6b7644f3f6b67167b2a44bd48c0cba1d2a5ff5fd50ceb364";
freebsd-riscv64 = "45b99a9884dcd0dd4c8e4c0f99a4dc2901b8e9628dd8091ae5c0620afd536f0a";
linux-386 = "0e6f378d9b072fab0a3d9ff4d5e990d98487d47252dba8160015a61e6bd0bcba";
linux-amd64 = "d0398903a16ba2232b389fb31032ddf57cac34efda306a0eebac34f0965a0742";
linux-arm64 = "f3d4548edf9b22f26bbd49720350bbfe59d75b7090a1a2bff1afad8214febaf3";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/go/print-hashes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ 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 + "\";")'
jq -r '.files[] | select(.kind == "archive" and (.os == "linux" or .os == "darwin" or .os == "freebsd")) | (.os + "-" + .arch + " = \"" + .sha256 + "\";")'
11 changes: 11 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25170,6 +25170,17 @@ with pkgs;
go = buildPackages.go_1_22;
};

# requires a newer Apple SDK
go_1_23 = darwin.apple_sdk_11_0.callPackage ../development/compilers/go/1.23.nix {
inherit (darwin.apple_sdk_11_0.frameworks) Foundation Security;
};
buildGo123Module = darwin.apple_sdk_11_0.callPackage ../build-support/go/module.nix {
go = buildPackages.go_1_23;
};
buildGo123Package = darwin.apple_sdk_11_0.callPackage ../build-support/go/package.nix {
go = buildPackages.go_1_23;
};

leaps = callPackage ../development/tools/leaps { };

### DEVELOPMENT / JAVA MODULES
Expand Down
Loading