2019-08-09 17:56:17 +00:00
## Building Nim projects on commercial CI systems
2017-02-25 17:08:29 +00:00
2019-08-09 17:56:17 +00:00
Building your code on CI is useful to check regressions against the master and devel branches of Nim.
2017-02-25 17:08:29 +00:00
Same for your code documentation.
2019-08-09 17:56:17 +00:00
There are 3 most common ways to install Nim:
2019-08-09 17:56:35 +00:00
2019-08-09 17:56:17 +00:00
* Pulling the Debian packages: fastest; requires keeping the .deb file URL up to date
* Using a Docker image: slower but requires little maintenance
* Using choosenim: slow when compiling Nim from sources
2018-10-14 15:36:45 +00:00
The Nim docker image contains the latest version.
2018-06-08 21:12:48 +00:00
Use this .circleci/config.yml
2017-08-26 14:55:12 +00:00
[source,yaml]
----
version: 2
jobs:
build:
2018-10-14 15:36:45 +00:00
docker:
- image: nimlang/nim
2017-08-26 14:55:12 +00:00
steps:
2018-10-14 15:36:45 +00:00
- run: echo 'export PATH=~/.nimble/bin:$PATH' >> $BASH_ENV
2017-08-26 14:55:12 +00:00
- checkout
2018-10-14 15:36:45 +00:00
# Reuse cached directories
2017-08-26 14:55:12 +00:00
- restore_cache:
2018-10-14 15:36:45 +00:00
key: nim-0000
2017-08-26 14:55:12 +00:00
- run:
command: |
2018-10-14 15:36:45 +00:00
# Example: adding OS libraries
apt-get update
apt-get install -y --no-install-recommends libsodium23
2017-08-26 14:55:12 +00:00
- save_cache:
2018-10-14 15:36:45 +00:00
key: nim-0000
2017-08-26 14:55:12 +00:00
paths:
2018-10-14 15:36:45 +00:00
- .nimble
2017-08-26 14:55:12 +00:00
- run: nimble build -y
- run: nim c -r <mytest.nim>
- store_artifacts:
path: test-reports/
destination: tr1
- store_test_results:
path: test-reports/
----
2017-08-26 13:16:58 +00:00
## Building Nim projects on Circle CI v2.0 with Docker
2017-06-25 22:14:48 +00:00
2017-08-26 13:16:58 +00:00
On Circle CI 2.0 you can use Docker containers to perform builds. The following example is taken from the following guide and builds against the current Nim version on both Ubuntu and Alpine Linux: https://www.euantorano.co.uk/posts/nim-circle-ci/[Continuous Integration for Nim using Circle CI]
2017-06-25 22:14:48 +00:00
[source,yaml]
----
version: 2
jobs:
build:
working_directory: /usr/src/dotenv
docker:
- image: nimlang/nim
branches:
only:
- master
steps:
- checkout
- run:
name: test
command: nim c -r tests/main.nim
build_alpine:
working_directory: /usr/src/dotenv
docker:
- image: nimlang/nim:alpine
branches:
only:
- master
steps:
- checkout
- run:
name: test
command: nim c -r tests/main.nim
workflows:
version: 2
build_and_test:
jobs:
- build
- build_alpine
----
2017-02-25 17:08:29 +00:00
## Building Nim projects on Travis CI
2018-10-20 11:40:32 +00:00
### Using Docker
[source,yaml]
----
sudo: required
services:
- docker
before_install:
- docker pull nimlang/nim
script:
- docker run nimlang/nim nim --version
- docker run -v "$(pwd):/project" -w /project nimlang/nim sh -c "nimble install -dy && nimble test"
2018-10-20 13:11:13 +00:00
# - docker run -v "$(pwd):/project" -w /project nimlang/nim sh -c "find src/ -name '*.nim' -type f -exec nim doc {} \;"
2018-10-20 11:40:32 +00:00
----
2018-10-20 13:11:13 +00:00
Uncomment the last line to test embedded `runnableExamples` blocks.
2018-10-20 11:40:32 +00:00
### Using choosenim
[source,yaml]
----
language: c
cache: ccache
cache:
directories:
- .cache
matrix:
include:
# Build and test against the master (stable) and devel branches of Nim
- os: linux
env: CHANNEL=stable
compiler: gcc
- os: linux
env: CHANNEL=devel
compiler: gcc
# On OSX we only test against clang (gcc is mapped to clang by default)
- os: osx
env: CHANNEL=stable
compiler: clang
allow_failures:
# Ignore failures when building against the devel Nim branch
2018-11-30 14:27:47 +00:00
# Also ignore OSX, due to very long build queue
2018-10-20 11:40:32 +00:00
- env: CHANNEL=devel
- os: osx
fast_finish: true
## BEGIN: Assuming you rely on external dependencies
addons: # This will only be executed on Linux
apt:
packages:
- libyourdependency
before_install:
2018-11-30 14:27:47 +00:00
# If you want to install an OSX Homebrew dependency
2018-10-20 11:40:32 +00:00
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install libyourdependency; fi
## END: Assuming you rely on external dependencies
install:
- export CHOOSENIM_NO_ANALYTICS=1
- curl https://nim-lang.org/choosenim/init.sh -sSf > init.sh
- sh init.sh -y
- export PATH=~/.nimble/bin:$PATH
- echo "export PATH=~/.nimble/bin:$PATH" >> ~/.profile
- choosenim $CHANNEL
script:
- nimble refresh
- nimble test
branches:
except:
- gh-pages
----
### Devel branches
2017-02-25 17:08:29 +00:00
Building your code on Travis CI is useful to check regressions against the master and devel branches of Nim.
Same for your code documentation.
Detailed guide, which the following example originates from: +
http://blaxpirit.com/blog/22/advanced-uses-of-travis-ci-with-nim.html[Advanced uses of Travis CI with Nim]
2019-08-09 19:01:33 +00:00
https://github.com/oprypin/nim-random/blob/ed21c4a1289d9314901f253e6edce826a794b17e/.travis.yml[Real example]
2017-02-25 17:08:29 +00:00
[source,yaml]
----
language: c
2019-08-09 19:01:33 +00:00
compiler: gcc
2017-02-25 17:08:29 +00:00
matrix:
2019-08-09 19:01:33 +00:00
include:
- {}
- compiler: clang
- env: nim_channel=devel
2017-02-25 17:08:29 +00:00
allow_failures:
2019-08-09 19:01:33 +00:00
- env: nim_channel=devel
2017-02-25 17:08:29 +00:00
fast_finish: true
2019-08-09 19:01:33 +00:00
before_install:
- nim_channel="${nim_channel-stable}"
- |
if [ "$nim_channel" = stable ]; then
nim_branch="v$(curl https://nim-lang.org/channels/stable)"
else
nim_branch="$nim_channel"
fi
2017-02-25 17:08:29 +00:00
install:
- |
2019-08-09 19:01:33 +00:00
if [ ! -x "nim-$nim_channel/bin/nim" ]; then
git clone -b "$nim_branch" https://github.com/nim-lang/nim "nim-$nim_channel/"
pushd "nim-$nim_channel"
git clone --depth 1 https://github.com/nim-lang/csources csources/
pushd csources
2017-02-25 17:08:29 +00:00
sh build.sh
2019-08-09 19:01:33 +00:00
popd
2017-02-25 17:08:29 +00:00
rm -rf csources
bin/nim c koch
./koch boot -d:release
else
2019-08-09 19:01:33 +00:00
pushd "nim-$nim_channel"
git fetch origin "$nim_branch"
if ! git merge FETCH_HEAD | grep "Already up.to.date"; then
2017-02-25 17:08:29 +00:00
bin/nim c koch
./koch boot -d:release
fi
fi
2019-08-09 19:01:33 +00:00
popd
2017-02-25 17:08:29 +00:00
before_script:
2019-08-09 19:01:33 +00:00
- export PATH="nim-$nim_channel/bin${PATH:+:$PATH}"
2017-02-25 17:08:29 +00:00
script:
# Replace uppercase strings!
2019-08-09 19:01:33 +00:00
- nim compile --cc:$CC --verbosity:0 --run MYFILE.nim
2017-02-25 17:08:29 +00:00
# Optional: build docs.
- nim doc --docSeeSrcUrl:https://github.com/AUTHOR/MYPROJECT/blob/master --project MYFILE.nim
cache:
directories:
- nim-master
2019-08-09 19:01:33 +00:00
- nim-stable
2017-02-25 17:08:29 +00:00
branches:
except:
- gh-pages
----
2017-02-25 18:10:48 +00:00
## Appveyor
Create .appveyor.yml
[source,yaml]
----
version: '{build}'
cache:
- nim-0.16.0_x64.zip
- x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z
matrix:
fast_finish: true
environment:
matrix:
- MINGW_ARCHIVE: x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z
MINGW_DIR: mingw64
MINGW_URL: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z/download
NIM_ARCHIVE: nim-0.16.0_x64.zip
NIM_DIR: nim-0.16.0
NIM_URL: https://nim-lang.org/download/nim-0.16.0_x64.zip
platform: x64
install:
- MKDIR %CD%\tools_tmp
- IF not exist "%MINGW_ARCHIVE%" appveyor DownloadFile "%MINGW_URL%" -FileName "%MINGW_ARCHIVE%"
2017-09-26 22:49:39 +00:00
- 7z x -y "%MINGW_ARCHIVE%" -o"%CD%\tools_tmp"> nul
2017-02-25 18:10:48 +00:00
- IF not exist "%NIM_ARCHIVE%" appveyor DownloadFile "%NIM_URL%" -FileName "%NIM_ARCHIVE%"
2017-09-26 22:49:39 +00:00
- 7z x -y "%NIM_ARCHIVE%" -o"%CD%\tools_tmp"> nul
2017-02-25 18:10:48 +00:00
- SET PATH=%CD%\tools_tmp\%NIM_DIR%\bin;%CD%\tools_tmp\%MINGW_DIR%\bin;%PATH%
build_script:
- nimble.exe install CHANGEME -y
- nim.exe c -p:. ./tests/CHANGEME.nim
test_script:
- ./tests/CHANGEME
deploy: off
----
2017-09-26 22:49:39 +00:00
You may encounter an issue with Sourceforge download and download just a webpage. In that case replace the generic URL by a direct link into a mirror like 'https://ayera.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/4.9.2/threads-win32/seh/x86_64-4.9.2-release-win32-seh-rt_v4-rev4.7z'