Can't setup Custom Ruby when writing a mac App.
I'm writing a macOS App, not a executable swift package. Is there a way to use custom Ruby rather than the system one.
You mean using Xcode -> Create Project? It should be doable - probably need to clone a separate copy of CRuby and configure that to point to whatever version of Ruby you want to us, then persuade Xcode to use that somehow -- at worst you'll need to clone RubyGateway (a la Carthage...) if Xcode won't do the right thing with the package dependencies.
I'm working with a xcodeproj. And I write a custom Package inside the project.
I can add RubyGateway into the Package.swift to use system ruby.
But any other way can't build.
I tried clone CRuby, and add it to the Package.swift. But after I run cfg-cruby, it can't build.
You'll probably need to ask for some Xcode help on how to best route the flags through - not something I know much about.
You'll probably need to ask for some Xcode help on how to best route the flags through - not something I know much about.
Is there a way to write the path of ruby inside CRuby?
The 'path of Ruby' is set by the -I & -L C compiler flags so that when the CRuby module does its #include <ruby.h> it gets the right thing. The CRuby package setup (cfg_cruby) is supposed to generate the right values for those flags so the build system sets them before / as part of importing the CRuby module.
For SwiftPM, this happens via the pkgconfig thing - the CRuby Package.swift refs that file, which includes the -I and -L values, that the build system sets so the import works.
After I setup cfg_cruby, it wouldn't build. Could not find <ruby.h>. And there is a warning tha can't find the pc file.
You need to help Xcode find the pc file -- I don't know how that works; could maybe use the PKG_CONFIG_PATH env var in xcconfig?
Or... try adding the xcconfig that cfg_cruby generated into the project - should have the -I and -L settings in it?
Did you get anywhere with this? I had a play today; it does look like an Xcode problem, that Xcode is not dealing properly with the pkgConfig setting in Package.swift.
macOS 15.3, Intel, Xcode 16.2.
Create new project "mac App", add RubyGateway as dependency, update default ContentView to Text("Hello, world from Ruby \(Ruby.version)!"). Preview works, shows system Ruby 2.6.10. OK.
Use apple instructions to create local copy of CRuby that I guess is their version of swift package edit. Xcode is happy, acknowledges local dependency:
Configure Ruby, ./cfg-cruby --mode rbenv --name 3.4.1. Everything breaks:
This is expected because we have not told Xcode where to find the files - but it does prove Xcode is using the right copy of
CRuby. Suspiciously there is no mention of a missing pkgconfig file.
And... I can't get past this. I tried:
- Put
CRuby.pcinto/usr/local/lib- no change. Who knows where Xcode is searching for it. - Add the CRuby-generated
CRuby.xcconfiginto the project. Nothing. 2a) Add aPKG_CONFIG_PATHinto that xcconfig. Nothing. - Manually add the correct
HEADER_SEARCH_PATHSin Project -> Build Settings. Still fails in the same way; these must be ignored for 'dependencies'.
I think a workaround would be to clone the entire RubyGateway project and create your App target in there -- then there are no dependencies to confuse Xcode. I had a quick go at this but the build failed with a "Type 'bundle' has no member 'module'" error before I could really start customising anything...