From 274afc49325403e8fd3bf2914950f856a9c63fd6 Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Thu, 7 Feb 2019 09:39:53 -0500 Subject: 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! --- pkgs/development/go-modules/generic/default.nix | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pkgs/development/go-modules') diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix index b282a49e8afd..eb45f446dc9d 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 ''; -- cgit v1.2.3