summary refs log tree commit diff stats
path: root/ci
diff options
context:
space:
mode:
Diffstat (limited to 'ci')
-rw-r--r--ci/build.bat14
-rw-r--r--ci/build.sh15
-rw-r--r--ci/deps.bat4
-rw-r--r--ci/deps.sh16
-rw-r--r--ci/funs.sh73
-rw-r--r--ci/nsis_build.bat59
6 files changed, 72 insertions, 109 deletions
diff --git a/ci/build.bat b/ci/build.bat
deleted file mode 100644
index 2227168e5..000000000
--- a/ci/build.bat
+++ /dev/null
@@ -1,14 +0,0 @@
-REM Some debug info
-echo "Running on %CI_RUNNER_ID% (%CI_RUNNER_DESCRIPTION%) with tags %CI_RUNNER_TAGS%."
-gcc -v
-
-git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources
-cd csources
-call build64.bat
-cd ..
-set PATH=%CD%\bin;%PATH%
-nim -v
-nim c koch
-koch.exe boot
-copy bin/nim bin/nimd
-koch.exe boot -d:release
diff --git a/ci/build.sh b/ci/build.sh
deleted file mode 100644
index a89d011ed..000000000
--- a/ci/build.sh
+++ /dev/null
@@ -1,15 +0,0 @@
-sh ci/deps.sh
-
-# Build from C sources.
-git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources
-cd csources
-sh build.sh
-cd ..
-# Add Nim to the PATH
-export PATH=$(pwd)/bin${PATH:+:$PATH}
-# Bootstrap.
-nim -v
-nim c koch
-./koch boot
-cp bin/nim bin/nimd
-./koch boot -d:release
diff --git a/ci/deps.bat b/ci/deps.bat
deleted file mode 100644
index bda1fe14f..000000000
--- a/ci/deps.bat
+++ /dev/null
@@ -1,4 +0,0 @@
-nim e install_nimble.nims
-nim e tests/test_nimscript.nims
-nimble update
-nimble install -y zip opengl sdl1 jester@#head niminst
diff --git a/ci/deps.sh b/ci/deps.sh
deleted file mode 100644
index f0f831a2a..000000000
--- a/ci/deps.sh
+++ /dev/null
@@ -1,16 +0,0 @@
-# Some debug info
-echo "Running on $CI_RUNNER_ID ($CI_RUNNER_DESCRIPTION) with tags $CI_RUNNER_TAGS."
-
-# Packages
-apt-get update -qq
-apt-get install -y -qq build-essential git libcurl4-openssl-dev libsdl1.2-dev libgc-dev nodejs
-
-gcc -v
-
-export PATH=$(pwd)/bin${PATH:+:$PATH}
-
-# Nimble deps
-nim e install_nimble.nims
-nim e tests/test_nimscript.nims
-nimble update
-nimble install zip opengl sdl1 jester@#head niminst
diff --git a/ci/funs.sh b/ci/funs.sh
index 7f82e1ca3..7a6c66722 100644
--- a/ci/funs.sh
+++ b/ci/funs.sh
@@ -1,5 +1,7 @@
-# utilities used in CI pipelines to avoid duplication.
+# Utilities used in CI pipelines and tooling to avoid duplication.
 # Avoid top-level statements.
+# Prefer nim scripts whenever possible.
+# functions starting with `_` are considered internal, less stable.
 
 echo_run () {
   # echo's a command before running it, which helps understanding logs
@@ -28,3 +30,72 @@ nimIsCiSkip(){
     return 1
   fi
 }
+
+nimDefineVars(){
+  nim_csourcesDir=csources_v1 # where we clone
+  nim_csourcesUrl=https://github.com/nim-lang/csources_v1.git
+  nim_csourcesHash=a8a5241f9475099c823cfe1a5e0ca4022ac201ff
+  nim_csources=bin/nim_csources_$nim_csourcesHash
+}
+
+_nimNumCpu(){
+  # linux: $(nproc)
+  # FreeBSD | macOS: $(sysctl -n hw.ncpu)
+  # OpenBSD: $(sysctl -n hw.ncpuonline)
+  # windows: $NUMBER_OF_PROCESSORS ?
+  echo $(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || 1)
+}
+
+_nimBuildCsourcesIfNeeded(){
+  # if some systems cannot use make or gmake, we could add support for calling `build.sh`
+  # but this is slower (not parallel jobs) and would require making build.sh
+  # understand the arguments passed to the makefile (e.g. `CC=gcc ucpu=amd64 uos=darwin`),
+  # instead of `--cpu amd64 --os darwin`.
+  unamestr=$(uname)
+  # uname values: https://en.wikipedia.org/wiki/Uname
+  if [ "$unamestr" = 'FreeBSD' ]; then
+    makeX=gmake
+  elif [ "$unamestr" = 'OpenBSD' ]; then
+    makeX=gmake
+  else
+    makeX=make
+  fi
+  nCPU=$(_nimNumCpu)
+  echo_run which $makeX
+  # parallel jobs (5X faster on 16 cores: 10s instead of 50s)
+  echo_run $makeX -C $nim_csourcesDir -j $((nCPU + 2)) -l $nCPU "$@"
+  # keep $nim_csources in case needed to investigate bootstrap issues
+  # without having to rebuild
+  echo_run cp bin/nim $nim_csources
+}
+
+nimCsourcesHash(){
+  nimDefineVars
+  echo $nim_csourcesHash
+}
+
+nimBuildCsourcesIfNeeded(){
+  # goal: allow cachine each tagged version independently
+  # to avoid rebuilding, so that tools like `git bisect`
+  # can grab a cached past version without rebuilding.
+  nimDefineVars
+  (
+    set -e
+    # avoid polluting caller scope with internal variable definitions.
+    if test -f "$nim_csources"; then
+      echo "$nim_csources exists."
+    else
+      if test -d "$nim_csourcesDir"; then
+        echo "$nim_csourcesDir exists."
+      else
+        # depth 1: adjust as needed in case useful for `git bisect`
+        echo_run git clone -q --depth 1 $nim_csourcesUrl "$nim_csourcesDir"
+        echo_run git -C "$nim_csourcesDir" checkout $nim_csourcesHash
+      fi
+      _nimBuildCsourcesIfNeeded "$@"
+    fi
+
+    echo_run cp $nim_csources bin/nim
+    echo_run $nim_csources -v
+  )
+}
diff --git a/ci/nsis_build.bat b/ci/nsis_build.bat
deleted file mode 100644
index 12aff1b72..000000000
--- a/ci/nsis_build.bat
+++ /dev/null
@@ -1,59 +0,0 @@
-REM - Run the full testsuite;  testament\tester all
-
-REM - Uncomment the list of changes in news.txt
-REM - write a news ticker entry
-REM - Update the version
-
-REM - Generate the full docs;  koch web0
-REM - Generate the installers;
-REM - Update the version in system.nim
-REM - Test the installers
-REM - Tag the release
-REM - Merge devel into master
-REM - Update csources
-
-set NIMVER=%1
-
-Rem Build -docs file:
-koch web0
-cd web\upload
-7z a -tzip docs-%NIMVER%.zip *.html
-move /y docs-%NIMVER%.zip download
-cd ..\..
-
-Rem Build csources
-koch csources -d:release || exit /b
-
-rem Grab C sources and nimsuggest
-git clone --depth 1 https://github.com/nim-lang/csources_v1.git csources
-
-set PATH=%CD%\bin;%PATH%
-
-ReM Build Win32 version:
-
-set PATH=C:\Users\araq\projects\mingw32\bin;%PATH%
-cd csources
-call build.bat
-cd ..
-ReM Rebuilding koch is necessary because it uses its pointer size to determine
-ReM which mingw link to put in the NSIS installer.
-nim c --out:koch_temp koch || exit /b
-koch_temp boot -d:release || exit /b
-koch_temp nsis -d:release || exit /b
-koch_temp zip -d:release || exit /b
-dir build
-move /y build\nim_%NIMVER%.exe build\nim-%NIMVER%_x32.exe || exit /b
-move /y build\nim-%NIMVER%.zip build\nim-%NIMVER%_x32.zip || exit /b
-
-
-ReM Build Win64 version:
-set PATH=C:\Users\araq\projects\mingw64\bin;%PATH%
-cd csources
-call build64.bat
-cd ..
-nim c --out:koch_temp koch || exit /b
-koch_temp boot -d:release || exit /b
-koch_temp nsis -d:release || exit /b
-koch_temp zip -d:release || exit /b
-move /y build\nim_%NIMVER%.exe build\nim-%NIMVER%_x64.exe || exit /b
-move /y build\nim-%NIMVER%.zip build\nim-%NIMVER%_x64.zip || exit /b