build_all.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /bin/sh
  2. # build development version of the compiler; can be rerun safely.
  3. # arguments can be passed, e.g. `--os freebsd`
  4. set -u # error on undefined variables
  5. set -e # exit on first error
  6. echo_run(){
  7. echo "$*"
  8. "$@"
  9. }
  10. [ -d csources ] || echo_run git clone -q --depth 1 https://github.com/nim-lang/csources.git
  11. nim_csources=bin/nim_csources
  12. build_nim_csources_via_script(){
  13. echo_run cd csources
  14. echo_run sh build.sh "$@"
  15. }
  16. build_nim_csources(){
  17. # avoid changing dir in case of failure
  18. (
  19. if [ $# -ne 0 ]; then
  20. # some args were passed (e.g.: `--cpu i386`), need to call build.sh
  21. build_nim_csources_via_script "$@"
  22. else
  23. # no args, use multiple Make jobs (5X faster on 16 cores: 10s instead of 50s)
  24. makeX=make
  25. unamestr=$(uname)
  26. if [ "$unamestr" = 'FreeBSD' ]; then
  27. makeX=gmake
  28. fi
  29. nCPU=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || 1)
  30. which $makeX && echo_run $makeX -C csources -j $((nCPU + 2)) -l $nCPU || build_nim_csources_via_script
  31. fi
  32. )
  33. # keep $nim_csources in case needed to investigate bootstrap issues
  34. # without having to rebuild from csources
  35. echo_run cp bin/nim $nim_csources
  36. }
  37. [ -f $nim_csources ] || echo_run build_nim_csources $@
  38. # Note: if fails, may need to `cd csources && git pull`
  39. echo_run bin/nim c --skipUserCfg --skipParentCfg koch
  40. echo_run ./koch boot -d:release --skipUserCfg --skipParentCfg
  41. echo_run ./koch tools --skipUserCfg --skipParentCfg # Compile Nimble and other tools.