go: build each package single-threaded (#53390)

I noticed that I was seeing the Go compiler build things in parallel even when I'd set `-j1 --cores 1`. It appears that the compiler, by default, uses the number of CPUs that are available to perform a build, while nixpkgs parallelizes at the directory level.

In order to change the fewest assumptions, this explicitly tells the Go compiler to run single-threaded. The flag's documentation is:

```
-p n
	the number of programs, such as build commands or
	test binaries, that can be run in parallel.
	The default is the number of CPUs available.
```

So this should function as expected. Feedback appreciated!
wip/yesman
Andrew Dunham 5 years ago committed by Jörg Thalheim
parent 3e3e7379cd
commit 274afc4932
  1. 11
      pkgs/development/go-modules/generic/default.nix

@ -130,7 +130,7 @@ let
echo "$d" | grep -q "\(/_\|examples\|Godeps\)" && return 0
[ -n "$excludedPackages" ] && echo "$d" | grep -q "$excludedPackages" && return 0
local OUT
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" -v $d 2>&1)"; then
if ! OUT="$(go $cmd $buildFlags "''${buildFlagsArray[@]}" -v -p $NIX_BUILD_CORES $d 2>&1)"; then
if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then
echo "$OUT" >&2
return 1
@ -163,11 +163,12 @@ let
else
touch $TMPDIR/buildFlagsArray
fi
export -f buildGoDir # xargs needs to see the function
if [ -z "$enableParallelBuilding" ]; then
export NIX_BUILD_CORES=1
fi
getGoDirs "" | xargs -n1 -P $NIX_BUILD_CORES bash -c 'buildGoDir install "$@"' --
for pkg in $(getGoDirs ""); do
buildGoDir install "$pkg"
done
'' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
# normalize cross-compiled builds w.r.t. native builds
(
@ -187,7 +188,9 @@ let
checkPhase = args.checkPhase or ''
runHook preCheck
getGoDirs test | xargs -n1 -P $NIX_BUILD_CORES bash -c 'buildGoDir test "$@"' --
for pkg in $(getGoDirs test); do
buildGoDir test "$pkg"
done
runHook postCheck
'';

Loading…
Cancel
Save