Skip to content

Commit

Permalink
Updates for Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfairh committed Jun 26, 2024
1 parent 0cdd51c commit 81c325d
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
xcode: ['15.3']
xcode: ['16.0-beta']
steps:
- uses: maxim-lobanov/setup-xcode@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ log(object2_to_log, priority: 2)

## Documentation

* [User guide](https://johnfairh.github.io/RubyGateway/user-guide.html)
* [User guide](https://johnfairh.github.io/RubyGateway/guides/user-guide.html)
* [API documentation](https://johnfairh.github.io/RubyGateway)
* [Docset for Dash](https://johnfairh.github.io/RubyGateway/docsets/RubyGateway.tgz)

Expand Down
24 changes: 17 additions & 7 deletions RubyGateway.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastUpgradeCheck = 1530;
LastUpgradeCheck = 1600;
TargetAttributes = {
022F3AB62036D4DD009E69BE = {
CreatedOnToolsVersion = 9.2;
Expand Down Expand Up @@ -707,19 +707,24 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
USE_HEADERMAP = NO;
};
name = Debug;
};
OBJ_39 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
DEAD_CODE_STRIPPING = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = (
"${inherited}",
"${SRCROOT}/CRuby/Sources/CRuby",
"${SRCROOT}/Sources/RubyGatewayHelpers/include",
);
INFOPLIST_FILE = RubyGateway.xcodeproj/RubyGatewayTests_Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"@loader_path/../Frameworks",
Expand All @@ -728,7 +733,7 @@
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_NAME = RubyGatewayTests;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGET_NAME = RubyGatewayTests;
};
name = Debug;
Expand Down Expand Up @@ -781,19 +786,24 @@
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
SWIFT_VERSION = 6.0;
USE_HEADERMAP = NO;
};
name = Release;
};
OBJ_40 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
DEAD_CODE_STRIPPING = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = (
"${inherited}",
"${SRCROOT}/CRuby/Sources/CRuby",
"${SRCROOT}/Sources/RubyGatewayHelpers/include",
);
INFOPLIST_FILE = RubyGateway.xcodeproj/RubyGatewayTests_Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"@loader_path/../Frameworks",
Expand All @@ -802,7 +812,7 @@
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_NAME = RubyGatewayTests;
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGET_NAME = RubyGatewayTests;
};
name = Release;
Expand Down Expand Up @@ -841,7 +851,7 @@
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/CRuby/Sources/CRuby ${SRCROOT}/Sources/RubyGatewayHelpers";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGET_NAME = RubyGateway;
};
name = Debug;
Expand Down Expand Up @@ -879,7 +889,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_INCLUDE_PATHS = "${SRCROOT}/CRuby/Sources/CRuby ${SRCROOT}/Sources/RubyGatewayHelpers";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 6.0;
TARGET_NAME = RubyGateway;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1530"
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
9 changes: 7 additions & 2 deletions Sources/RubyGateway/RbBlockCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,13 @@ private func rbproc_value_block_callback(context: VALUE,
internal enum RbBlock {
/// One-time init to register the callbacks
private static let initOnce: Void = {
rbg_register_pvoid_block_proc_callback(rbproc_pvoid_block_callback)
rbg_register_value_block_proc_callback(rbproc_value_block_callback)
// Swift 6 breakage, 'func's apparently don't work for C functions
rbg_register_pvoid_block_proc_callback { a, b, c, d, e in
rbproc_pvoid_block_callback(rawContext: a, argc: b, argv: c, blockArg: d, returnValue: e)
}
rbg_register_value_block_proc_callback { a, b, c, d, e in
rbproc_value_block_callback(context: a, argc: b, argv: c, blockArg: d, returnValue: e)
}
}()

/// Call a method on an object passing a Swift closure as its block
Expand Down
6 changes: 5 additions & 1 deletion Sources/RubyGateway/RbClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ internal enum RbClassBinding {

/// One-time init to register the callbacks
private static let initOnce: Void = {
rbg_register_object_binding_callbacks(rbbinding_alloc, rbbinding_free)
// Swift 6 breakage :(
rbg_register_object_binding_callbacks(
{ rbbinding_alloc(className: $0) },
{ rbbinding_free(className: $0, instance: $1) }
)
}()

private static let bindings = LockedDictionary<String, any RbBoundClassProtocol>()
Expand Down
5 changes: 3 additions & 2 deletions Sources/RubyGateway/RbGlobalVar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ private enum RbGlobalVar {

/// One-time init to register the callbacks
private static let initOnce: Void = {
rbg_register_gvar_callbacks(rbobject_gvar_get_callback,
rbobject_gvar_set_callback)
// Swift 6 breakage
rbg_register_gvar_callbacks( { rbobject_gvar_get_callback(id: $0) },
{ rbobject_gvar_set_callback(id: $0, newValue: $1, returnValue: $2) })
}()

/// Callbacks + store - type-erased at this point
Expand Down
5 changes: 4 additions & 1 deletion Sources/RubyGateway/RbMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ private struct RbMethodExec {
private struct RbMethodDispatch {
/// One-time init to register the callbacks
private static let initOnce: Void = {
rbg_register_method_callback(rbmethod_callback)
// Swift 6 breakage
rbg_register_method_callback {
rbmethod_callback(symbol: $0, targetCount: $1, rawTargets: $2, rubySelf: $3, argc: $4, argv: $5, returnValue: $6)
}
}()

/// List of all method callbacks
Expand Down
16 changes: 11 additions & 5 deletions Sources/RubyGateway/RbThread.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public enum RbThread {
withoutActuallyEscaping(callback) { escapingCallback in
let context = RbThreadContext(escapingCallback)
context.withRaw { rawContext in
rb_thread_call_without_gvl(rbthread_callback, rawContext, nil, nil)
// Swift 6
rb_thread_call_without_gvl( { rbthread_callback(rawContext: $0) }, rawContext, nil, nil)
}
}
}
Expand Down Expand Up @@ -126,12 +127,16 @@ public enum RbThread {
withoutActuallyEscaping(ubfFunc) { escapingUbfFunc in
let ubfContext = RbThreadContext(escapingUbfFunc)
ubfContext.withRaw { rawUbfContext in
rb_thread_call_without_gvl(rbthread_callback, rawContext,
rbthread_ubf_callback, rawUbfContext)
// Swift 6
rb_thread_call_without_gvl( { rbthread_callback(rawContext: $0) },
rawContext,
{ rbthread_ubf_callback(rawContext: $0) },
rawUbfContext)
}
}
case .io:
rb_thread_call_without_gvl(rbthread_callback, rawContext, rbg_RUBY_UBF_IO(), nil)
// Swift 6
rb_thread_call_without_gvl( { rbthread_callback(rawContext: $0) }, rawContext, rbg_RUBY_UBF_IO(), nil)
}
}
}
Expand All @@ -146,7 +151,8 @@ public enum RbThread {
withoutActuallyEscaping(callback) { escapingCallback in
let context = RbThreadContext(escapingCallback)
context.withRaw { rawContext in
rb_thread_call_with_gvl(rbthread_callback, rawContext)
// Swift 6
rb_thread_call_with_gvl( { rbthread_callback(rawContext: $0) }, rawContext)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/RubyGatewayTests/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct Helpers {

/// Ruby files etc.
private static let fixturesDir: String = {
URL(fileURLWithPath: #file).deletingLastPathComponent().path + "/Fixtures"
URL(fileURLWithPath: #filePath).deletingLastPathComponent().path + "/Fixtures"
}()

/// Get full path to fixture with name
Expand Down
2 changes: 1 addition & 1 deletion Tests/RubyGatewayTests/TestClassDef.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class TestClassDef: XCTestCase {
}
}

class InvaderModel {
class InvaderModel: @unchecked Sendable {
private var name = ""

init() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/RubyGatewayTests/TestDemo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestDemo: XCTestCase {
doErrorFree {
try Ruby.require(filename: "rouge")
// Careful to avoid String methods that are unimplemented on Linux....
let swiftText = try String(contentsOfFile: URL(fileURLWithPath: #file).path, encoding: .utf8)
let swiftText = try String(contentsOfFile: URL(fileURLWithPath: #filePath).path, encoding: .utf8)

let html = try Ruby.get("Rouge").call("highlight", args: [swiftText, "swift", "html"])

Expand Down

0 comments on commit 81c325d

Please sign in to comment.