Compile Swift on Mac and Start Windows
If you have the correct Windows swift library module, your macOS swift compiler can generate Windows object files like Hello.obj. Alternatively, you can create an executable file (like Hello.exe) if you have a dedicated linker and some C / C ++ runtime object files for Windows.
All you need is the following.
-
Copy directories to macOS from Windows package.
1) Install Swift for Windows ver-1.5 ( https://swiftforwindows.codeplex.com ) on Windows
2) Copy directories to macOS from Windows
SwiftForWindows/Swift/lib/swift // Swift library for Windows (MinGW) SwiftForWindows/Swift/lib/mingw // C/C++ runtime object files (MinGW)
-
Install Swift Compiler for MacOS ( https://swift.org/builds/swift-3.0-release/xcode/swift-3.0-RELEASE/swift-3.0-RELEASE-osx.pkg )
You must use the same version for the library unit and compiler. Use version 3.0. Swift 3.0.1 or 3.1 will not work with SwiftForWindows-1.5.
-
Install the MinGW linker with Mac port
1) Install the Mac port (https://www.macports.org/install.php)
2) $ sudo port install x86_64-w64-mingw32-binutils
3) Create bfd_ld directory and copy / opt / local / bin / x 86_64-w64-mingw32-ld and name in ld
$ mkdir bfd_ld $ cp -p /opt/local/bin/x86_64-w64-mingw32-ld bfd_ld/ld
-
Additional settings
1) Rename the directory on macOS
mv SwiftForWindows/Swift/lib/swift/mingw SwiftForWindows/Swift/lib/swift/windows
2) Copy C Objects (3 files)
cp SwiftForWindows/Swift/lib/mingw/*.o bfd_ld
-
Compilation
echo "print(Hello)" > Hello.swift ~/Library/Developer/Toolchains/swift-3.0-RELEASE.xctoolchain/usr/bin/swiftc -target x86_64-pc-windows-gnu -resource-dir SwiftForWindows/Swift/lib/swift -tools-directory bfd_ld -L SwiftForWindows/Swift/lib/mingw -lswiftSwiftOnoneSupport -o Hello.exe Hello.swift
This will generate Hello.exe. You can ignore the "Warning: .drectve" message.
-
Running
The executable will need a DLL in the SwiftForWindows / My Programs directory.
Copy the Hello.exe file to a directory on Windows and run it.
Good luck to you. Thank.
source to share
If you want to run Swift code on Windows, the closest you can get is swift-windows . I've never used it, but it looks like you can compile your Swift 3.0 code into a Windows executable.
To download the prebuilt binaries, try this link . It requires Windows 10 64 bit and Visual Studio 2015 SDK. Also, you will have to have a cygwin or mingw environment.
source to share