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

Conversation

alaviss
Copy link
Contributor

@alaviss alaviss commented Jan 20, 2024

Summary

Implement Windows 64-bit testing and builds using MinGW toolchain, as
well as providing Windows compatibility patches

Details

Toolchain and dependencies

  • DLLs are built within CI from Microsoft's vcpkg repository as it
    appears to be the most reliable source for pinned library versions out
    there.
  • vcpkg uses custom triplets hosted in this repository to ensure
    reproducible builds
  • Toolchain is sourced from
    https://github.com/niXman/mingw-builds-binaries, which provides bare
    toolchains without extras like gdb.
  • The target is Windows Universal C Runtime, the new C99 compatible
    standard library bundled with Windows 10.

CI changes

  • Download/Upload compiler actions has been rewritten in Python to make
    sure that they are compatible across OSes.
  • Added a new setup-mingw action to setup a MinGW environment.
  • Added Windows to the matrix using windows-2022 image.

Git tree changes

  • Added configuration to force LF line endings on all platforms. This
    makes sure that Windows users always has the same source on disk as
    everyone else.

Compiler changes

  • Added missing resources required to compile koch from source
    archive.
  • On Windows, nim and nimsuggest now have a stack size of 8MiB.
    This avoids stack overflow when compiling complex programs, and make
    sure that the stack size is similar to Linux and macOS.
  • On Windows, PE timestamps are removed for release builds using GCC.
    This makes sure that release builds are reproducible.

Standard library changes

  • posix_utils examples are disabled on Windows as they could not be
    compiled there.
  • pcre and sqlite now prefers canonical DLL names on Windows.
    This makes it easier to use built DLLs from repositories like Conan or
    vcpkg.

Tests changes

  • nimsuggest 's tester now normalizes all path endings to Unix-style
    / .
  • Removed tfdleak_multiple as the "flaky" status no longer applies
    due to changes to tfdleak .
  • tvmprofiler got an increased time range to account for Windows CI
    being relatively slower than the rest.
  • Tests that requires POSIX imports are disabled.

Closes #276

@alaviss alaviss requested a review from a team as a code owner January 20, 2024 23:04
@alaviss alaviss force-pushed the mingw branch 3 times, most recently from 959e475 to 03fbbf7 Compare January 20, 2024 23:13
@saem saem added test Add or improve tests ci Continuous Integration labels Jan 20, 2024
@saem
Copy link
Collaborator

saem commented Jan 20, 2024

Minor update to the PR summary to indicate that it's for 64-bit. Reviewing the rest of the PR now.

saem
saem previously approved these changes Jan 20, 2024
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alaviss alaviss force-pushed the mingw branch 3 times, most recently from dea909f to 708190d Compare January 21, 2024 19:24
@alaviss alaviss dismissed saem’s stale review January 23, 2024 03:52

this is now a behemoth that requires slicing

github-merge-queue bot pushed a commit that referenced this pull request Jan 23, 2024
## Summary

Importing posix or modules that are meant to work on POSIX systems will
make tests unable to compile on non-POSIX platforms (ie. Windows) due to
missing required C headers.

---
<!--- Anything before this section break (`---`) will be used as
the commit message when the PR is merged. -->

## Notes for Reviewers
* Cherry picked from #1123 
* I'm not sure if importing `posix` is required for `tconcepts_issues`
(ie. due to unwanted interactions), but I haven't seen complaints from
CI so far, nor was there any references to symbols defined in posix.

<!--
Pull Request(PR) Help

Before Merge Ensure:
* title reads like a short changelog line entry
* code includes tests and is documented
* leave the source better than before, but split out big reformats

See contributor
(guide)[https://nim-works.github.io/nimskull/contributing.html]
for details, especially if you're new to this project.

Tips that make PRs easier:
* for big/impactful changes, start with chat/discussions to refine ideas
* refine the pull request message over time; don't have to nail it in
one go
This commit implements CI/CD for Windows using MinGW toolchain.

Implementation details:

* Toolchain is sourced from
  https://github.com/niXman/mingw-builds-binaries, which are bare
  toolchain without extras like gdb.
* The target is Windows Universal C Runtime, the new C99 compatible
  standard library bundled with Windows 10.
* Download/Upload compiler actions has been rewritten in Python to
  make sure that they are compatible across OSes.
This file is required to build on Windows x64
The path in the test message uses Unix path separators, which is incorrect
on Windows.

There's no easy way to handle this with the current testament, so skip
this one on Windows.
While POSIX shells will unwrap this, on Windows the quotes are passed
verbatim.
With the usage of CompareObjectHandles, Windows leaks are now accurately
determined and this test is obsolete.
We don't bundles DLLs at the moment, so make sure the name is close to
what users might have in their environment.
We don't bundle DLLs at the moment, so keep the names close to what a typical
Windows dev environment might carry.
Windows have \ as its preferred separator, which broke tests due
to how they are compared. To handle this, normalize the separator to
/, which is both supported by Windows and *nix, simplifying test writing
Windows CI seems to barely cut it to 10000, so bump the value higher.

Also add a debug print so we know if the value requires adjustment.
The compiler requires a fair bit of stack space to function properly.
Windows default 1MB is rather restrictive, so use 8MB to match the rest
of the supported OS.
This ensure that release builds are reproducible.
This makes sure that Git will checkout files exactly the way they are
on Windows, preventing errors from the automatic CRLF conversion.
This is a POSIX test
This test requires a POSIX import
The runnable examples only compiles on POSIX
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this change is about as lean as it gets. If we broke things out further, then we'd be making changes without Windows CI in place. Alternatively, we'd be blocked on Windows CI because it needs some of these changes.

@saem
Copy link
Collaborator

saem commented Jan 30, 2024

PR description looks good.

@saem
Copy link
Collaborator

saem commented Jan 30, 2024

Not going to merge until we get a chance to test the windows binaries that are built from this CI flow.

Copy link
Collaborator

@zerbina zerbina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you for adding Windows CI support!

Since this closes #276, could you add a "Closes" line for it to the PR description?

As far as I know of, @zerbina uses MinGW on Windows, so we are targeting the most tested toolchain.

Yep, I use MinGW on Windows.

tests/arc/timportedobj.nim Show resolved Hide resolved
This makes sure that nimgrep.exe works out of the box
This makes sure that DLLs obtained from vcpkg are reproducible.
vcpkg-action switches directory before running vcpkg, so the relative
path could not work in this case.

This commit switches to absolute path to solve this problem.
@alaviss
Copy link
Contributor Author

alaviss commented Jan 31, 2024

/merge

nimgrep is working on windows with the bundled pcre, so :shipit:

Copy link

Merge requested by: @alaviss

Contents after the first section break of the PR description has been removed and preserved below:


Notes for Reviewers

Toolchain and target ABI selection

Why target MinGW instead of MSVC?

  • Most developers appear to carry a MinGW toolchain due to Nim using it as the default. Bringing in DLLs based on MSVC ABI is a recipe for disaster in a MinGW environment.
  • As far as I know of, @zerbina uses MinGW on Windows, so we are targeting the most tested toolchain.

Why don't we source toolchains and dependencies from MSYS2?

  • MSYS2 is a rolling release, as such their compiler and libraries may fluctuates greatly between runs, creating uncertainty in the pipeline.

Will there be an MSVC target?

  • Maybe. When this PR was first created there were too many issues. Now that those has been cleaned up an MSVC CI is definitely possible.

What architectures are supported?

  • Only x86-64 is built and tested at the moment.

@chore-runner chore-runner bot added this pull request to the merge queue Jan 31, 2024
Merged via the queue into nim-works:devel with commit 2ba0893 Jan 31, 2024
25 checks passed
@alaviss alaviss deleted the mingw branch January 31, 2024 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Continuous Integration test Add or improve tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Windows binaries to GitHub Actions
3 participants