Skip to content

Commit

Permalink
Move Xcode CRuby settings into xcconfig (#48)
Browse files Browse the repository at this point in the history
* Move search paths into xcconfig
* Update to CRuby 2.1.0
* Update CI, docs
  • Loading branch information
johnfairh authored Apr 23, 2024
1 parent 53b9f2f commit 782cee1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 46 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
with:
xcode-version: ${{ matrix.xcode }}
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Ruby
run: |
gem install rouge
Expand All @@ -36,10 +38,10 @@ jobs:
cat Packages/CRuby/CRuby.pc
cat Packages/CRuby/Sources/CRuby/module.modulemap
cat Packages/CRuby/Sources/CRuby/ruby_headers.h
- name: Tests
- name: Tests (SPM)
run: |
export PKG_CONFIG_PATH=$(pwd)/Packages/CRuby:$PKG_CONFIG_PATH
swift test --enable-code-coverage -Xcc -fdeclspec
swift test --enable-code-coverage
- name: Coverage generation
run: |
xcrun llvm-cov export -format lcov .build/debug/RubyGatewayPackageTests.xctest/Contents/MacOS/RubyGatewayPackageTests -instr-profile .build/debug/codecov/default.profdata -ignore-filename-regex "(Test|checkouts)" > coverage.lcov
Expand All @@ -48,6 +50,10 @@ jobs:
with:
files: ./coverage.lcov
verbose: true
- name: Tests (Xcodebuild)
run: |
CRuby/cfg-cruby --mode custom --path `ruby -e 'puts RbConfig::TOPDIR'`
xcodebuild test -scheme RubyGateway-Package
linux:
name: ubuntu latest
Expand All @@ -58,13 +64,9 @@ jobs:
rby:
- short: '2.7'
- short: '3.0'
extra_args: '-Xcc -fdeclspec'
- short: '3.1'
extra_args: '-Xcc -fdeclspec'
- short: '3.2'
extra_args: '-Xcc -fdeclspec'
- short: '3.3'
extra_args: '-Xcc -fdeclspec'
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
Expand Down Expand Up @@ -92,4 +94,4 @@ jobs:
run: |
export PKG_CONFIG_PATH=$(pwd)/Packages/CRuby:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=${RB_PREFIX}/lib:$LD_LIBRARY_PATH
swift test ${{ matrix.rby.extra_args }}
swift test
2 changes: 1 addition & 1 deletion CRuby
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
targets: ["RubyGateway", "RubyGatewayHelpers"])
],
dependencies: [
.package(url: "https://github.com/johnfairh/CRuby", from: "2.0.0"),
.package(url: "https://github.com/johnfairh/CRuby", from: "2.1.0"),
],
targets: [
.target(
Expand Down
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,20 @@ log(object2_to_log, priority: 2)

## Requirements

* Swift 5.4 or later, from swift.org or Xcode 12.5+
* macOS (tested on 14.1) or Linux (tested on Ubuntu Bionic/18.04 on x86_64) with Clang 6.
* Swift 5.9 or later, from swift.org or Xcode 15.3+
* macOS (tested on 14.1) 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
is installed.
* RubyGateway requires 'original' MRI/CRuby Ruby - no JRuby/Rubinius/etc.

There's something wrong with the Ruby 3 Xcode project since Ruby 3.2: running
tests in Xcode shows all kinds of weird errors that look like a linking problem
that is not present run normally in SPM.

## Installation

For macOS, if you are happy to use the system Ruby then you just need to include
the RubyGateway framework as a dependency. If you are building on Linux or want
to use a different Ruby then you also need to configure CRuby.

If you are using Ruby 3 then you need to set the `-fdeclspec` Clang flag, either
on the Swift PM command line (`swift build -Xcc -fdeclspec`) or in Xcode's
_Other Swift Flags_ settings.

### Getting the framework

Carthage for macOS:
Expand Down Expand Up @@ -216,7 +208,7 @@ echo "import RubyGateway; print(Ruby.versionDescription)" > Sources/MyProject/ma
swift package update
swift package edit CRuby
Packages/CRuby/cfg-cruby --mode rbenv --name 3.0.0
PKG_CONFIG_PATH=$(pwd)/Packages/CRuby:$PKG_CONFIG_PATH swift run -Xcc -fdeclspec
PKG_CONFIG_PATH=$(pwd)/Packages/CRuby:$PKG_CONFIG_PATH swift run
```

## Contributions
Expand Down
3 changes: 3 additions & 0 deletions RubyGateway.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jump over to CRuby for the actual settings.
// Relative include path means relative to the location of this file.
#include? "CRuby/CRuby.xcconfig"
38 changes: 12 additions & 26 deletions RubyGateway.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
02901339203ED8D60090C5C9 /* RbConversions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RbConversions.swift; sourceTree = "<group>"; };
0290133B203EF0F60090C5C9 /* nonconvert.rb */ = {isa = PBXFileReference; lastKnownFileType = text.script.ruby; path = nonconvert.rb; sourceTree = "<group>"; };
0290133C203F42820090C5C9 /* TestMiscObjTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestMiscObjTypes.swift; sourceTree = "<group>"; };
02A1D66C2BD1173700B07523 /* RubyGateway.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = RubyGateway.xcconfig; sourceTree = "<group>"; };
02ABDBA3216CF7BF00AFDB64 /* RbMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RbMethod.swift; sourceTree = "<group>"; };
02ABDBA5216D060300AFDB64 /* TestMethods.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestMethods.swift; sourceTree = "<group>"; };
02C5C85020ECD87E007138A2 /* RbComplex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RbComplex.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -289,6 +290,7 @@
isa = PBXGroup;
children = (
OBJ_6 /* Package.swift */,
02A1D66C2BD1173700B07523 /* RubyGateway.xcconfig */,
OBJ_7 /* Sources */,
OBJ_12 /* Tests */,
OBJ_16 /* Dependencies */,
Expand Down Expand Up @@ -590,14 +592,12 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"${SRCROOT}/CRuby/Sources/CRuby",
"${SRCROOT}/Sources/RubyGatewayHelpers/include",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0/x86_64-darwin23",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MTL_ENABLE_DEBUG_INFO = YES;
OTHER_CFLAGS = "-fdeclspec";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand Down Expand Up @@ -647,20 +647,19 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"${SRCROOT}/CRuby/Sources/CRuby",
"${SRCROOT}/Sources/RubyGatewayHelpers/include",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0/x86_64-darwin23",
);
MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)";
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CFLAGS = "-fdeclspec";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
OBJ_3 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 02A1D66C2BD1173700B07523 /* RubyGateway.xcconfig */;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand Down Expand Up @@ -721,18 +720,13 @@
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = (
"$(HOME)/.rbenv/versions/3.3.0/include/ruby-3.3.0/x86_64-darwin23",
"$(HOME)/.rbenv/versions/3.3.0/include/ruby-3.3.0",
);
INFOPLIST_FILE = RubyGateway.xcodeproj/RubyGatewayTests_Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"@loader_path/../Frameworks",
"@loader_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(HOME)/.rbenv/versions/3.3.0/lib";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fdeclspec";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_NAME = RubyGatewayTests;
SWIFT_VERSION = 5.0;
TARGET_NAME = RubyGatewayTests;
Expand All @@ -741,6 +735,7 @@
};
OBJ_4 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 02A1D66C2BD1173700B07523 /* RubyGateway.xcconfig */;
buildSettings = {
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ENABLE_OBJC_ARC = YES;
Expand Down Expand Up @@ -799,18 +794,13 @@
"$(inherited)",
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = (
"$(HOME)/.rbenv/versions/3.3.0/include/ruby-3.3.0/x86_64-darwin23",
"$(HOME)/.rbenv/versions/3.3.0/include/ruby-3.3.0",
);
INFOPLIST_FILE = RubyGateway.xcodeproj/RubyGatewayTests_Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"@loader_path/../Frameworks",
"@loader_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(HOME)/.rbenv/versions/3.3.0/lib";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fdeclspec";
OTHER_SWIFT_FLAGS = "$(inherited)";
PRODUCT_NAME = RubyGatewayTests;
SWIFT_VERSION = 5.0;
TARGET_NAME = RubyGatewayTests;
Expand All @@ -830,23 +820,21 @@
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"${SRCROOT}/CRuby/Sources/CRuby",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0/x86_64-darwin23",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0",
);
INFOPLIST_FILE = RubyGateway.xcodeproj/RubyGateway_Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(HOME)/.rbenv/versions/3.3.0/lib";
MACOSX_DEPLOYMENT_TARGET = 11.4;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14";
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fdeclspec -enable-experimental-feature AccessLevelOnImport";
OTHER_SWIFT_FLAGS = "$(inherited) -enable-experimental-feature AccessLevelOnImport";
PRODUCT_BUNDLE_IDENTIFIER = RubyGateway;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand All @@ -871,23 +859,21 @@
"$(PLATFORM_DIR)/Developer/Library/Frameworks",
);
HEADER_SEARCH_PATHS = (
"$(inherited)",
"${SRCROOT}/CRuby/Sources/CRuby",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0/x86_64-darwin23",
"/Users/johnf/.rbenv/versions/3.3.0/include/ruby-3.3.0",
);
INFOPLIST_FILE = RubyGateway.xcodeproj/RubyGateway_Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = "$(HOME)/.rbenv/versions/3.3.0/lib";
MACOSX_DEPLOYMENT_TARGET = 11.4;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++14";
OTHER_CFLAGS = "";
OTHER_LDFLAGS = "$(inherited)";
OTHER_SWIFT_FLAGS = "$(inherited) -Xcc -fdeclspec -enable-experimental-feature AccessLevelOnImport";
OTHER_SWIFT_FLAGS = "$(inherited) -enable-experimental-feature AccessLevelOnImport";
PRODUCT_BUNDLE_IDENTIFIER = RubyGateway;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down

0 comments on commit 782cee1

Please sign in to comment.