migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.06k stars 65 forks source link

Windows: Unable to build SwiftGodot using Swift 5.10 toolchain #418

Closed tishin closed 5 months ago

tishin commented 5 months ago

Building SwiftGodot on Windows using Swift 5.10 fails during generator plugin execution:

error: failed: PrebuildCommand(configuration: SPMBuildCore.BuildToolPluginInvocationResult.CommandConfiguration(displayName: Optional("Generating Swift API from /Projects/SwiftGodot/Sources/ExtensionApi/extension_api.json to /Projects/SwiftGodot/.build/plugins/outputs/swiftgodot/SwiftGodot/CodeGeneratorPlugin/GeneratedSources"), executable: <AbsolutePath:"\Projects\SwiftGodot\.build\plugins\tools\debug\Generator.exe">, arguments: ["/Projects/SwiftGodot/Sources/ExtensionApi/extension_api.json", "/Projects/SwiftGodot/.build/plugins/outputs/swiftgodot/SwiftGodot/CodeGeneratorPlugin/GeneratedSources", "/Projects/SwiftGodot/doc", "--singlefile"], environment: [:], workingDirectory: nil), outputFilesDirectory: <AbsolutePath:"\Projects\SwiftGodot\.build\plugins\outputs\swiftgodot\SwiftGodot\CodeGeneratorPlugin\GeneratedSources">)

Generator/main.swift:30: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"
Current stack trace:
0    (null)                             0x00007ffac5964ae0 swift_stdlib_reportFatalErrorInFile + 132
tishin commented 5 months ago

Looks like Foundation file management is broken in Swift 5.10 on Windows. I made a trivial Swift script replicating extension api opening by Generator:

import Foundation

let url = URL(fileURLWithPath: "/Projects/SwiftGodot/Sources/ExtensionApi/extension_api.json")
print(try! Data(contentsOf: url))

It works fine on 5.9.2 release:

PS C:\Projects\UrlIssue> swift --version
Swift version 5.9.2 (swift-5.9.2-RELEASE)
Target: x86_64-unknown-windows-msvc
PS C:\Projects\UrlIssue> swift run      
Building for debugging...
Build complete! (0.07s)
9467198 bytes

But fails on 5.10 release:

PS C:\Projects\UrlIssue> swift --version
Swift version 5.10 (swift-5.10-RELEASE)
Target: x86_64-unknown-windows-msvc
PS C:\Projects\UrlIssue> swift run      
Building for debugging...
Build complete! (0.13s)
Generator/main.swift:4: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"
Current stack trace:
0    (null)                             0x00007fffe8764ae0 swift_stdlib_reportFatalErrorInFile + 132
tishin commented 5 months ago

Reported the issue at https://github.com/apple/swift-corelibs-foundation/issues/4921

tishin commented 5 months ago

After fixing extension api reading Windows build still fails throwing a whole bunch of errors like

C:\Projects\SwiftGodot\Sources\SwiftGodot\Core\VariantCollection.swift:50:24: error: cannot find 'GArray' in scope
        if let array = GArray (variant) {
                       ^~~~~~
C:\Projects\SwiftGodot\Sources\SwiftGodot\Core\VariantRepresentable.swift:91:11: error: cannot find type 'Vector2' in scope
extension Vector2: SelfVariantRepresentable {
          ^~~~~~~
C:\Projects\SwiftGodot\Sources\SwiftGodot\Core\VariantRepresentable.swift:95:11: error: cannot find type 'Vector2i' in scope
extension Vector2i: SelfVariantRepresentable {
          ^~~~~~~~
C:\Projects\SwiftGodot\Sources\SwiftGodot\Core\VariantRepresentable.swift:99:11: error: cannot find type 'Rect2' in scope
extension Rect2: SelfVariantRepresentable {
          ^~~~~

and so on, basically it does not include generated sources into the build for some reason. I'd guess that prebuildCommand workaround does not work anymore. Need to test it on a simpler package.