Skip to content
Draft
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
11 changes: 7 additions & 4 deletions .github/workflows/release_ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ jobs:
- os: ubuntu-24.04-arm
platform: aarch64-linux
rust_target: aarch64-unknown-linux-gnu
- os: macos-14
platform: arm64-darwin23
rust_target: aarch64-apple-darwin
- os: macos-15
platform: arm64-darwin24
rust_target: aarch64-apple-darwin
Expand All @@ -109,14 +112,14 @@ jobs:
continue-on-error: true

env:
RB_SYS_CARGO_TARGET: ${{ matrix.rust_target }}
CARGO_BUILD_TARGET: ${{ matrix.rust_target }}
OPENDAL_RUBY_PLATFORM: ${{ matrix.platform }}

steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Setup Rust toolchain
shell: bash
run: |
rustup toolchain install stable --profile minimal
rustup default stable
Expand All @@ -126,13 +129,13 @@ jobs:
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
working-directory: bindings/ruby # must repeat because GitHub Actions will not use defaults.run
working-directory: bindings/ruby # must repeat because actions will not use defaults.run

- name: Show available rake tasks
run: bundle exec rake --tasks

- name: Build native gem
run: bundle exec rake native:opendal:${{ matrix.platform }} gem
run: bundle exec rake native:opendal:${{ matrix.platform }}

- name: Collect built gem
run: |
Expand Down
2 changes: 1 addition & 1 deletion bindings/ruby/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ homepage = "https://opendal.apache.org/"
license = "Apache-2.0"
repository = "https://github.com/apache/opendal"
rust-version = "1.85"
version = "0.1.6"
version = "0.1.7-rc.1"

[lib]
crate-type = ["cdylib"]
Expand Down
2 changes: 0 additions & 2 deletions bindings/ruby/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ gemspec

group :development, :test do
gem "rake", ">= 13.2"
gem "rb_sys", "~> 0.9.128" # for Makefile generation in extconf.rb
gem "rake-compiler", "~> 1.2.9" # to build a debug build
gem "minitest", "~> 6.0.6" # test library
gem "minitest-reporters", "~> 1.7.1" # better test output
gem "activesupport", "~> 8.0.5" # testing support
Expand Down
87 changes: 62 additions & 25 deletions bindings/ruby/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "fileutils"
require "rake/testtask"
require "rb_sys/extensiontask"
require "rubygems/ext"
require "rubygems/ext/cargo_builder"
require "rubygems/package"
require "standard/rake"

GEMSPEC = Gem::Specification.load("opendal.gemspec")
PACKAGE_NAME = "opendal"
CRATE_PACKAGE_NAME = "opendal-ruby"
# Ruby loads native extensions by basename without the platform suffix.
# RbConfig::CONFIG["DLEXT"] is Ruby's loadable native-extension suffix for
# the current platform, such as "bundle" on macOS or "so" on Linux.
EXTENSION = "opendal_ruby"
EXTENSION_FILE = "#{EXTENSION}.#{RbConfig::CONFIG["DLEXT"]}"
EXTENSION_PATH = "lib/#{EXTENSION_FILE}"

desc "Copy core files for compilation"
task :copy_core do
Expand Down Expand Up @@ -52,29 +62,6 @@ task :copy_core do
end
end

RbSys::ExtensionTask.new(CRATE_PACKAGE_NAME, GEMSPEC) do |ext|
ext.name = "opendal_ruby"
ext.ext_dir = "."
ext.lib_dir = "lib/opendal_ruby"

ext.cross_compile = true
ext.cross_platform = %w[
x86_64-linux
arm64-linux
arm64-darwin
arm64-darwin23
]

# Override Ruby version requirement for native gems
# This prevents automatic constraint to the build Ruby version (e.g., >= 3.3, < 3.4.dev)
ext.cross_compiling do |gem_spec|
# keep in sync with opendal.gemspec
gem_spec.required_ruby_version = ">= 3.2", "< 3.5.dev"
end
end

Rake::Task[:test].prerequisites << :compile

Rake::TestTask.new("test:base") do |t|
t.libs << "lib"
t.libs << "test"
Expand Down Expand Up @@ -132,14 +119,64 @@ task :version do
print GEMSPEC.version
end

# Rake's file task below writes into lib/, so model the directory explicitly.
directory "lib"

file EXTENSION_PATH => FileList["Cargo.toml", "Cargo.lock", "build.rs", "src/**/*.rs"] do
original_verbose = Gem.configuration.verbose
Gem.configuration.verbose = :really
puts "Building #{EXTENSION_PATH} with CargoBuilder..."
puts "CARGO_BUILD_TARGET=#{ENV["CARGO_BUILD_TARGET"]}" if ENV["CARGO_BUILD_TARGET"]
Gem::Ext::CargoBuilder.new.build("Cargo.toml", ".", [], [], "lib", __dir__)
FileUtils.rm_f EXTENSION_FILE
puts "Built #{EXTENSION_PATH}"
ensure
Gem.configuration.verbose = original_verbose
end

# Make `rake clean` remove the generated native extension.
CLEAN.include EXTENSION_PATH

desc "Compile #{EXTENSION}"
task "compile:#{EXTENSION}" => EXTENSION_PATH

desc "Compile all the extensions"
task compile: "compile:#{EXTENSION}"

Rake::Task[:test].prerequisites << EXTENSION_PATH

namespace :native do
desc "Build a native gem for #{ENV.fetch("OPENDAL_RUBY_PLATFORM", Gem::Platform.local.to_s)}"
task PACKAGE_NAME do
platform = ENV.fetch("OPENDAL_RUBY_PLATFORM", Gem::Platform.local.to_s)
Rake::Task["native:#{PACKAGE_NAME}:#{platform}"].invoke
end

task "#{PACKAGE_NAME}:#{ENV.fetch("OPENDAL_RUBY_PLATFORM", Gem::Platform.local.to_s)}" => EXTENSION_PATH do
platform = ENV.fetch("OPENDAL_RUBY_PLATFORM", Gem::Platform.local.to_s)
puts "Packaging #{PACKAGE_NAME} native gem for #{platform}..."
spec = GEMSPEC.dup
spec.platform = Gem::Platform.new(platform)
spec.extensions.clear
spec.files |= [EXTENSION_PATH]

FileUtils.mkdir_p "pkg"
gem_file = Gem::Package.build(spec)
FileUtils.mv gem_file, "pkg/#{File.basename(gem_file)}"
puts "Packaged pkg/#{File.basename(gem_file)}"
end
end

task native: "native:#{PACKAGE_NAME}"

# Ensure core files are copied before compilation and packaging
Rake::Task["build"].enhance(["copy_core"]) if Rake::Task.task_defined?("build")

Rake::Task["release"].clear # clear the existing release task to allow override
Rake::Task["release:rubygem_push"].clear if Rake::Task.task_defined?("release:rubygem_push")

# overrides bundler's default rake release task
# we removed build and git tagging steps. Read more in ``./.github/workflows/release-ruby.yml`
# we removed build and git tagging steps. Read more in `./.github/workflows/release-ruby.yml`
# read more https://github.com/rubygems/rubygems/blob/master/bundler/lib/bundler/gem_helper.rb
desc "Multi-arch release"
task release: [
Expand Down
24 changes: 0 additions & 24 deletions bindings/ruby/extconf.rb

This file was deleted.

2 changes: 1 addition & 1 deletion bindings/ruby/lib/opendal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# frozen_string_literal: true

require_relative "opendal_ruby/opendal_ruby"
require_relative "opendal_ruby"
require_relative "opendal_ruby/io"
require_relative "opendal_ruby/entry"
require_relative "opendal_ruby/metadata"
Expand Down
2 changes: 1 addition & 1 deletion bindings/ruby/opendal.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Gem::Specification.new do |spec|

spec.require_paths = ["lib"]

spec.extensions = ["./extconf.rb"]
spec.extensions = ["./Cargo.toml"]

# Exclude non-Ruby files from RDoc to prevent parsing errors
spec.rdoc_options = ["--exclude", "Cargo\\..*", "--exclude", "core/", "--exclude", "\\.rs$"]
Expand Down