aboutsummaryrefslogtreecommitdiff
path: root/pkgs/development/go-modules/generic
diff options
context:
space:
mode:
authorAndrew Dunham <andrew@du.nham.ca>2019-02-07 09:39:53 -0500
committerJรถrg Thalheim <Mic92@users.noreply.github.com>2019-02-07 14:39:53 +0000
commit274afc49325403e8fd3bf2914950f856a9c63fd6 (patch)
treeb6de2bdc11a7eb17c47e88474fe99accea9acde0 /pkgs/development/go-modules/generic
parent3e3e7379cdc20a115557e4bd4e2ca2e815492cdb (diff)
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!
Diffstat (limited to 'pkgs/development/go-modules/generic')
-rw-r--r--pkgs/development/go-modules/generic/default.nix11
1 files changed, 7 insertions, 4 deletions
diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix
index b282a49e8af..eb45f446dc9 100644
--- a/pkgs/development/go-modules/generic/default.nix
+++ b/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
'';