@@ -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 )
0 commit comments