compnerd / swift-win32

A Windows application framework for Swift
https://compnerd.github.io/swift-win32/
BSD 3-Clause "New" or "Revised" License
1.1k stars 69 forks source link

Can not build with Swift 5.9.1 #768

Closed tonka3000 closed 10 months ago

tonka3000 commented 10 months ago

I tried to build the project with the 5.9.1 build from https://www.swift.org/download but I always get the same error with CoreAnimation.

Any idea what is wrong here? Static vs dynamic build?

[main] Building folder: swift-win32 
[build] Starting build
[proc] Executing command: C:\Users\tbam\Downloads\cmake-3.27.7-windows-x86_64\bin\cmake.EXE --build C:/sandbox/swift/swift-win32/build/x86_64-unknown-windows-msvc/Release --target all
[build] [1/6] Linking Swift static library lib\CoreAnimation.lib
[build] FAILED: lib/CoreAnimation.lib Sources/SwiftWin32/CMakeFiles/CoreAnimation.dir/CoreAnimation/Transform3D.swift.obj swift/CoreAnimation.swiftmodule 
[build] cmd.exe /C "cd . && C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe -j 6 -num-threads 6 -emit-library -static -o lib\CoreAnimation.lib -module-name CoreAnimation -module-link-name CoreAnimation -emit-module -emit-module-path swift\CoreAnimation.swiftmodule -emit-dependencies  -sdk C:/Library/Developer/Platforms/Windows.platform/Developer/SDKs/Windows.sdk -O -wmo -libc MD -output-file-map Sources\SwiftWin32\CMakeFiles\CoreAnimation.dir\Release\output-file-map.json  C:\sandbox\swift\swift-win32\Sources\SwiftWin32\CoreAnimation\Transform3D.swift    && cd ."
[build] error: link command failed with exit code 1 (use -v to see invocation)
[build] /usr/bin/link: extra operand '/OUT:lib\\CoreAnimation.lib'
[build] Try '/usr/bin/link --help' for more information.
[build] error: fatalError
[build] [2/6] Linking Swift shared library bin\Collections.dll
[build] ninja: build stopped: subcommand failed.
[proc] The command: C:\Users\tbam\Downloads\cmake-3.27.7-windows-x86_64\bin\cmake.EXE --build C:/sandbox/swift/swift-win32/build/x86_64-unknown-windows-msvc/Release --target all exited with code: 1
[driver] Build completed: 00:00:00.574
[build] Build finished with exit code 1
compnerd commented 10 months ago

You are running in the wrong environment. As the instructions state, run from a VS developer cmd shell. /usr/bin/link would onky appear if you are using bash as the shell.

tonka3000 commented 10 months ago

Thanks, that worked. It is strange that cmake presets don't bootstrap the environment like it is possible with vscode in non cmake-preset cases, but this seems to be intentional from cmake.

I missing the instructions because they are in the swift package manager section. Would you accept a PR where I would update the README in that regard for the cmake section? Just in case somebody else have the same issue.

compnerd commented 10 months ago

@tonka3000 Absolutely!

tonka3000 commented 10 months ago

@compnerd I add #769 with the update in the Readme

One thing I hit with 5.9 when I used SPM to build.

It always throw an error

error: 'swift-win32': package 'package@swift-5.9.swift' is using Swift tools version 3.1.0 which is no longer supported; consider using '// swift-tools-version: 5.9' to specify the current tools version

when I type swift build --product UICatalog.

I was only able to fix it by copy Package@swift-5.4.swift to Package@swift-5.9.swift and change the swift-tools-version to 5.9. I also need add build extra target for CoreAnimation back as it was done in Package.swift, otherwise I always get an error when it tried to import CoreAnimation. I have a full impl. in my fork here

Maybe there are better ways to do that, but I was my first time playing with swift and the redirect package.swift files seems not to allow the declaration of another swift-tools-version.

compnerd commented 10 months ago

Hmm, I think that something weird is going on. SPM should be using Package.swift, which does indicate swift-tools-version:5.7. The redirection is something very recent that I introduced so that I can start ripping out some of the complexity in the build rules.

The intent is to have a version for the older releases and have the latest release use Package.swift.

This does sound like a separate issue, perhaps we should create a new issue to track and discuss it?

tonka3000 commented 10 months ago

This does sound like a separate issue, perhaps we should create a new issue to track and discuss it?

See #771