Skip to content

Instantly share code, notes, and snippets.

@camertron
Created September 18, 2021 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camertron/a753e12d2acb29039725cf7c3a180194 to your computer and use it in GitHub Desktop.
Save camertron/a753e12d2acb29039725cf7c3a180194 to your computer and use it in GitHub Desktop.
Compile ruby for iPhone SDK
#!/bin/bash
# First, install Xcode and accompanying command-line tools
wget https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.2.tar.gz
tar -zxvf ruby-3.0.2.tar.gz
cd ruby-3.0.2
./configure --prefix=/tmp \
--build=x86_64-apple-darwin20 \
--target=aarch64-apple-darwin20 \
--with-gmp=/usr/local/opt/gmp \
--with-mpfr=/usr/local/opt/mpfr \
--with-mpc=/usr/local/opt/libmpc \
--with-isl=/usr/local/opt/isl \
--with-native-system-header-dir=/usr/include \
--with-sysroot=$(xcrun --sdk iphoneos --show-sdk-path) \
AS_FOR_TARGET=/usr/bin/as LD_FOR_TARGET=/usr/bin/ld \
NM_FOR_TARGET=/usr/bin/nm RANLIB_FOR_TARGET=/usr/bin/ranlib \
AR_FOR_TARGET=/usr/bin/ar LIPO_FOR_TARGET=/usr/bin/lipo \
--disable-multilib
# makes a fat binary that supports all the given archs
make CC="$(xcrun --sdk iphoneos --find clang) -fdeclspec -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -arch armv7 -arch armv7s -arch arm64"
# ruby and headers, etc will be placed in the /tmp directory
make install
# Sources:
# https://www.ruby-lang.org/en/documentation/installation/#building-from-source
# https://github.com/iains/gcc-darwin-arm64/issues/34
# https://coderwall.com/p/heonhw/compiling-for-ios-outside-of-xcode-with-xcrun
# Can we package ruby as an iOS Framework and/or Swift package?
# https://github.com/carsonmcdonald/ios-ruby-embedded (check out the Rakefile)
# https://www.raywenderlich.com/17753301-creating-a-framework-for-ios
# https://forums.swift.org/t/packaging-static-library-in-spm-package-for-ios-executable/41245/5
# https://developer.apple.com/documentation/swift_packages/distributing_binary_frameworks_as_swift_packages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment