Hi,
I have been playing around with OpenGL and GLFW with Swift on Windows and the experience has been quite pleasant especially with the new SourceKit LSP support!
Right now the version of Swift (and SPM which comes with the installer) I'm using is
swift --version
compnerd.org Swift version 5.3-dev (LLVM f9c85c8b92cf757, Swift 4f49b6ab81b7dcb)
Target: x86_64-unknown-windows-msvc
Downloaded from VS2019#20201009.1
Today I tried adding resources for fun to my package and when I try to build the package it seems like SPM creates a resource_bundle_accessor.swift file that contains an extension for users to access the Bundle.module bundle. The buildPath variable has some issues though (probably the backslashes)
C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug.build\DerivedSources\resource_bundle_accessor.swift:6:29: error: invalid escape sequence in literal
let buildPath = "C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug_resource_bug.resources"
^
C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug.build\DerivedSources\resource_bundle_accessor.swift:6:33: error: invalid escape sequence in literal
let buildPath = "C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug_resource_bug.resources"
^
C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug.build\DerivedSources\resource_bundle_accessor.swift:6:60: error: invalid escape sequence in literal
let buildPath = "C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug_resource_bug.resources"
^
C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug.build\DerivedSources\resource_bundle_accessor.swift:6:67: error: invalid escape sequence in literal
let buildPath = "C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug_resource_bug.resources"
^
C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug.build\DerivedSources\resource_bundle_accessor.swift:6:95: error: invalid escape sequence in literal
let buildPath = "C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug_resource_bug.resources"
^
error: fatalError
The package is an empty one with only a main.swift
file and a "resource.txt" file inside the Sources directory.
Package.swift
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "resource_bug",
targets: [
.target(
name: "resource_bug",
resources: [.process("resource.txt")])
]
)
The same thing happens also when using .copy("resource.txt")
instead of .process("resource.txt")
and with proper packages with multiple sourcefiles etc.
The resource_bundle_accessor.swift
file looks like this
import class Foundation.Bundle
extension Foundation.Bundle {
static var module: Bundle = {
let mainPath = Bundle.main.bundlePath + "/" + "resource_bug_resource_bug.resources"
let buildPath = "C:\Dev\SwiftProjects\resource_bug\.build\x86_64-unknown-windows-msvc\debug\resource_bug_resource_bug.resources"
let preferredBundle = Bundle(path: mainPath)
guard let bundle = preferredBundle != nil ? preferredBundle : Bundle(path: buildPath) else {
fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
}
return bundle
}()
}
One other thing that I discovered is that swift build -Xswiftc -wmo
and that the executable produced by swift build -c release
doesn't work properly yet but normal optimizations do work just fine. Right now these aren't a big deal to me but I thought you guys might want to know about them :)