Skip to content

Commit 722db5c

Browse files
committed
fix(bindings/ruby): fix release build error
1 parent 043977e commit 722db5c

File tree

3 files changed

+51
-36
lines changed

3 files changed

+51
-36
lines changed

bindings/ruby/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ name = "opendal_ruby"
3434

3535
[dependencies]
3636
magnus = { version = "0.8", features = ["bytes", "io"] }
37-
# 1. this crate won't be published, we always use the local version
38-
# 2. we use the symbolink to allow released gem to find core's source files.
37+
# 1. we don't use published core but a local copy
38+
# 2. for source release, this path must be the local "./core". read more in opendal.gemspec
3939
opendal = { version = ">=0", path = "../../core", features = [
4040
"blocking",
4141
"layers-throttle",

bindings/ruby/Rakefile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ require "standard/rake"
2525
GEMSPEC = Gem::Specification.load("opendal.gemspec")
2626
CRATE_PACKAGE_NAME = "opendal-ruby"
2727

28+
desc "Copy core files for compilation"
29+
task :copy_core do
30+
core_dir = "../../core"
31+
distributed_core_dir = "core"
32+
33+
puts "Copying core files from #{core_dir} to #{distributed_core_dir}..."
34+
FileUtils.rm_rf(distributed_core_dir, secure: true)
35+
system("cp", "-Lr", core_dir, distributed_core_dir) # resolves symbolic links to a copy
36+
37+
# Verify core files were copied
38+
core_files_count = `git -C #{File.expand_path(core_dir, __dir__)} ls-files -z`.split("\x0").length
39+
puts "Copied #{core_files_count} files from core directory"
40+
41+
# Patch Cargo.toml for source distribution
42+
# When core files are copied locally, update Cargo.toml to reference the local copy
43+
if File.directory?(distributed_core_dir)
44+
cargo_toml = File.read("Cargo.toml")
45+
46+
# Only patch if we haven't already and we're using the relative path
47+
if cargo_toml.include?('path = "../../core"')
48+
puts "Patching Cargo.toml to use local core directory..."
49+
cargo_toml.gsub!('path = "../../core"', 'path = "core"')
50+
File.write("Cargo.toml", cargo_toml)
51+
end
52+
end
53+
end
54+
2855
RbSys::ExtensionTask.new(CRATE_PACKAGE_NAME, GEMSPEC) do |ext|
2956
ext.name = "opendal_ruby"
3057
ext.ext_dir = "."
@@ -93,16 +120,8 @@ task :version do
93120
print GEMSPEC.version
94121
end
95122

96-
desc "Copy the core directory for gem packaging" # Read more in `./.github/workflows/release-ruby.yml`
97-
task :copy_core do
98-
puts "Copy the core directory for packaging..."
99-
src = "../../core"
100-
dst = "./core"
101-
`cp -RL #{src} #{dst}`
102-
end
103-
104-
# Hook into build task to copy the core directory first
105-
Rake::Task["build"].enhance([:copy_core]) if Rake::Task.task_defined?("build")
123+
# Ensure core files are copied before compilation and packaging
124+
Rake::Task["build"].enhance(["copy_core"]) if Rake::Task.task_defined?("build")
106125

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

bindings/ruby/opendal.gemspec

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ require "json"
2222
Gem::Specification.new do |spec|
2323
spec.name = "opendal"
2424
# RubyGems integrates and expects `cargo`.
25-
# Read more about [Gem::Ext::CargoBuilder](https://github.com/rubygems/rubygems/blob/v3.5.23/lib/rubygems/ext/cargo_builder.rb)
25+
# Read more about
26+
# [Gem::Ext::CargoBuilder](https://github.com/rubygems/rubygems/blob/v3.5.23/lib/rubygems/ext/cargo_builder.rb)
2627
#
2728
# OpenDAL relies on "version" in `Cargo.toml` for the release process. You can read this gem spec with:
2829
# `bundle exec ruby -e 'puts Gem::Specification.load("opendal.gemspec")'`
@@ -54,40 +55,35 @@ Gem::Specification.new do |spec|
5455
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
5556
spec.files = Dir.chdir(__dir__) do
5657
git_files = `git ls-files -z`.split("\x0").reject do |f|
57-
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[gems/ pkg/ target/ tmp/ .git]) || f == "core"
58+
f.start_with?(*%w[gems/ pkg/ target/ tmp/ .git])
5859
end
5960

60-
# Copy core directory
61-
src = "../../core"
62-
dst = "./core"
63-
`cp -RL #{src} #{dst}`
61+
# When building release package, include core directory files for rake build
62+
core_dir = "../../core"
63+
distributed_core_dir = "core"
6464

65-
# Include core directory files, excluding symlinks
66-
core_files = Dir.chdir("./core") do
67-
`git ls-files -z`.split("\x0").reject do |f|
68-
File.symlink?(File.join("./core", f))
69-
end.map { |f| "core/#{f}" }
70-
end
65+
if Dir.exist?(distributed_core_dir)
66+
# Core files should already be copied by the Rakefile's copy_core task
67+
core_files = `git -C #{File.expand_path(core_dir, __dir__)} ls-files -z`
68+
.split("\x0")
69+
.filter_map do |f|
70+
full_path = "#{distributed_core_dir}/#{f}"
71+
full_path if File.exist?(full_path)
72+
end
7173

72-
# Resolve symlinks: copy actual files from their target locations
73-
# This handles recursive symbol link cases. e.g., core/CHANGELOG.md -> ../CHANGELOG.md
74-
symlink_targets = Dir.chdir("./core") do
75-
`git ls-files -z`.split("\x0").select do |f|
76-
File.symlink?(File.join("./core", f))
77-
end.filter_map do |f|
78-
link_target = File.readlink(File.join("./core", f))
79-
resolved_path = File.expand_path(link_target, File.join(__dir__, "core"))
80-
File.exist?(resolved_path) ? "core/#{f}" : nil
81-
end
74+
git_files + core_files
75+
else
76+
git_files
8277
end
83-
84-
git_files + core_files + symlink_targets
8578
end
8679

8780
spec.require_paths = ["lib"]
8881

8982
spec.extensions = ["./extconf.rb"]
9083

84+
# Exclude non-Ruby files from RDoc to prevent parsing errors
85+
spec.rdoc_options = ["--exclude", "Cargo\\..*", "--exclude", "core/", "--exclude", "\\.rs$"]
86+
9187
spec.requirements = ["Rust >= 1.85"]
9288
# use a Ruby version which:
9389
# - supports Rubygems with the ability of compilation of Rust gem

0 commit comments

Comments
 (0)