I have grown weary of CMake, and since I noticed that a few weeks ago WSL was added to GitHub Actions’ hosts, I thought I would see if it was possible to run SwiftPM inside WSL and cross‐compile to the external Windows host.
I have gotten Swift 5.2.1 installed both in and out of WSL (Ubuntu 18.04) such that Windows successfully builds for Windows (with CMake) and WSL successfully builds for Linux with SwiftPM. However, in attempting to cross‐compile, I’ve gotten stuck on the part where WSL’s toolchain needs to be directed to use Windows’ SDK.
In every attempt below, graph resolution succeeds and everything is fetched, but then it fails when it tries to build the first source file (meaning all the manifests are correctly building and executing on WSL for WSL and the error has to do with the actual cross‐compile for Windows).
The destination JSON contains these entries (because the --triple
and --sdk
flags didn’t exist yet in 5.2.1):
-
sdk
:/mnt/c/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk
(the one in Windows) -
toolchain-bin-dir
:/usr/bin
(the one in WSL) -
target
:x86_64-unknown-windows-msvc
-
Without any extra
-Xswiftc
flags, it errors like this:<unknown>:0: error: unable to load standard library for target 'x86_64-unknown-windows-msvc' swift: /home/buildnode/jenkins/workspace/oss-swift-5.2-package-linux-ubuntu-18_04/swift/lib/Frontend/FrontendInputsAndOutputs.cpp:111: void swift::FrontendInputsAndOutputs::assertMustNotBeMoreThanOnePrimaryInput() const: Assertion `!hasMultiplePrimaryInputs() && "have not implemented >1 primary input yet"' failed.
Based on this Tensorflow issue, I assume SwiftPM is not passing the SDK to
swiftc
in all the necessary ways. -
Upon adding
-Xswiftc -sdk -Xswiftc //mnt/c/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk
, it errors like this://mnt/c/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/include/dispatch/module.modulemap:1:8: error: redefinition of module 'Dispatch' module Dispatch { ^ /usr/lib/swift/dispatch/module.modulemap:1:8: note: previously defined here module Dispatch { ^
That seems to mean that it is now using both the SDK from the command line and the host SDK at
/
in WSL. -
Remembering similar issues in the past dealing with Android, I tried mimicking the Android cross‐compilation flags for 5.2.1, and doing
-Xswiftc -resource-dir -Xswiftc //mnt/c/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift
instead. Then it errors like this:<module-includes>:1:10: note: in file included from <module-includes>:1: #include "AssertionReporting.h" ^ //mnt/c/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift/shims/AssertionReporting.h:16:10: note: in file included from //mnt/c/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift/shims/AssertionReporting.h:16: #include "SwiftStdint.h" ^ //mnt/c/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk/usr/lib/swift/shims/SwiftStdint.h:28:10: error: 'stdint.h' file not found #include <stdint.h> ^ <unknown>:0: error: could not build C module 'SwiftShims' swift: /home/buildnode/jenkins/workspace/oss-swift-5.2-package-linux-ubuntu-18_04/swift/lib/Frontend/FrontendInputsAndOutputs.cpp:111: void swift::FrontendInputsAndOutputs::assertMustNotBeMoreThanOnePrimaryInput() const: Assertion `!hasMultiplePrimaryInputs() && "have not implemented >1 primary input yet"' failed.
I found this swift‐build issue, which makes it look like Swift either doesn’t know about or cannot find the MSVC components. They are present; CMake can build with them. So my hunch is that CMake automatically infers some
-I
flags or--sysroot
based on knowledge of Visual Studio, which I need to pass manually while inside WSL.
So answers to any of these questions, or any other ideas that might help me along would be appreciated:
- What are the proper
--sysroot
and include (-I
) directories? - Does the SDK contain hard‐coded paths? (The slashes would have to be reversed in WSL, and prepended with
//mnt
.) - Does anyone out there already have a working cross‐compilation from WSL to Windows?