Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Jruby support #294

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
steps:
- id: data
run: |
curl -s https://raw.githubusercontent.com/oxidize-rb/rb-sys/$GITHUB_SHA/data/toolchains.json > toolchains.json
curl -s https://raw.githubusercontent.com/uvlad7/rb-sys/$GITHUB_SHA/data/toolchains.json > toolchains.json
echo "minimum-supported-rust-version=$(jq -r '.policy["minimum-supported-rust-version"]' toolchains.json)" >> $GITHUB_OUTPUT
build_and_test:
name: 🧪 Test
Expand All @@ -34,7 +34,18 @@ jobs:
fail-fast: false
matrix:
# Test against all versions supported by rubygems
ruby_version: ["2.4", "2.5", "2.6", "2.7", "3.0", "3.1", "3.2", "head"]
ruby_version:
[
"2.4",
"2.5",
"2.6",
"2.7",
"3.0",
"3.1",
"3.2",
"head",
"jruby-9.4.3.0",
]
sys:
- os: ubuntu-latest
rust_toolchain: ${{ needs.fetch_ci_data.outputs.minimum-supported-rust-version }}
Expand All @@ -44,6 +55,16 @@ jobs:
rust_toolchain: stable
- os: windows-2022
rust_toolchain: stable
exclude:
- ruby_version: "jruby-9.4.3.0"
sys:
os: ubuntu-latest
rust_toolchain: ${{ needs.fetch_ci_data.outputs.minimum-supported-rust-version }}
# Should re-include this after build on windows is fixed
- ruby_version: "jruby-9.4.3.0"
sys:
os: windows-2022
rust_toolchain: stable
include:
- ruby_version: mswin
sys:
Expand All @@ -53,10 +74,26 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Patch examples
shell: bash
run: |
if [[ "${{ startsWith( matrix.ruby_version, 'jruby') }}" == "true" ]]; then
rm -r examples/rust_reverse/
mv examples/rust_reverse_jruby/ examples/rust_reverse/
else
rm -r examples/rust_reverse_jruby/
fi

- name: Setup debug info
shell: bash
run: script/ci/set-debug-env.sh

- uses: actions/setup-java@v4
if: startsWith( matrix.ruby_version, 'jruby')
with:
distribution: "temurin"
java-version: "17"

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
if: matrix.ruby_version != 'skip'
with:
Expand Down Expand Up @@ -87,6 +124,7 @@ jobs:
run: script/ci/upload-on-failure.sh "bundle exec rake test:examples" "examples-test" "./examples"

- name: 🧪 Cargo test
if: startsWith( matrix.ruby_version, 'jruby') != true
shell: bash
run: bundle exec rake test:cargo

Expand All @@ -107,6 +145,7 @@ jobs:
popd

- name: ✂️ Run clippy
if: startsWith( matrix.ruby_version, 'jruby') != true
run: cargo clippy

- name: 📃 Run cargo fmt
Expand All @@ -118,7 +157,7 @@ jobs:
run: bundle exec standardrb --format github

- name: "🧱 Generate bindings"
if: env.ACTIONS_STEP_DEBUG == 'true'
if: env.ACTIONS_STEP_DEBUG == 'true' && startsWith( matrix.ruby_version, 'jruby') != true
run: bundle exec rake bindings:generate

- uses: actions/upload-artifact@v3
Expand All @@ -144,6 +183,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Patch examples
shell: bash
run: |
rm -r examples/rust_reverse_jruby/

- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
with:
ruby-version: none
Expand Down
33 changes: 32 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
repo:
- name: "oxidize-rb/oxi-test"
- name: "uvlad7/oxi-test"
slug: oxi-test
ref: main
run: rake
Expand All @@ -32,6 +32,23 @@ jobs:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
rust: ["stable"]
ruby: ["2.7", "3.2", "ruby-head"]
include:
- repo:
name: "uvlad7/oxi-test"
slug: oxi-test
ref: main
run: rake
os: "ubuntu-latest"
rust: "stable"
ruby: jruby-9.4.3.0
- repo:
name: "uvlad7/oxi-test"
slug: oxi-test
ref: main
run: rake
os: "macos-latest"
rust: "stable"
ruby: jruby-9.4.3.0
# Should re-include these after unstable-api is enabled
exclude:
- os: windows-latest
Expand All @@ -48,6 +65,15 @@ jobs:
slug: magnus-0.5
ref: "0.5.4"
run: cargo test
# Should re-include this after build on windows is fixed
- repo:
name: "uvlad7/oxi-test"
slug: oxi-test
ref: main
run: rake
os: "windows-latest"
rust: "stable"
ruby: jruby-9.4.3.0

runs-on: ${{ matrix.os }}
steps:
Expand All @@ -65,6 +91,11 @@ jobs:
- uses: actions/checkout@v4
with:
path: rb-sys
- uses: actions/setup-java@v4
if: startsWith( matrix.ruby, 'jruby')
with:
distribution: "temurin"
java-version: "17"
- uses: oxidize-rb/actions/setup-ruby-and-rust@v1
id: setup
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ Gemfile.lock
tmp/
gem/docs
.yardoc/
.rtx.toml
*.iml
.idea/
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
]
exclude = [
"examples/rust_reverse/ext/rust_reverse",
"examples/rust_reverse_jruby/ext/rust_reverse",
"crates/rb-sys-test-helpers-macros-impl",
"./fuzz",
"./bench",
Expand Down
14 changes: 14 additions & 0 deletions examples/rust_reverse_jruby/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.jar
*.o
*.a
mkmf.log
60 changes: 60 additions & 0 deletions examples/rust_reverse_jruby/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: true

require "rake/testtask"
require_relative "rake_ext"
require "rake/javaextensiontask"
require "rake/extensiontask"

SOURCE_PATTERN = "*.{rs,toml,lock,rb}"

Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/test_*.rb"]
end

Rake::JavaExtensionTask.new("rust_reverse") do |ext|
ext.lib_dir = "lib/rust_reverse"
ext.ext_dir = "ext"
ext.source_version = "11"
ext.target_version = "11"
end

Rake::Task[:compile].rename(:java_compile)

Rake::ExtensionTask.new("rust_reverse") do |ext|
ext.lib_dir = "lib/rust_reverse"
ext.source_pattern = SOURCE_PATTERN
ext.cross_compile = true
ext.cross_platform = %w[x86-mingw32 x64-mingw-ucrt x64-mingw32 x86-linux x86_64-linux x86_64-darwin arm64-darwin aarch64-linux]
ext.config_script = ENV["ALTERNATE_CONFIG_SCRIPT"] || "extconf.rb"
end

task compile: :java_compile

task :build do
require "bundler"

spec = Bundler.load_gemspec("rust_reverse.gemspec")

FileUtils.rm_rf("pkg/rust_reverse")

spec.files.each do |file|
FileUtils.mkdir_p("pkg/rust_reverse/#{File.dirname(file)}")
FileUtils.cp(file, "pkg/rust_reverse/#{file}")
end

FileUtils.cp("rust_reverse.gemspec", "pkg/rust_reverse")

full_path = File.expand_path("./../../../crates/rb-sys", __FILE__)
cargo_toml_path = "pkg/rust_reverse/ext/rust_reverse/Cargo.toml"
new_contents = File.read(cargo_toml_path).gsub("./../../../../crates/rb-sys", full_path)
FileUtils.rm(cargo_toml_path)
File.write(cargo_toml_path, new_contents)

Dir.chdir("pkg/rust_reverse") do
sh "gem build rust_reverse.gemspec --output=../rust_reverse.gem"
end
end

task default: %i[compile test]
1 change: 1 addition & 0 deletions examples/rust_reverse_jruby/ext/rust_reverse/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
Loading