summary refs log tree commit diff stats
path: root/tools/niminst
diff options
context:
space:
mode:
authorFederico Ceratto <federico.ceratto@gmail.com>2021-06-14 08:30:04 +0100
committerGitHub <noreply@github.com>2021-06-14 09:30:04 +0200
commit2d34b1f5bc45a180d1b53d6c24857133859a4f46 (patch)
tree8adf7ca0dc927d00b738afdaa392dc65f2d064e2 /tools/niminst
parent488acd9d077e8179d35d665ac0591c456bfa93aa (diff)
downloadNim-2d34b1f5bc45a180d1b53d6c24857133859a4f46.tar.gz
Enable parallel build in build.sh (#18195)
Add help
Diffstat (limited to 'tools/niminst')
-rw-r--r--tools/niminst/buildsh.nimf24
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/niminst/buildsh.nimf b/tools/niminst/buildsh.nimf
index e13221781..e7afd402e 100644
--- a/tools/niminst/buildsh.nimf
+++ b/tools/niminst/buildsh.nimf
@@ -21,10 +21,23 @@ do
       optosname=$2
       shift 2
       ;;
+    --parallel)
+      parallel=$2
+      shift 2
+      ;;
     --extraBuildArgs)
       extraBuildArgs=" $2"
       shift 2
       ;;
+    -h | --help)
+      echo "Options:"
+      echo "  --os <OS>"
+      echo "  --cpu <CPU architecture>"
+      echo "  --osname <name>           Additional OS specification (used for Android)"
+      echo "  --extraBuildArgs <args>   Additional arguments passed to the compiler"
+      echo "  --parallel <number>       Multiprocess build. Requires GNU parallel"
+      exit 0
+      ;;
     --) # End of all options
       shift
       break;
@@ -39,7 +52,15 @@ do
   esac
 done
 
+parallel="${parallel:-0}"
 CC="${CC:-gcc}"
+if [ "$parallel" -gt 1 ]; then
+  if ! command -v sem > /dev/null; then
+    echo "Error: GNU parallel is required to use --parallel"
+    exit 1
+  fi
+  CC="sem -j $parallel --id $$ ${CC}"
+fi
 COMP_FLAGS="${CPPFLAGS:-} ${CFLAGS:-} ?{c.ccompiler.flags}$extraBuildArgs"
 LINK_FLAGS="${LDFLAGS:-} ?{c.linker.flags}"
 PS4=""
@@ -222,6 +243,9 @@ case $myos in
     $CC $COMP_FLAGS -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")}
 #        add(linkCmd, " \\\n" & changeFileExt(f, "o"))
 #      end for
+    if [ "$parallel" -gt 0 ]; then
+      sem --wait --id $$
+    fi
     $CC -o ?{"$binDir/" & toLowerAscii(c.name)} ?linkCmd $LINK_FLAGS
     ;;
 #    end for