diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5661983..d5b65f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,10 @@ on: pull_request: workflow_dispatch: +concurrency: # Cancel stale PR builds (but not push builds) + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + jobs: build: strategy: @@ -43,10 +47,10 @@ jobs: name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})' runs-on: ${{ matrix.builder }} - continue-on-error: ${{ matrix.branch == 'version-1-6' || matrix.branch == 'devel' }} + continue-on-error: ${{ matrix.branch == 'devel' }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install build dependencies (Linux i386) if: runner.os == 'Linux' && matrix.target.cpu == 'i386' @@ -94,23 +98,23 @@ jobs: id: windows-dlls-cache uses: actions/cache@v2 with: - path: external/dlls - key: 'dlls' + path: external/dlls-${{ matrix.target.cpu }} + key: 'dlls-${{ matrix.target.cpu }}' - - name: Install DLL dependencies (Windows) + - name: Install DLLs dependencies (Windows) if: > steps.windows-dlls-cache.outputs.cache-hit != 'true' && runner.os == 'Windows' run: | - mkdir external + mkdir -p external curl -L "https://nim-lang.org/download/windeps.zip" -o external/windeps.zip - 7z x external/windeps.zip -oexternal/dlls + 7z x -y external/windeps.zip -oexternal/dlls-${{ matrix.target.cpu }} - name: Path to cached dependencies (Windows) if: > runner.os == 'Windows' run: | - echo '${{ github.workspace }}'"/external/dlls" >> $GITHUB_PATH + echo "${{ github.workspace }}/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH - name: Derive environment variables run: | @@ -152,5 +156,5 @@ jobs: nim --version nimble --version nimble install -y --depsOnly - env TEST_LANG="c" nimble test - env TEST_LANG="cpp" nimble test + env NIMLANG=c nimble test + env NIMLANG=cpp nimble test diff --git a/faststreams.nimble b/faststreams.nimble index 48a3657..7dfaa0a 100644 --- a/faststreams.nimble +++ b/faststreams.nimble @@ -12,37 +12,27 @@ requires "nim >= 1.2.0", "chronos", "unittest2" -### Helper functions -proc test(args, path: string) = - # Compilation language is controlled by TEST_LANG - let lang = getEnv("TEST_LANG", "c") +let nimc = getEnv("NIMC", "nim") # Which nim compiler to use +let lang = getEnv("NIMLANG", "c") # Which backend (c/cpp/js) +let flags = getEnv("NIMFLAGS", "") # Extra flags for the compiler +let verbose = getEnv("V", "") notin ["", "0"] - # nnkArglist was changed to nnkArgList, so can't always use --styleCheck:error - # https://github.com/nim-lang/Nim/pull/17529 - # https://github.com/nim-lang/Nim/pull/19822 - let styleCheckStyle = - if (NimMajor, NimMinor) < (1, 6): - "hint" - else: - "error" +let styleCheckStyle = if (NimMajor, NimMinor) < (1, 6): "hint" else: "error" +let cfg = + " --styleCheck:usages --styleCheck:" & styleCheckStyle & + (if verbose: "" else: " --verbosity:0 --hints:off") & + " --skipParentCfg --skipUserCfg --outdir:build --nimcache:build/nimcache -f" - var common_args = "-r -f " & getEnv("NIMFLAGS") & " --hints:off --styleCheck:usages --styleCheck:" & styleCheckStyle +proc build(args, path: string) = + exec nimc & " " & lang & " " & cfg & " " & flags & " " & args & " " & path - if getEnv("NIMBUS_ENV_DIR") != "": - common_args &= " --skipParentCfg" - - exec "nim " & lang & " " & args & - " -d:asyncBackend=none " & common_args & " " & path - exec "nim " & lang & " " & args & - " -d:asyncBackend=chronos " & common_args & " " & path - # TODO std backend is broken / untested - # exec "nim " & lang & " " & args & - # " -d:asyncBackend=asyncdispatch " & common_args & " " & path +proc run(args, path: string) = + build args & " -r", path task test, "Run all tests": - test "-d:debug --threads:off", "tests/all_tests" - test "-d:release --threads:off", "tests/all_tests" - test "-d:danger --threads:off", "tests/all_tests" - test "-d:debug --threads:on", "tests/all_tests" - test "-d:release --threads:on", "tests/all_tests" - test "-d:danger --threads:on", "tests/all_tests" + # TODO asyncdispatch backend is broken / untested + for backend in ["-d:asyncBackend=none", "-d:asyncBackend=chronos"]: + for threads in ["--threads:off", "--threads:on"]: + for mode in ["-d:debug", "-d:release", "-d:danger"]: + run backend & " " & threads & " " & mode, "tests/all_tests" + diff --git a/faststreams/buffers.nim b/faststreams/buffers.nim index d7747b7..a86a880 100644 --- a/faststreams/buffers.nim +++ b/faststreams/buffers.nim @@ -1,6 +1,6 @@ import deques, - stew/[ptrops, ranges/ptr_arith], + stew/ptrops, async_backend export diff --git a/faststreams/inputs.nim b/faststreams/inputs.nim index e646338..f1f0b5d 100644 --- a/faststreams/inputs.nim +++ b/faststreams/inputs.nim @@ -1,6 +1,6 @@ import os, memfiles, options, - stew/[ptrops, ranges/ptr_arith], + stew/[ptrops], async_backend, buffers export diff --git a/faststreams/outputs.nim b/faststreams/outputs.nim index f24d297..0903aed 100644 --- a/faststreams/outputs.nim +++ b/faststreams/outputs.nim @@ -8,7 +8,7 @@ import deques, typetraits, - stew/[ptrops, strings, ranges/ptr_arith], + stew/[ptrops, strings], buffers, async_backend export diff --git a/faststreams/textio.nim b/faststreams/textio.nim index 9bdd449..7360ff4 100644 --- a/faststreams/textio.nim +++ b/faststreams/textio.nim @@ -126,7 +126,7 @@ const NewLines* = {'\r', '\n'} Digits* = {'0'..'9'} -proc readLine*(s: InputStream, keepEol = false): TaintedString {.fsMultiSync.} = +proc readLine*(s: InputStream, keepEol = false): string {.fsMultiSync.} = fsAssert readableNow(s) while s.readable: @@ -145,7 +145,7 @@ proc readLine*(s: InputStream, keepEol = false): TaintedString {.fsMultiSync.} = result.add s.read.char proc readUntil*(s: InputStream, - sep: openArray[char]): Option[TaintedString] = + sep: openArray[char]): Option[string] = fsAssert readableNow(s) var res = "" while s.readable(sep.len): @@ -153,14 +153,14 @@ proc readUntil*(s: InputStream, return some(res) res.add s.read.char -template nextLine*(sp: InputStream, keepEol = false): Option[TaintedString] = +template nextLine*(sp: InputStream, keepEol = false): Option[string] = let s = sp if s.readable: some readLine(s, keepEol) else: none string -iterator lines*(s: InputStream, keepEol = false): TaintedString = +iterator lines*(s: InputStream, keepEol = false): string = while s.readable: yield readLine(s, keepEol) diff --git a/tests/test_inputs.nim b/tests/test_inputs.nim index da9dbaa..4e69058 100644 --- a/tests/test_inputs.nim +++ b/tests/test_inputs.nim @@ -4,7 +4,7 @@ import os, unittest2, strutils, random, ../faststreams, ../faststreams/textio -setCurrentDir getAppDir() +setCurrentDir currentSourcePath.parentDir proc str(bytes: openArray[byte]): string = result = newStringOfCap(bytes.len) diff --git a/tests/test_outputs.nim b/tests/test_outputs.nim index 7c1003b..e438099 100644 --- a/tests/test_outputs.nim +++ b/tests/test_outputs.nim @@ -2,7 +2,7 @@ import os, unittest2, random, strformat, - stew/ranges/ptr_arith, + stew/ptrops, ../faststreams, ../faststreams/textio proc bytes(s: string): seq[byte] =