Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add Windows builds using MinGW toolchain #1123

Merged
merged 21 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Enforce LF line endings on all text files.
#
# This prevents issues caused by line-ending conversions by Git on Windows.
* text=auto eol=lf

# Avoids changelog conflicts by assuming additions-only, which is by far the common case.
# In the rare case where branch b1 rebases against branch b2 and both branches
# modified the same changelog entry, you'll end up with that changelog entry
# duplicated, which is easily identifiable and fixable.
/changelog.md merge=union

# bug https://github.com/dom96/choosenim/issues/256 for WSL CRLF
*.sh text eol=lf
/config/build_config.txt text eol=lf
11 changes: 9 additions & 2 deletions .github/actions/download-compiler/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ runs:
path: "${{ runner.temp }}"

- name: Unpack the workspace
run: tar xf "$RUNNER_TEMP/compiler.tar"
shell: bash
run: |
import os
import tarfile
from pathlib import Path

archivepath = Path(os.environ["RUNNER_TEMP"]) / "compiler.tar"
with tarfile.open(archivepath) as archive:
archive.extractall()
shell: python
working-directory: "${{ inputs.workspace }}"
40 changes: 40 additions & 0 deletions .github/actions/setup-mingw/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Setup MinGW environment
description: Download and setup MinGW environment for Windows
inputs:
mingw-version:
description: The release tag from niXman/mingw-builds-binaries to use
required: false
default: "13.2.0-rt_v11-rev1"

runs:
using: "composite"
steps:
- if: runner.os != 'Windows'
name: Error when used on non-Windows runners
run: |
echo "::error::This action does not support $RUNNER_OS"
exit 1
shell: bash

- name: Download from niXman/mingw-builds-binaries
id: download
uses: robinraju/[email protected]
with:
repository: niXman/mingw-builds-binaries
tag: ${{ inputs.mingw-version }}
fileName: x86_64-*-win32-*-ucrt*.7z

- name: Extract MinGW and add to PATH
run: |
7z x "$env:MINGW_ARCHIVE"
rm $env:MINGW_ARCHIVE
Join-Path $env:RUNNER_TEMP "mingw64" "bin" | Out-File -Append $env:GITHUB_PATH
shell: pwsh
env:
MINGW_ARCHIVE:
${{ fromJson(steps.download.outputs.downloaded_files)[0] }}
working-directory: ${{ runner.temp }}

- name: Print GCC version
run: gcc -v
shell: pwsh
20 changes: 13 additions & 7 deletions .github/actions/upload-compiler/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ runs:
steps:
- name: Package workspace
run: |
# Package new and changed files
declare -a diff
while IFS= read -r -d '' file; do
diff+=("$file")
done < <(git ls-files -zmo)
tar cf "$RUNNER_TEMP/compiler.tar" "${diff[@]}"
shell: bash
import os
import tarfile
from pathlib import Path
from subprocess import run, PIPE

diff = run(["git", "ls-files", "-zmo"], stdout=PIPE, check=True).stdout.split(b"\0")
diff = [f.decode() for f in diff if f] # trim empty strings and decode into str

archivepath = Path(os.environ["RUNNER_TEMP"]) / "compiler.tar"
with tarfile.open(archivepath, mode="x") as archive:
for file in diff:
archive.add(file)
shell: python
working-directory: "${{ inputs.source }}"

- uses: actions/upload-artifact@v4
Expand Down
119 changes: 117 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ jobs:
{
"name": "macOS",
"runner": "macos-11"
},
{
"name": "Windows",
"runner": "windows-2022"
}
]
EOF
Expand Down Expand Up @@ -123,6 +127,30 @@ jobs:
- name: Enable annotations
run: echo "::add-matcher::.github/nim-problem-matcher.json"

- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw

- name: Install dependencies (Windows)
if: runner.os == 'Windows'
uses: johnwason/vcpkg-action@v6
with:
pkgs: >-
pcre
sqlite3
triplet: x64-mingw-dynamic-release
extra-args: --overlay-triplets=${{ github.workspace }}/tools/vcpkg/triplets --host-triplet=x64-mingw-dynamic-release
revision: 2024.01.12
github-binarycache: true
token: ${{ github.token }}

- name: Download CA certificates (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
Invoke-WebRequest https://curl.se/ca/cacert.pem -OutFile (Join-Path $binPath "cacert.pem")
shell: pwsh

- name: Build release binaries
run: ./koch.py all-strict

Expand Down Expand Up @@ -180,6 +208,17 @@ jobs:
run: |
brew update

- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw

- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh

- name: Run tester
run: ./koch.py test --batch:'${{ matrix.batch }}_${{ matrix.total_batch }}' --tryFailing all

Expand All @@ -205,6 +244,17 @@ jobs:
fetch-depth: 0
filter: tree:0

- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw

- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh

- uses: ./.github/actions/download-compiler

- name: Enable annotations
Expand Down Expand Up @@ -269,6 +319,16 @@ jobs:
runs-on: ${{ matrix.target.runner }}

steps:
- name: Get actions
uses: actions/checkout@v4
with:
path: git-src
sparse-checkout: .github/actions

- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./git-src/.github/actions/setup-mingw

- name: Download source archive
uses: actions/download-artifact@v4
with:
Expand All @@ -281,6 +341,34 @@ jobs:
# Pipe from zstd to tar because macOS' tar does not support unpacking zstd
zstd -c -d "$archive" | tar -xf - --strip-components 1

- name: Install dependencies (Windows)
if: runner.os == 'Windows'
uses: johnwason/vcpkg-action@v6
with:
pkgs: >-
pcre
sqlite3
triplet: x64-mingw-dynamic-release
extra-args: --overlay-triplets=${{ github.workspace }}/tools/vcpkg/triplets --host-triplet=x64-mingw-dynamic-release
revision: 2024.01.12
github-binarycache: true
token: ${{ github.token }}

- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh

- name: Install DLLs to package (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
Copy-Item (Join-Path $binPath "libpcre.dll") -Destination bin
shell: pwsh

- name: Build release binaries
run: ./koch.py all

Expand All @@ -298,7 +386,11 @@ jobs:
- id: package
name: Create release package
run: |
./koch.py unixrelease
releasecmd=unixrelease
if [[ "$RUNNER_OS" == Windows ]]; then
releasecmd=winrelease
fi
./koch.py "$releasecmd"

archive=build/archive/$(jq -r .name build/archive/archive.json)
# Rename the archive manifest to avoid collision with other artifacts
Expand Down Expand Up @@ -343,6 +435,25 @@ jobs:
- name: Enable annotations
run: echo "::add-matcher::.github/nim-problem-matcher.json"

- name: Install MinGW (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/setup-mingw

- name: Add DLLs to PATH (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
shell: pwsh

- name: Install DLLs to package (Windows)
if: runner.os == 'Windows'
run: |
$binPath = Join-Path $PWD "vcpkg" "installed" "x64-mingw-dynamic-release" "bin"
$binPath | Out-File -Append $env:GITHUB_PATH
Copy-Item (Join-Path $binPath "libpcre.dll") -Destination bin
shell: pwsh

# Note: keep synchronized with source_binaries job
- name: Build docs
run: |
Expand All @@ -357,7 +468,11 @@ jobs:
- id: package
name: Create release package
run: |
./koch.py unixrelease
releasecmd=unixrelease
if [[ "$RUNNER_OS" == Windows ]]; then
releasecmd=winrelease
fi
./koch.py "$releasecmd"

archive=build/archive/$(jq -r .name build/archive/archive.json)
# Rename the archive manifest to avoid collision with other artifacts
Expand Down
2 changes: 2 additions & 0 deletions compiler/installer.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Files: "icons/nim.rc"
Files: "icons/nim.res"
Files: "icons/nim_icon.o"

Files: "tools/koch/icons/koch_icon.o"

Files: "compiler"
Files: "doc"
Files: "doc/html"
Expand Down
4 changes: 4 additions & 0 deletions compiler/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ define:nimPreviewFloatRoundtrip

@if windows:
cincludes: "$lib/wrappers/libffi/common"
@if gcc:
# use an 8MB stack to prevent overflows
passL: "-Wl,--stack,8388608"
@end
@end

define:useStdoutAsStdmsg
Expand Down
3 changes: 3 additions & 0 deletions config/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ gcc.options.speed = "-O3 -fno-strict-aliasing -fno-ident"
gcc.options.size = "-Os -fno-ident"
@if windows:
gcc.options.debug = "-g3 -Og -gdwarf-3"
@if release:
gcc.options.linker = "-Wl,--no-insert-timestamp"
@end
@else:
gcc.options.debug = "-g3 -Og"
@end
Expand Down
11 changes: 6 additions & 5 deletions lib/posix/posix_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ proc osReleaseFile*(): Config {.since: (1, 5).} =
## Available in Linux and BSD distributions, except Android and Android-based Linux.
## `os-release` file is not available on Windows and OS X by design.
## * https://www.freedesktop.org/software/systemd/man/os-release.html
runnableExamples:
import std/parsecfg
when defined(linux):
let data = osReleaseFile()
echo "OS name: ", data.getSectionValue("", "NAME") ## the data is up to each distro.
when defined(posix):
runnableExamples:
import std/parsecfg
when defined(linux):
let data = osReleaseFile()
echo "OS name: ", data.getSectionValue("", "NAME") ## the data is up to each distro.

# We do not use a {.strdefine.} because Standard says it *must* be that path.
for osReleaseFile in ["/etc/os-release", "/usr/lib/os-release"]:
Expand Down
7 changes: 1 addition & 6 deletions lib/wrappers/pcre.nim
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,7 @@ type

when not defined(usePcreHeader):
when hostOS == "windows":
when defined(nimOldDlls):
const pcreDll = "pcre.dll"
elif defined(cpu64):
const pcreDll = "pcre64.dll"
else:
const pcreDll = "pcre32.dll"
const pcreDll = "(lib|)pcre.dll"
elif hostOS == "macosx":
const pcreDll = "libpcre(.3|.1|).dylib"
else:
Expand Down
7 changes: 1 addition & 6 deletions lib/wrappers/sqlite3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ when defined(nimHasStyleChecks):
{.push styleChecks: off.}

when defined(windows):
when defined(nimOldDlls):
const Lib = "sqlite3.dll"
elif defined(cpu64):
const Lib = "sqlite3_64.dll"
else:
const Lib = "sqlite3_32.dll"
const Lib = "(lib|)sqlite3.dll"
elif defined(macosx):
const
Lib = "libsqlite3(|.0).dylib"
Expand Down
5 changes: 5 additions & 0 deletions nimsuggest/nimsuggest.nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ define:nimcore
define:"nimMaxHeap=4000"
@end

@if windows and gcc:
# use an 8MB stack to prevent overflows
passL: "-Wl,--stack,8388608"
@end

--path:"$config/.."
--threads:on
3 changes: 2 additions & 1 deletion nimsuggest/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ proc parseTest(filename: string; epcMode=false): Test =
result.script.add((x.substr(1).replaceWord("$path", tpath), ""))
elif x.len > 0:
# expected output line:
let filename = replace(filename, '\\', '/')
let x = x % ["file", filename, "lib", libpath]
result.script[^1][1].add x.replace(";;", "\t") & '\L'
# else: ignore empty lines for better readability of the specs
Expand Down Expand Up @@ -211,7 +212,7 @@ proc sexpToAnswer(s: SexpNode): string =
result.add '\t'
result.add typ
result.add '\t'
result.add file
result.add replace(file, '\\', '/')
result.add '\t'
result.addInt line
result.add '\t'
Expand Down
1 change: 1 addition & 0 deletions tests/arc/timportedobj.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
discard """
cmd: "nim c --gc:arc $file"
action: "compile"
disabled: "windows"
zerbina marked this conversation as resolved.
Show resolved Hide resolved
"""

# bug #13269
Expand Down
Loading
Loading