summary refs log tree commit diff stats
path: root/build_all.sh
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-01-31 11:00:05 -0800
committerGitHub <noreply@github.com>2020-01-31 20:00:05 +0100
commit45a5c64c9a01cb198450fa1a7b108710241c8768 (patch)
tree71d2c3cf19c9d8432999e9d7fa8661d4bbf0b338 /build_all.sh
parentadc52b003960817553aa3481e21a9b335a504e7f (diff)
downloadNim-45a5c64c9a01cb198450fa1a7b108710241c8768.tar.gz
build_all.sh: building csources 5X faster thanks to make -j (#13300)
* build_all.sh: building csources 5X faster thanks to make -j
* fix for freebsd
* use OS-dependent formula to get number of logical cores
* make is an optional dependency
Diffstat (limited to 'build_all.sh')
-rw-r--r--build_all.sh28
1 files changed, 24 insertions, 4 deletions
diff --git a/build_all.sh b/build_all.sh
index e22facc1b..2af7f14ee 100644
--- a/build_all.sh
+++ b/build_all.sh
@@ -1,6 +1,7 @@
 #! /bin/sh
 
-# build development version of the compiler; can be rerun safely
+# build development version of the compiler; can be rerun safely.
+# arguments can be passed, eg `--os freebsd`
 
 set -u # error on undefined variables
 set -e # exit on first error
@@ -10,14 +11,33 @@ echo_run(){
   "$@"
 }
 
-[ -d csources ] || echo_run git clone --depth 1 https://github.com/nim-lang/csources.git
+[ -d csources ] || echo_run git clone -q --depth 1 https://github.com/nim-lang/csources.git
 
 nim_csources=bin/nim_csources
+
+build_nim_csources_via_script(){
+  echo_run cd csources
+  echo_run sh build.sh "$@"
+}
+
 build_nim_csources(){
   ## avoid changing dir in case of failure
   (
-    echo_run cd csources
-    echo_run sh build.sh $@
+    if [[ $# -ne 0 ]]; then
+      # some args were passed (eg: `--cpu i386`), need to call build.sh
+      build_nim_csources_via_script "$@"
+    else
+      # no args, use multhreaded (5X faster on 16 cores: 10s instead of 50s)
+      makeX=make
+      unamestr=$(uname)
+      if [ "$unamestr" = 'FreeBSD' ]; then
+        makeX=gmake
+      fi
+      # see https://stackoverflow.com/a/53427092/1426932
+      logicalCpus=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null)
+      # +1: see https://unix.stackexchange.com/questions/519092/what-is-the-logic-of-using-nproc-1-in-make-command
+      which $makeX && echo_run $makeX -C csources -j $(($logicalCpus + 1)) || build_nim_csources_via_script
+    fi
   )
   # keep $nim_csources in case needed to investigate bootstrap issues
   # without having to rebuild from csources