diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2ace2f0..1575345 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,6 +52,10 @@ jobs: files: ./coverage.lcov token: ${{ secrets.CODECOV_TOKEN }} verbose: true + - name: Samples + run: | + export PKG_CONFIG_PATH=$(pwd)/Packages/CRuby:$PKG_CONFIG_PATH + swift run RubyThreadSample - name: Tests (Xcodebuild) run: | CRuby/cfg-cruby --mode custom --path `ruby -e 'puts RbConfig::TOPDIR'` diff --git a/Package.swift b/Package.swift index 078a21d..842c5de 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,10 @@ let package = Package( products: [ .library( name: "RubyGateway", - targets: ["RubyGateway", "RubyGatewayHelpers"]) + targets: ["RubyGateway", "RubyGatewayHelpers"]), + .executable( + name: "RubyThreadSample", + targets: ["RubyThreadSample"]) ], dependencies: [ .package(url: "https://github.com/johnfairh/CRuby", from: "2.1.0"), @@ -32,6 +35,9 @@ let package = Package( .testTarget( name: "RubyGatewayTests", dependencies: ["RubyGateway"], - exclude: ["Fixtures"]) + exclude: ["Fixtures"]), + .executableTarget( + name: "RubyThreadSample", + dependencies: ["RubyGateway"]) ] ) diff --git a/README.md b/README.md index 8f1351d..fb181b3 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ print(html) // Create an object. Use keyword arguments with initializer let student = RbObject(ofClass: "Academy::Student", kwArgs: ["name": "barney"])! -// Acess an attribute +// Access an attribute print("Name is \(student.get("name"))") // Fix their name by poking an ivar @@ -158,7 +158,7 @@ log(object2_to_log, priority: 2) ## Requirements * Swift 6.0 or later, from swift.org or Xcode 16+ -* macOS (tested on 14.1) or Linux (tested on Ubuntu Jammy) +* macOS (tested on 15.3) or Linux (tested on Ubuntu Jammy) * Ruby 2.6 or later including development files: * For macOS, these come with Xcode. * For Linux you may need to install a -dev package depending on how your Ruby diff --git a/RubyGateway.xcodeproj/project.pbxproj b/RubyGateway.xcodeproj/project.pbxproj index bbe3fe5..6a0e10b 100644 --- a/RubyGateway.xcodeproj/project.pbxproj +++ b/RubyGateway.xcodeproj/project.pbxproj @@ -146,6 +146,8 @@ 02A1D66C2BD1173700B07523 /* RubyGateway.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = RubyGateway.xcconfig; sourceTree = ""; }; 02ABDBA3216CF7BF00AFDB64 /* RbMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RbMethod.swift; sourceTree = ""; }; 02ABDBA5216D060300AFDB64 /* TestMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestMethods.swift; sourceTree = ""; }; + 02C143F52D5A0415009C99CF /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 02C143F62D5A0415009C99CF /* RubyExecutor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RubyExecutor.swift; sourceTree = ""; }; 02C5C85020ECD87E007138A2 /* RbComplex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RbComplex.swift; sourceTree = ""; }; 02C5C85220ECE51A007138A2 /* TestComplex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestComplex.swift; sourceTree = ""; }; 02C5C85420F0CD24007138A2 /* RbRational.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RbRational.swift; sourceTree = ""; }; @@ -225,6 +227,16 @@ path = Tests/RubyGatewayTests/Fixtures; sourceTree = SOURCE_ROOT; }; + 02C143F42D5A03C4009C99CF /* RubyThreadSample */ = { + isa = PBXGroup; + children = ( + 02C143F52D5A0415009C99CF /* main.swift */, + 02C143F62D5A0415009C99CF /* RubyExecutor.swift */, + ); + name = RubyThreadSample; + path = Sources/RubyThreadSample; + sourceTree = SOURCE_ROOT; + }; OBJ_12 /* Tests */ = { isa = PBXGroup; children = ( @@ -304,6 +316,7 @@ children = ( OBJ_8 /* RubyGateway */, 022F3ABC2036D58C009E69BE /* RubyGatewayHelpers */, + 02C143F42D5A03C4009C99CF /* RubyThreadSample */, ); name = Sources; sourceTree = SOURCE_ROOT; @@ -419,7 +432,7 @@ isa = PBXProject; attributes = { BuildIndependentTargetsInParallel = YES; - LastUpgradeCheck = 1600; + LastUpgradeCheck = 1620; TargetAttributes = { 022F3AB62036D4DD009E69BE = { CreatedOnToolsVersion = 9.2; diff --git a/RubyGateway.xcodeproj/xcshareddata/xcschemes/RubyGateway-Package.xcscheme b/RubyGateway.xcodeproj/xcshareddata/xcschemes/RubyGateway-Package.xcscheme index 482c8ef..87a0458 100644 --- a/RubyGateway.xcodeproj/xcshareddata/xcschemes/RubyGateway-Package.xcscheme +++ b/RubyGateway.xcodeproj/xcshareddata/xcschemes/RubyGateway-Package.xcscheme @@ -1,6 +1,6 @@ String { + let ver = Ruby.version + let result = try Ruby.eval(ruby: "Kernel.rand") + return "Ruby (\(ver)) random: \(result)" + } +} + +@MainActor +@available(macOS 14, *) +func doRubyWork() async { + do { + let executor = RubyExecutor() + let actor = RubyActor(executor: executor) + let result = try await actor.rand() + print(result) + // This is optional - fine to just let the process exit. + executor.stop() + } catch { + print("error: \(error)") + } +} + +if #available(macOS 14, *) { + await doRubyWork() +}