Skip to content

Commit

Permalink
Switch to llvm-mingw in Windows CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Sep 14, 2023
1 parent e415763 commit d55d3a8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
47 changes: 25 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@ jobs:
- target:
os: linux
builder: ubuntu-20.04
shell: bash
- target:
os: macos
builder: macos-12
shell: bash
- target:
os: windows
builder: windows-latest
shell: msys2 {0}

defaults:
run:
shell: ${{ matrix.shell }}
shell: bash

name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})'
runs-on: ${{ matrix.builder }}
Expand Down Expand Up @@ -74,26 +71,31 @@ jobs:
chmod 755 external/bin/gcc external/bin/g++
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
- name: MSYS2 (Windows i386)
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
uses: msys2/setup-msys2@v2
- name: Restore llvm-mingw (Windows) from cache
if: runner.os == 'Windows'
id: windows-mingw-cache
uses: actions/cache@v3
with:
path-type: inherit
msystem: MINGW32
install: >-
base-devel
git
mingw-w64-i686-toolchain
path: external/mingw-${{ matrix.target.cpu }}
key: 'mingw-llvm-17-${{ matrix.target.cpu }}'

- name: MSYS2 (Windows amd64)
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
uses: msys2/setup-msys2@v2
with:
path-type: inherit
install: >-
base-devel
git
mingw-w64-x86_64-toolchain
- name: Install llvm-mingw dependency (Windows)
if: >
steps.windows-mingw-cache.outputs.cache-hit != 'true' &&
runner.os == 'Windows'
run: |
mkdir -p external
MINGW_BASE="https://github.com/mstorsjo/llvm-mingw/releases/download/20230905"
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
MINGW_URL="$MINGW_BASE/llvm-mingw-20230905-ucrt-x86_64.zip"
ARCH=64
else
MINGW_URL="$MINGW_BASE/llvm-mingw-20230905-ucrt-i686.zip"
ARCH=32
fi
curl -L "$MINGW_URL" -o "external/mingw-${{ matrix.target.cpu }}.zip"
7z x -y "external/mingw-${{ matrix.target.cpu }}.zip" -oexternal/mingw-${{ matrix.target.cpu }}/
mv external/mingw-${{ matrix.target.cpu }}/**/* ./external/mingw-${{ matrix.target.cpu }}
- name: Restore Nim DLLs dependencies (Windows) from cache
if: runner.os == 'Windows'
Expand All @@ -116,6 +118,7 @@ jobs:
if: >
runner.os == 'Windows'
run: |
echo '${{ github.workspace }}'"/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH
echo "${{ github.workspace }}/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
- name: Derive environment variables
Expand Down
12 changes: 10 additions & 2 deletions bearssl/abi/bearssl_pem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ proc pemDecoderPush*(ctx: var PemDecoderContext; data: pointer; len: uint): uint

proc pemDecoderSetdest*(ctx: var PemDecoderContext; dest: proc (destCtx: pointer;
src: pointer; len: uint) {.importcFunc.}; destCtx: pointer) {.inline.} =
ctx.dest = dest

# llvm-mingw will complaints about `incompatible function pointer types`
# because generated type missing const in the middle param
# `void (*)(void *, void *, size_t)`
when false:
ctx.dest = dest

{.emit: """typedef void (*pem_decoder_dest_t)(void *, const void *, size_t);""" .}
{.emit: [ctx.dest, "= (pem_decoder_dest_t)", dest, ";"].}
ctx.destCtx = destCtx


Expand All @@ -62,7 +70,7 @@ const


proc pemDecoderName*(ctx: var PemDecoderContext): cstring {.inline.} =
return addr ctx.name
return cast[cstring](addr ctx.name)


proc pemEncode*(dest: pointer; data: pointer; len: uint; banner: cstring; flags: cuint): uint {.
Expand Down
2 changes: 1 addition & 1 deletion bearssl/pem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func lastEvent*(ctx: var PemDecoderContext): cint =
func banner*(ctx: PemDecoderContext): string =
## Return the `name` field as a string
if ctx.name[ctx.name.high] == char(0):
$(unsafeAddr ctx.name)
$(cast[cstring](unsafeAddr ctx.name))
else:
var res = newString(ctx.name.len)
for i, c in ctx.name: res[i] = ctx.name[i]
Expand Down

0 comments on commit d55d3a8

Please sign in to comment.