Skip to content

Commit 866f53d

Browse files
build: Apply patches bundled with ruby_wasm gem
And now build user should use `--patch` option to apply custom patches instead of placing them in the `patches` directory.
1 parent a3d007e commit 866f53d

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

lib/ruby_wasm/cli.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def compute_build_source(options)
191191
"Unknown Ruby source: #{src_name} (available: #{aliases.keys.join(", ")} or a local directory)"
192192
)
193193
end
194-
# Apply user-specified patches in addition to <root>/patches.
194+
# Apply user-specified patches in addition to bundled patches.
195195
source[:patches].concat(options[:patches])
196196
source
197197
end
@@ -214,11 +214,15 @@ def self.build_source_aliases(root)
214214
url: "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.3.tar.gz"
215215
}
216216
}
217+
218+
# Apply bundled and user-specified `<root>/patches` directories.
217219
sources.each do |name, source|
218220
source[:name] = name
219-
patches = Dir[File.join(root, "patches", name, "*.patch")]
220-
.map { |p| File.expand_path(p) }
221-
source[:patches] = patches
221+
patches_dirs = [bundled_patches_path, File.join(root, "patches")]
222+
source[:patches] = patches_dirs.flat_map do |patches_dir|
223+
Dir[File.join(patches_dir, name, "*.patch")]
224+
.map { |p| File.expand_path(p) }
225+
end
222226
end
223227

224228
build_manifest = File.join(root, "build_manifest.json")
@@ -255,12 +259,20 @@ def root
255259
end
256260
end
257261

262+
# Path to the directory containing the bundled patches, which is shipped
263+
# as part of ruby_wasm gem to backport fixes or try experimental features
264+
# before landing them to the ruby/ruby repository.
265+
def self.bundled_patches_path
266+
lib_source_root = File.join(__dir__, "..", "..")
267+
File.join(lib_source_root, "patches")
268+
end
269+
258270
def derive_packager(options)
259271
__skip__ =
260272
if defined?(Bundler) && !options[:disable_gems]
261273
definition = Bundler.definition
262274
end
263-
RubyWasm::Packager.new(build_config(options), definition)
275+
RubyWasm::Packager.new(root, build_config(options), definition)
264276
end
265277

266278
def do_print_ruby_cache_key(packager)

lib/ruby_wasm/packager.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ class RubyWasm::Packager
44
#
55
# @param root [String] The root directory of the Ruby project.
66
# The root directory (will) contain the following files:
7-
# * patches/{source}/*.patch
87
# * build_manifest.json
98
# * rubies
109
# * build

sig/ruby_wasm/cli.rbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module RubyWasm
3434
def build_config: (cli_options options) -> Packager::build_config
3535
def compute_build_source: (cli_options options) -> Packager::build_source
3636
def self.build_source_aliases: (string root) -> Hash[string, Packager::build_source]
37+
def self.bundled_patches_path: () -> string
3738
def root: () -> string
3839

3940
def derive_packager: (cli_options options) -> Packager

0 commit comments

Comments
 (0)