Skip to content

Commit

Permalink
Enable parallel build in build.sh (nim-lang#18195)
Browse files Browse the repository at this point in the history
Add help
  • Loading branch information
Federico Ceratto authored and PMunch committed Mar 28, 2022
1 parent cbf7b7d commit 1548ea3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tools/niminst/buildsh.nimf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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=""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1548ea3

Please sign in to comment.