Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for Xcode 15.3 #8

Merged
merged 6 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ on:
jobs:
macos:
name: macOS SPM unit tests
runs-on: macos-13
env:
DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer
runs-on: macos-14
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 15.3
- name: Set up SDK
run: cd sdk && make install
run: cd sdk && sudo make install
- name: Run tests
run: swift test

macos_raw:
name: macOS raw build
runs-on: macos-13
env:
DEVELOPER_DIR: /Applications/Xcode_15.0.app/Contents/Developer
runs-on: macos-14
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: 15.3
- name: Raw build
run: swift build

Expand All @@ -38,12 +40,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- name: Give up and run in docker
run: 'docker run -v `pwd`:`pwd` -w `pwd` --name steamworks --rm swiftlang/swift:nightly-5.9-focal /bin/bash -c "apt-get update; apt-get install make; (cd sdk && make install); swift test -Xswiftc -cxx-interoperability-mode=default"'
# - name: Set up SDK
#run: cd sdk && sudo make install
#- name: Run tests
#run: swift test -Xswiftc -cxx-interoperability-mode=default
- name: Set up SDK
run: cd sdk && sudo make install
- name: Run tests
run: swift test -Xswiftc -cxx-interoperability-mode=default
5 changes: 5 additions & 0 deletions DocIndex/jazzy-custom-groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@
- SteamAPICall
- SteamAPIWarningMessageHook
- SteamErrMsg
- SteamUnsafeMutablePointer
- SteamUnsafeMutableRawPointer
- SteamUnsafeRawPointer
- name: Enumerations and Option Sets
children:
- AccountType
Expand All @@ -676,6 +679,7 @@
- PlayerResult
- Result
- ServerMode
- SteamAPIInitResult
- SteamIPType
- SteamIPv6ConnectivityProtocol
- SteamIPv6ConnectivityState
Expand All @@ -687,6 +691,7 @@
- GameID
- SteamID
- SteamIPAddress
- SteamUncheckedSendable
- name: Constants
topics:
- name: Constants
Expand Down
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 swiftlang/swift:nightly-5.9-focal /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:5.10 /bin/bash -c "apt-get update; apt-get install make; (cd sdk && make install); swift test -Xswiftc -cxx-interoperability-mode=default"

shell_linux:
docker run -it -v `pwd`:`pwd` -w `pwd` --name steamworks --rm swiftlang/swift:nightly-5.9-focal /bin/bash
docker run -it -v `pwd`:`pwd` -w `pwd` --name steamworks --rm swift:5.10 /bin/bash
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
"identity" : "yams",
"kind" : "remoteSourceControl",
"location" : "https://github.com/jpsim/Yams.git",
"state" : {
"revision" : "0d9ee7ea8c4ebd4a489ad7a73d5c6cad55d6fed3",
"version" : "5.0.6"
"revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76",
"version" : "5.1.2"
}
}
],
Expand Down
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ import PackageDescription
// so that Xcode in SPM mode can depend on Steamworks.

var steamworksSwiftFlags: [SwiftSetting] = [
.interoperabilityMode(.Cxx)
.interoperabilityMode(.Cxx),
.enableExperimentalFeature("AccessLevelOnImport"),
.enableExperimentalFeature("StrictConcurrency")
]

let pkgConfigSetting = "steamworks-swift"
Expand Down Expand Up @@ -100,7 +102,7 @@ if !hasPkgConfig {
let package = Package(
name: "steamworks-swift",
platforms: [
.macOS("13.0"),
.macOS("14.0"),
],
products: [
.library(
Expand Down
31 changes: 29 additions & 2 deletions Sources/LibGenerate/DocStructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ struct DocStructure {
/// Common Types is a special catch-all
static let commonTypesHeader = "steamclientpublic.h"

/// A fabricated header that we use to hold common types purely created by Steamworks-swift
static let fakeCommonTypesHeader = "fakecommon.h"

/// 'Primary' headers each generate a section in the docs.
/// 'Secondary' headers' contents are merged over into their primaries.
static let secondaryHeaderMap = [
Expand All @@ -123,7 +126,10 @@ struct DocStructure {
"isteamhttp.h" : ["steamhttpenums.h"],
"isteamnetworkingutils.h" : ["steamnetworkingtypes.h"], /* bit arbitrary */
"isteamnetworkingsockets.h" : ["steamnetworkingfakeip.h"],
commonTypesHeader : ["steamtypes.h", "steamuniverse.h", "steam_api_common.h", "steam_gameserver.h"]
commonTypesHeader : [
"steamtypes.h", "steamuniverse.h", "steam_api_common.h",
"steam_gameserver.h", "steam_api.h", fakeCommonTypesHeader
]
]

static let secondaryHeaders = Set(secondaryHeaderMap.values.joined())
Expand All @@ -148,8 +154,29 @@ struct DocStructure {
filename == Self.commonTypesHeader
}

/// List of SwiftType type names found per header file
typealias SwiftTypeSets = [String : Set<SwiftType>]

/// Types that need to go into the common types docs that are not found from the Steam headers
static let fakeCommonTypes: [(String, Generated.Kind)] = [
("SteamUncheckedSendable", .struct),
("SteamUnsafeRawPointer", .typedef),
("SteamUnsafeMutablePointer", .typedef),
("SteamUnsafeMutableRawPointer", .typedef)
]

func addFakeCommonTypes(types: SwiftTypeSets) -> SwiftTypeSets {
var fakeTypes: Set<SwiftType> = []
for (name, kind) in Self.fakeCommonTypes {
let swiftType = SwiftType(name)
fakeTypes.insert(swiftType)
generated.add(type: swiftType, kind: kind)
}
var types = types
types[Self.fakeCommonTypesHeader] = fakeTypes
return types
}

/// Generate ToC / Index for jazzy/bebop/j2 and docc structured 'semantically',
/// that is by steam interface. Broadly use the SDK header files to figure out
/// which enums/structs etc. are associated with which interfaces, but a fair bit
Expand Down Expand Up @@ -235,7 +262,7 @@ struct DocStructure {

/// Add the secondary files' types into their primary files' sets, remove the secondaries from the list
private func mergeSecondaryHeaders(types: SwiftTypeSets) -> SwiftTypeSets {
var result = types
var result = addFakeCommonTypes(types: types)
for (prim, secs) in Self.secondaryHeaderMap {
for sec in secs {
guard let secTypes = result.removeValue(forKey: sec) else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/LibGenerate/Generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class Generated {

/// Steamworks types that are implemented manually instead of being generated.
/// They should appear in doc sections driven by the header files.
private static var manualTypes: [(String, Kind)] = [
private static let manualTypes: [(String, Kind)] = [
("SteamID", .struct),
("GameID", .struct),
("SteamIPAddress", .struct),
Expand Down
4 changes: 2 additions & 2 deletions Sources/LibGenerate/IO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class IO {
final class IO: Sendable {
let redistSdkURL: URL
let swiftOutputDirURL: URL
let cOutputDirURL: URL
Expand Down Expand Up @@ -135,7 +135,7 @@ final class IO {
//
\(fileHeaderLicense)

@_implementationOnly import CSteamworks
internal import CSteamworks
"""
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/LibGenerate/Interfaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ extension MetadataDB.Interface.Access {

switch self {
case .instance:
let sendableSwiftType = "Steam\(swiftType)"
decl = """
private let interface: \(swiftType)
private let _interface: \(sendableSwiftType)
private var interface: \(swiftType) {
_interface.base
}
init(_ interface: \(swiftType)) {
self.interface = interface
self._interface = .init(interface)
}
"""
case .user(let accessor), .gameserver(let accessor), .global(let accessor):
Expand Down
8 changes: 4 additions & 4 deletions Sources/LibGenerate/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ struct Patch: Codable {
/// Also fast lookups and central access for weird special cases of knowledge needs
/// (like 'is this random string an enum?')
///
struct MetadataDB {
struct MetadataDB: Sendable {
struct Const {
let name: SteamHungarianName
let type: SteamType
Expand All @@ -213,7 +213,7 @@ struct MetadataDB {
/// Indexed by `constname`, filtered by patch exclude-list
let consts: [SteamHungarianName : Const]

final class Enum {
final class Enum: Sendable {
let name: SteamType
let setPassedInTypeName: SwiftNativeType?
var isSet: Bool { setPassedInTypeName != nil }
Expand Down Expand Up @@ -491,7 +491,7 @@ struct MetadataDB {
/// Sharable reference wrapper around the API metadata
///
/// The API available here is the patched version.
final class Metadata: CustomStringConvertible {
final class Metadata: CustomStringConvertible, Sendable {
let io: IO
let db: MetadataDB

Expand Down Expand Up @@ -560,7 +560,7 @@ final class Metadata: CustomStringConvertible {
"""
}

static private(set) var shared: Metadata?
nonisolated(unsafe) static private(set) var shared: Metadata?

var allEnums: [MetadataDB.Enum] {
Array(db.enums.values) + Array(nestedEnums.values)
Expand Down
2 changes: 2 additions & 0 deletions Sources/LibGenerate/Resources/steam_api_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ enums:
ESteamNetworkingSendFlags:
is_set: Int32
prefix: nSteamNetworkingSend
ETimelineGameMode:
ignore: "In metadata but not header"
EUGCContentDescriptorID:
prefix: EUGCContentDescriptor
EUGCReadAction:
Expand Down
14 changes: 13 additions & 1 deletion Sources/LibGenerate/SteamSwiftTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// A C++ type used in the native Steam API. Would be understood by the C++ compiler.
///
/// Eg. a straight type name `SteamFoo_t` or a parameter type eg. `const SteamFoo_t *`.
struct SteamType: StringFungible {
struct SteamType: StringFungible, Sendable {
let name: String

init(_ name: String) {
Expand Down Expand Up @@ -78,6 +78,14 @@ extension SteamType {
return SwiftType(name1.replacingOccurrences(of: "_", with: ""))
}

var sendableSwiftType: SwiftType {
let base = swiftType
if base.isSendable {
return base
}
return SwiftType("Steam\(base.name)")
}

/// Does this C++ type look like a pointer but is actually something else?
/// Mostly for `const char *` -> `String`
fileprivate var isPointerTypePassedByValue: Bool {
Expand Down Expand Up @@ -409,6 +417,10 @@ extension SwiftTypeUtils {
var isOptional: Bool {
name.hasSuffix("?")
}

var isSendable: Bool {
!name.re_isMatch("^Unsafe.*Pointer$")
}
}

// MARK: SwiftExpr
Expand Down
4 changes: 2 additions & 2 deletions Sources/LibGenerate/Structs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension MetadataDB.Struct.Field {
/// Swift structure declaration field
var declLine: [String] {[
"/// Steamworks `\(name)`",
"public let \(name.swiftName): \(type.swiftType)"
"public let \(name.swiftName): \(type.sendableSwiftType)"
]}

/// Swift structure initializer lines
Expand Down Expand Up @@ -130,7 +130,7 @@ extension MetadataDB.Struct.Field {
/// Default value setup for memberwise initializer
var memberwiseParameter: String {
let initClause = type.swiftTypeInstance.flatMap { " = \($0)"} ?? ""
return "\(name.swiftName): \(type.swiftType)\(initClause)"
return "\(name.swiftName): \(type.sendableSwiftType)\(initClause)"
}

/// Initializer line for memberwise initializer
Expand Down
24 changes: 20 additions & 4 deletions Sources/LibGenerate/Typedefs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,28 @@ extension MetadataDB.Typedef {
var decl = """
/// Steamworks `\(typedef)`
public struct \(swiftType): Hashable, Sendable {
public let value: \(swiftNativeType)
public init(_ value: \(swiftNativeType)) { self.value = value }
}

extension \(swiftType): SteamTypeAlias, SteamCreatable {}
"""
if swiftNativeType.isSendable {
decl += """
public let value: \(swiftNativeType)
public init(_ value: \(swiftNativeType)) { self.value = value }
}
"""
} else {
decl += """
private let _value: Steam\(swiftNativeType)
public var value: \(swiftNativeType) { _value.base }
public init(_ value: \(swiftNativeType)) { self._value = .init(value) }
}
"""
}
decl += """


extension \(swiftType): SteamTypeAlias, SteamCreatable {}
"""

if swiftNativeType.isInteger {
decl += """

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
- ``SteamAPICall``
- ``SteamAPIWarningMessageHook``
- ``SteamErrMsg``
- ``SteamUnsafeMutablePointer``
- ``SteamUnsafeMutableRawPointer``
- ``SteamUnsafeRawPointer``

### Enumerations and Option Sets
- ``AccountType``
Expand All @@ -33,6 +36,7 @@
- ``PlayerResult``
- ``Result``
- ``ServerMode``
- ``SteamAPIInitResult``
- ``SteamIPType``
- ``SteamIPv6ConnectivityProtocol``
- ``SteamIPv6ConnectivityState``
Expand All @@ -44,3 +48,4 @@
- ``GameID``
- ``SteamID``
- ``SteamIPAddress``
- ``SteamUncheckedSendable``
Loading