From 80f822c2275744a4fd3c1029d91d32cd34595f2b Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 23 Feb 2020 18:27:26 +0100 Subject: [PATCH] Set up CI with Azure Pipelines (#13) * Set up CI with Azure Pipelines [skip ci] * Add task for testing without GMP * Add C++ testing + no GMP on windows * Add the Nim wrapper for GMP to Azure build * Add Azure badge * Fix nimble test tasks * Workaround windows path in Azure * Fix nim binaries path and mingw on 32-bit * add stew test dependency * Fix nim/nimble path * disable GMP tests on windows --- README.md | 4 +- azure-pipelines.yml | 197 ++++++++++++++++++++++++++++++++++++++++++++ constantine.nimble | 38 ++++++--- 3 files changed, 227 insertions(+), 12 deletions(-) create mode 100644 azure-pipelines.yml diff --git a/README.md b/README.md index 3600fc0..97ada4d 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ [![License: Apache](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) -![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg) - +![Stability: experimental](https://img.shields.io/badge/stability-experimental-orange.svg)\ [![Build Status: Travis](https://img.shields.io/travis/com/mratsim/constantine/master?label=Travis%20%28Linux%20x86_64%2FARM64,%20MacOS%20x86_64%29)](https://travis-ci.com/mratsim/constantine) +[![Build Status: Azure](https://img.shields.io/azure-devops/build/numforge/07a2a7a5-995a-45d3-acd5-f5456fe7b04d/4?label=Azure%20%28Linux%2064-bit%2C%20Windows%2032%2F64-bit%2C%20MacOS%2064-bit%29)](https://dev.azure.com/numforge/Constantine/_build?definitionId=4&branchName=master) This library provides constant-time implementation of elliptic curve cryptography. diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..bb936fc --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,197 @@ +strategy: + maxParallel: 10 + matrix: + # TODO: Linux 32-bit requires gcc -m32 setup + + Windows_devel_32bit: + VM: 'windows-latest' + UCPU: i686 + CHANNEL: devel + TEST_LANG: c + Windows_devel_64bit: + VM: 'windows-latest' + UCPU: amd64 + CHANNEL: devel + TEST_LANG: c + Windows_cpp_devel_64bit: + VM: 'windows-latest' + UCPU: amd64 + CHANNEL: devel + TEST_LANG: cpp + Linux_devel_64bit: + VM: 'ubuntu-16.04' + UCPU: amd64 + CHANNEL: devel + TEST_LANG: c + Linux_cpp_devel_64bit: + VM: 'ubuntu-16.04' + UCPU: amd64 + CHANNEL: devel + WEAVE_TEST_LANG: cpp + + # Linux_devel_32bit: + # VM: 'ubuntu-16.04' + # UCPU: i686 + # CHANNEL: devel + # TEST_LANG: c + + MacOS_devel_64bit: + VM: 'macOS-10.14' + UCPU: amd64 + CHANNEL: devel + TEST_LANG: c +pool: + vmImage: $(VM) + +steps: + - task: CacheBeta@1 + displayName: 'cache Nim binaries' + inputs: + key: NimBinaries | $(Agent.OS) | $(CHANNEL) | $(UCPU) + path: NimBinaries + + - task: CacheBeta@1 + displayName: 'cache MinGW-w64' + inputs: + key: mingwCache | 8_1_0 | $(UCPU) + path: mingwCache + condition: eq(variables['Agent.OS'], 'Windows_NT') + + - powershell: | + Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1 + displayName: 'long path support' + condition: eq(variables['Agent.OS'], 'Windows_NT') + - bash: | + echo "PATH=${PATH}" + set -e + echo "Installing MinGW-w64" + if [[ $UCPU == "i686" ]]; then + MINGW_FILE="i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z" + MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/8.1.0/threads-posix/dwarf/${MINGW_FILE}" + MINGW_DIR="mingw32" + else + MINGW_FILE="x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z" + MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/seh/${MINGW_FILE}" + MINGW_DIR="mingw64" + fi + mkdir -p mingwCache + pushd mingwCache + if [[ ! -e "$MINGW_FILE" ]]; then + rm -f *.7z + curl -OLsS "$MINGW_URL" + fi + 7z x -y -bd "$MINGW_FILE" >/dev/null + mkdir -p /c/custom + mv "$MINGW_DIR" /c/custom/ + popd + + # Workaround https://developercommunity.visualstudio.com/content/problem/891929/windows-2019-cygheap-base-mismatch-detected-git-ba.html + echo "##vso[task.prependpath]/usr/bin" + echo "##vso[task.prependpath]/mingw64/bin" + echo "##vso[task.setvariable variable=MINGW_DIR;]$MINGW_DIR" + + displayName: 'Install dependencies (Windows)' + condition: eq(variables['Agent.OS'], 'Windows_NT') + - powershell: | + # export custom mingw PATH to other tasks + echo "##vso[task.prependpath]c:\custom\$(MINGW_DIR)\bin" + displayName: 'Mingw PATH (Windows)' + condition: eq(variables['Agent.OS'], 'Windows_NT') + + - bash: | + echo "PATH=${PATH}" + export ncpu= + case '$(Agent.OS)' in + 'Linux') + ncpu=$(nproc) + ;; + 'Darwin') + ncpu=$(sysctl -n hw.ncpu) + ;; + 'Windows_NT') + ncpu=$NUMBER_OF_PROCESSORS + ;; + esac + [[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1 + echo "Found ${ncpu} cores" + echo "##vso[task.setvariable variable=ncpu;]$ncpu" + displayName: 'Detecting number of cores' + + - bash: | + echo "PATH=${PATH}" + gcc -v + export ucpu=${UCPU} + + if [ "${CHANNEL}" = stable ]; then + BRANCH="v$(curl https://nim-lang.org/channels/stable)" + else + BRANCH="${CHANNEL}" + fi + mkdir -p NimBinaries + pushd NimBinaries + if [ ! -x "nim-${CHANNEL}/bin/nim" ]; then + git clone -b "${BRANCH}" https://github.com/nim-lang/nim "nim-${CHANNEL}/" + pushd "nim-${CHANNEL}" + git clone --depth 1 https://github.com/nim-lang/csources csources/ + pushd csources + + make -j $ncpu ucpu=${UCPU} CC=gcc + popd + rm -rf csources + bin/nim c koch + ./koch boot -d:release + ./koch tools + else + pushd "nim-${CHANNEL}" + git fetch origin "${BRANCH}" + if [[ $(git merge FETCH_HEAD | grep -c "Already up to date.") -ne 1 ]]; then + bin/nim c koch + ./koch boot -d:release + ./koch tools + fi + fi + popd # exit nim-${CHANNEL} + popd # exit NimBinaries + displayName: 'Building Nim' + + - powershell: | + echo "##vso[task.prependpath]$pwd\NimBinaries\nim-$(CHANNEL)\bin" + displayName: 'Set env variable (Windows)' + condition: eq(variables['Agent.OS'], 'Windows_NT') + - bash: | + echo "##vso[task.prependpath]$PWD/NimBinaries/nim-${CHANNEL}/bin" + displayName: 'Set env variable (Posix)' + condition: ne(variables['Agent.OS'], 'Windows_NT') + + # GMP is preinstalled on Azure + # - bash: | + # echo "PATH=${PATH}" + # sudo apt-get install libgmp-dev + # displayName: 'Downloading GMP (Linux)' + # condition: eq(variables['Agent.OS'], 'Linux') + # + # - bash: | + # echo "PATH=${PATH}" + # brew install gmp + # displayName: 'Downloading GMP (MacOS)' + # condition: eq(variables['Agent.OS'], 'Darwin') + + - bash: | + echo "PATH=${PATH}" + nimble refresh + nimble install gmp stew + displayName: 'Installing package and testing dependencies' + + - bash: | + echo "PATH=${PATH}" + export ucpu=${UCPU} + nimble test + displayName: 'Testing the package (including GMP)' + condition: ne(variables['Agent.OS'], 'Windows_NT') + + - bash: | + echo "PATH=${PATH}" + export ucpu=${UCPU} + nimble test_no_gmp + displayName: 'Testing the package (without GMP)' + condition: eq(variables['Agent.OS'], 'Windows_NT') diff --git a/constantine.nimble b/constantine.nimble index 5215559..29774f8 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -9,18 +9,36 @@ srcDir = "src" requires "nim >= 1.1.0" ### Helper functions -proc test(fakeCurves: string, path: string, lang = "c") = +proc test(path: string) = if not dirExists "build": mkDir "build" - exec "nim " & lang & fakeCurves & " --outdir:build -r --hints:off --warnings:off " & path + # Compilation language is controlled by WEAVE_TEST_LANG + var lang = "c" + if existsEnv"TEST_LANG": + lang = getEnv"TEST_LANG" + + echo "\n========================================================================================" + echo "Running ", path + echo "========================================================================================" + exec "nim " & lang & " --verbosity:0 --outdir:build -r --hints:off --warnings:off " & path ### tasks task test, "Run all tests": - test "", "tests/test_primitives.nim" - test "", "tests/test_io_bigints.nim" - test "", "tests/test_bigints.nim" - test "", "tests/test_bigints_multimod.nim" - test "", "tests/test_bigints_vs_gmp.nim" - test "", "tests/test_finite_fields.nim" - test "", "tests/test_finite_fields_vs_gmp.nim" - test "", "tests/test_finite_fields_powinv.nim" + # -d:testingCurves is configured in a *.nim.cfg for convenience + test "tests/test_primitives.nim" + test "tests/test_io_bigints.nim" + test "tests/test_bigints.nim" + test "tests/test_bigints_multimod.nim" + test "tests/test_bigints_vs_gmp.nim" + test "tests/test_finite_fields.nim" + test "tests/test_finite_fields_vs_gmp.nim" + test "tests/test_finite_fields_powinv.nim" + +task test_no_gmp, "Run tests that don't require GMP": + # -d:testingCurves is configured in a *.nim.cfg for convenience + test "tests/test_primitives.nim" + test "tests/test_io_bigints.nim" + test "tests/test_bigints.nim" + test "tests/test_bigints_multimod.nim" + test "tests/test_finite_fields.nim" + test "tests/test_finite_fields_powinv.nim"