Skip to content

Commit

Permalink
Updates for Xcode 16 / Linux Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed Sep 21, 2024
1 parent 968d0f4 commit 72f3cf6
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 70 deletions.
26 changes: 23 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
persist-credentials: false
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '16.0-beta'
xcode-version: '16.0'
- name: Set up SDK
run: cd sdk && sudo make install
- name: Run tests
Expand All @@ -33,7 +33,7 @@ jobs:
persist-credentials: false
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '16.0-beta'
xcode-version: '16.0'
- name: Raw build
run: swift build

Expand All @@ -46,7 +46,27 @@ jobs:
with:
submodules: true
persist-credentials: false
- uses: vapor/swiftly-action@v0.1
with:
toolchain: "6.0"
- name: Set up SDK
run: cd sdk && sudo make install
- name: Run tests
run: swift test -Xswiftc -cxx-interoperability-mode=default
run: swift test

linux2:
name: Linux SPM unit tests
runs-on: ubuntu-latest
container:
image: swift:6.0
steps:
- uses: actions/checkout@v4
with:
submodules: true
persist-credentials: false
- name: Install tools
run: apt-get update && apt-get install make
- name: Set up SDK
run: cd sdk && make install
- name: Run tests
run: swift test
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ clean:

# Random flags here to get around crap Linux C++ support
test_linux:
docker run -v `pwd`:`pwd` -w `pwd` --name steamworks --rm swift:5.10 /bin/bash -c "apt-get update; apt-get install make; (cd sdk && make install); swift test -Xswiftc -cxx-interoperability-mode=default"
docker run -v `pwd`:`pwd` -w `pwd` --name steamworks --rm swift:6.0 /bin/bash -c "apt-get update; apt-get install make; (cd sdk && make install); swift test"

shell_linux:
docker run -it -v `pwd`:`pwd` -w `pwd` --name steamworks --rm swift:5.10 /bin/bash
docker run -it -v `pwd`:`pwd` -w `pwd` --name steamworks --rm swift:6.0 /bin/bash
12 changes: 6 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"branch" : "main",
"revision" : "1f2007ef4165432f59f28615c473eb79a844a2af"
"revision" : "9e6597236356dadea31b681cea6a09e8e065fc85"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
"revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64",
"version" : "1.4.3"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"location" : "https://github.com/swiftlang/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
Expand All @@ -42,8 +42,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76",
"version" : "5.1.2"
"revision" : "3036ba9d69cf1fd04d433527bc339dc0dc75433d",
"version" : "5.1.3"
}
}
],
Expand Down
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,13 @@ let package = Package(
),
.testTarget(
name: "SteamworksTests",
dependencies: ["Steamworks", "SteamworksHelpers", "LibGenerate", "SteamworksConcurrency"],
dependencies: [
.target(name: "Steamworks"),
.target(name: "SteamworksHelpers"),
.target(name: "SteamworksConcurrency"),
.target(name: "LibGenerate",
condition: .when(platforms: [.macOS])),
],
exclude: ["Fixtures"],
swiftSettings: [.interoperabilityMode(.Cxx)], // lies lies lies
linkerSettings: clientLinkerSettings
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Current state:
`SteamworksConcurrency` module
* Encrypted app ticket support in separate `SteamworksEncryptedAppTicket` module
* Separate demo showing encrypted app-ticket stuff, `make run_ticket`
* Requires Swift 6, Xcode 16 beta -- Linux not building right now, wait for 6 GA
* Requires Swift 6 / Xcode 16
* The Xcode project basically works.
* ~Unit tests sometimes crash inside steam on exit~ fixed!

Expand Down Expand Up @@ -306,7 +306,7 @@ Fully-fledged AppKit/Metal demo [here](https://github.com/johnfairh/spacewar-swi

### Swift C++ Bugs

_to recheck in Swift 6 for Linux - looking good though_
Mostly fixed in Swift 6. Linux still suffering a bit.

Tech limitations, on 6.0 Xcode 16.b3:
* Some structures/classes aren't imported -- is the common factor a `protected`
Expand All @@ -323,15 +323,17 @@ Tech limitations, on 6.0 Xcode 16.b3:
* ~sourcekit won't give me a module interface for `CSteamworks` to see what else the
importer is doing. Probably Xcode's fault, still not passing the user's flags to
sourcekit and still doing insultingly bad error-reporting.~ fixed in Xcode 15?!
* Linux only: random parts of Glibc silently fail to import. SMH. Work around in C++.
See `swift_shims.h`.
* ~Linux only: random parts of Glibc silently fail to import. SMH. Work around in C++.
See `swift_shims.h`.~ Fixed in 6.0 ("for now")
* ~Linux only: implicit struct constructors are not created, Swift generates a ref
to a non-existent method that fails at link time. Work around with dumb C++
allocate shim.~ Sort of fixed in 5.9, but instead `swiftc` crashes on some uses -- on
allocate shim.~ ~Sort of fixed in 5.9, but instead `swiftc` crashes on some uses -- on
both macOS and Linux. Check by refs to eg. `CSteamNetworkingIPAddr_Allocate()`, see
`steam_missing.h`.
`steam_missing.h`.~ Fixed in 6.0.
* Linux only, _again_: SPM test auto-discovery has no clue about C++ interop. Work around by
smashing in the flag everywhere...
smashing in the flag everywhere... Swift 6 - worse now, utterly broken on Linux with
yams 3rd-party dependency. Maybe fixable with swift-testing - for now nobbled those tests
on Linux. Yay?
* ~Swift 5.8+ adopts a broken/paranoid model about 'projected pointers' requiring some fairly
ugly code to work around. Verify with the `__ unsafe` stuff in `ManualTypes.swift`.~
fixed by Swift 6ish
Expand Down
16 changes: 0 additions & 16 deletions Sources/CSteamworks/steam_missing.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,3 @@ static inline bool CSteamAPI_ISteamNetworkingSockets_SetCertificate( ISteamNetwo
auto msgp = reinterpret_cast<SteamNetworkingErrMsg *>(errMsg);
return SteamAPI_ISteamNetworkingSockets_SetCertificate(self, pCertificate, cbCertificate, *msgp);
}

// On Linux but not Darwin, Swift importer decides not to implement these two
// implicit dumb-struct constructors and instead leaves them as dangling symbols.
//
// OK, that part is fixed in Swift 5.9....
// ...but the swift compiler crashes in IRGen instead in some of invocations.
//
// So we still need these dumb functions.

static inline SteamNetworkingIPAddr CSteamNetworkingIPAddr_Allocate() {
return SteamNetworkingIPAddr();
}

static inline SteamNetworkingIdentity CSteamNetworkingIdentity_Allocate() {
return SteamNetworkingIdentity();
}
1 change: 0 additions & 1 deletion Sources/CSteamworks/steamapi_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
#include "steam_missing.h"
#include "steam_matchmaking_shims.h"
#include "steam_networking_shims.h"
#include "swift_shims.h"
9 changes: 0 additions & 9 deletions Sources/CSteamworks/swift_shims.h

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/LibGenerate/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ final class IO: Sendable {
print("\(Colors.red)\(message)\(Colors.reset)")
}
guard let url = resources.url(forResource: "EXPECTED_SDK", withExtension: nil),
let expected = try? String(contentsOf: url).trimmingCharacters(in: .newlines) else {
let expected = try? String(contentsOf: url, encoding: .utf8).trimmingCharacters(in: .newlines) else {
warn("Can't resolve EXPECTED_SDK")
return
}
Expand Down Expand Up @@ -177,7 +177,7 @@ final class IO: Sendable {
let url = baseURL.appendingPathComponent(fileName)
let fullContents = (header.map { $0 + "\n\n" } ?? "") + contents + "\n"

if let existing = try? String(contentsOf: url) {
if let existing = try? String(contentsOf: url, encoding: .utf8) {
if existing == fullContents {
print("\(Colors.green)\(fileName): unchanged\(Colors.reset)")
return
Expand Down
6 changes: 2 additions & 4 deletions Sources/Steamworks/ManualTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ public struct SteamNetworkingIPAddr: @unchecked Sendable {

/// An invalid address
public init() {
// Crashes Swift 5.9 compiler without thunk...
adr = CSteamNetworkingIPAddr_Allocate() // SteamType
adr = SteamType()
}

/// `INADDR_ANY` with some port
Expand Down Expand Up @@ -406,8 +405,7 @@ public struct SteamNetworkingIdentity: Sendable {

/// Create an invalid identity
public init() {
// Crashes Swift 5.9 compiler without thunk...
identity = CSteamNetworkingIdentity_Allocate() //SteamType()
identity = SteamType()
}

/// Init from a Steam ID
Expand Down
6 changes: 5 additions & 1 deletion Sources/Steamworks/SteamAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
internal import CSteamworks
import Logging

#if canImport(Glibc)
import Glibc
#endif

/// An instance of the Steamworks user API
///
/// Create and retain one of these to access and use the Steamworks APIs.
Expand Down Expand Up @@ -47,7 +51,7 @@ public final class SteamAPI: SteamBaseAPI, @unchecked Sendable {
return nil
}
if fakeAppIdTxtFile {
my_setenv("SteamAppId", "\(appID.value)")
setenv("SteamAppId", "\(appID.value)", 1)
}
if let initSteamCEG, !initSteamCEG() {
logError("SteamAPI.init() failed: Steamworks_InitCEGLibrary() returned false")
Expand Down
4 changes: 4 additions & 0 deletions Tests/SteamworksTests/TestGenNames.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Licensed under MIT (https://github.com/johnfairh/steamworks-swift/blob/main/LICENSE
//

#if !os(Linux)

@testable import LibGenerate
import XCTest

Expand Down Expand Up @@ -113,3 +115,5 @@ class TestNames: XCTestCase {
XCTAssertEqual("expr.map { T($0) }", SwiftExpr("expr").asCast(to: SwiftType("T?")).expr)
}
}

#endif
4 changes: 4 additions & 0 deletions Tests/SteamworksTests/TestGenTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Licensed under MIT (https://github.com/johnfairh/steamworks-swift/blob/main/LICENSE
//

#if !os(Linux)

import XCTest
@testable import Steamworks

Expand Down Expand Up @@ -77,3 +79,5 @@ class TestTypes: XCTestCase {
XCTAssertEqual(strings, oStrings)
}
}

#endif
6 changes: 5 additions & 1 deletion Tests/SteamworksTests/TestGenVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
// Licensed under MIT (https://github.com/johnfairh/steamworks-swift/blob/main/LICENSE
//

@testable import LibGenerate
#if !os(Linux)

import XCTest
@testable import LibGenerate

/// Readme.txt version parsing ... thought there was going to be more here!
///
Expand Down Expand Up @@ -34,3 +36,5 @@ class TestVersion: XCTestCase {
XCTAssertEqual("1.2", version)
}
}

#endif
22 changes: 10 additions & 12 deletions Tests/SteamworksTests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@

import Foundation
import XCTest
#if !os(Linux)
@testable import LibGenerate
import Steamworks
import CSteamworks // for weird 'Linux C++ mode erase random stdlib calls' issue

#if canImport(Darwin)
import Darwin
#endif
#if canImport(GLibc)
import Glibc
#endif
import Steamworks

/// Wrapper for Steam API initialization
///
Expand Down Expand Up @@ -225,6 +219,8 @@ extension XCTestCase {
fixturesURL.appendingPathComponent("steam_api_extra.json")
}

#if !os(Linux)

class Harness {
let swiftOutputDirURL: URL
let cOutputDirURL: URL
Expand All @@ -233,8 +229,8 @@ extension XCTestCase {
let generator: Generator

init() throws {
my_setenv(IO.PATCH_YAML_PATH_VAR, patchYAMLURL.path)
my_setenv(IO.SDK_EXTRA_JSON_PATH_VAR, sdkExtraJSONURL.path)
setenv(IO.PATCH_YAML_PATH_VAR, patchYAMLURL.path, 1)
setenv(IO.SDK_EXTRA_JSON_PATH_VAR, sdkExtraJSONURL.path, 1)
swiftOutputDirURL = try! FileManager.default.createTemporaryDirectory()
cOutputDirURL = try! FileManager.default.createTemporaryDirectory()
docsOutputDirURL = try! FileManager.default.createTemporaryDirectory()
Expand All @@ -252,8 +248,10 @@ extension XCTestCase {
try? FileManager.default.removeItem(at: cOutputDirURL)
try? FileManager.default.removeItem(at: docsOutputDirURL)
try? FileManager.default.removeItem(at: doccCollectionOutputDirURL)
my_unsetenv(IO.PATCH_YAML_PATH_VAR)
my_unsetenv(IO.SDK_EXTRA_JSON_PATH_VAR)
unsetenv(IO.PATCH_YAML_PATH_VAR)
unsetenv(IO.SDK_EXTRA_JSON_PATH_VAR)
}
}

#endif
}
2 changes: 0 additions & 2 deletions steamworks-swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@
02B81B202886C82400780A57 /* SteamMatchmaking+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SteamMatchmaking+Helpers.swift"; sourceTree = "<group>"; };
02B81B232886D68B00780A57 /* SteamUser+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SteamUser+Helpers.swift"; sourceTree = "<group>"; };
02BD4F5A2C3D43B100A50860 /* SteamTimeline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SteamTimeline.swift; sourceTree = "<group>"; };
02BD4F5C2C3D63D700A50860 /* swift_shims.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = swift_shims.h; sourceTree = "<group>"; };
02D309D62722C49B00DE64F0 /* SteamAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SteamAPI.swift; sourceTree = "<group>"; };
02D309DD2722D81E00DE64F0 /* SteamBaseAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SteamBaseAPI.swift; sourceTree = "<group>"; };
02D309E22728111A00DE64F0 /* Lock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Lock.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -761,7 +760,6 @@
OBJ_8 /* CSteamworks */ = {
isa = PBXGroup;
children = (
02BD4F5C2C3D63D700A50860 /* swift_shims.h */,
OBJ_9 /* steamapi_headers.h */,
02AD45712751565E00BD93ED /* steam_missing.h */,
02AD45EF2758F01100BD93ED /* steam_matchmaking_shims.h */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"branch" : "main",
"revision" : "1f2007ef4165432f59f28615c473eb79a844a2af"
"revision" : "9e6597236356dadea31b681cea6a09e8e065fc85"
}
},
{
Expand All @@ -24,8 +24,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76",
"version" : "5.1.2"
"revision" : "3036ba9d69cf1fd04d433527bc339dc0dc75433d",
"version" : "5.1.3"
}
}
],
Expand Down

0 comments on commit 72f3cf6

Please sign in to comment.