@@ -181,12 +181,12 @@ def pack(args)
181181 private
182182
183183 def build_config ( options )
184- build_source , all_default_exts = compute_build_source ( options )
185184 # @type var config: Packager::build_config
186- config = { target : options [ :target_triplet ] , src : build_source }
185+ config = compute_build_alias ( options )
186+ config [ :target ] = options [ :target_triplet ]
187187 case options [ :profile ]
188188 when "full"
189- config [ :default_exts ] = all_default_exts || ""
189+ config [ :default_exts ] = config [ : all_default_exts] || ""
190190 env_additional_exts = ENV [ "RUBY_WASM_ADDITIONAL_EXTS" ] || ""
191191 unless env_additional_exts . empty?
192192 config [ :default_exts ] += "," + env_additional_exts
@@ -201,80 +201,103 @@ def build_config(options)
201201 config
202202 end
203203
204- def compute_build_source ( options )
204+ def compute_build_alias ( options )
205205 src_name = options [ :ruby_version ]
206- aliases = self . class . build_source_aliases ( root )
207- source = aliases [ src_name ]
208- if source . nil?
206+ aliases = self . class . build_config_aliases ( root )
207+ config = aliases [ src_name ]
208+ if config . nil?
209209 if File . directory? ( src_name )
210210 # Treat as a local source if the given name is a source directory.
211211 RubyWasm . logger . debug "Using local source: #{ src_name } "
212212 if options [ :patches ] . any?
213213 RubyWasm . logger . warn "Patches specified through --patch are ignored for local sources"
214214 end
215- # @type var local_source: RubyWasm::Packager::build_source_local
216- local_source = { type : "local" , path : src_name }
217- # @type var local_source: RubyWasm::Packager::build_source
218- local_source = local_source . merge ( name : "local" , patches : [ ] )
219215 # FIXME: We should have a way to specify extensions to be included by users.
220216 # For now, assume all default extensions available in the head revision are available.
221- return [ local_source , RubyWasm ::Packager ::ALL_DEFAULT_EXTS ]
217+ return {
218+ name : "local" ,
219+ src : {
220+ type : "local" ,
221+ path : src_name ,
222+ patches : [ ]
223+ } ,
224+ all_default_exts : RubyWasm ::Packager ::ALL_DEFAULT_EXTS ,
225+ }
222226 end
223227 # Otherwise, it's an unknown source.
224228 raise (
225229 "Unknown Ruby source: #{ src_name } (available: #{ aliases . keys . join ( ", " ) } or a local directory)"
226230 )
227231 end
228232 # Apply user-specified patches in addition to bundled patches.
229- source [ :patches ] . concat ( options [ :patches ] )
230- # @type var all_default_exts: String
231- __skip__ = all_default_exts = source [ :all_default_exts ]
232- [ source , all_default_exts ]
233+ config [ :src ] [ :patches ] . concat ( options [ :patches ] )
234+ config
233235 end
234236
235237 # Retrieves the alias definitions for the Ruby sources.
236- def self . build_source_aliases ( root )
237- # @type var sources: Hash[string, RubyWasm::Packager::build_source]
238- sources = {
239- "head" => {
240- type : "github" ,
241- repo : "ruby/ruby" ,
242- rev : "master" ,
238+ def self . build_config_aliases ( root )
239+ # @type var aliases: Array[RubyWasm::Packager::build_source]
240+ aliases = [
241+ {
242+ name : "head" ,
243+ src : {
244+ type : "github" ,
245+ repo : "ruby/ruby" ,
246+ rev : "master" ,
247+ } ,
243248 all_default_exts : RubyWasm ::Packager ::ALL_DEFAULT_EXTS ,
249+ wasi_sdk_version : "23.0" ,
244250 } ,
245- "3.4" => {
246- type : "tarball" ,
247- url : "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.1.tar.gz" ,
251+ {
252+ name : "3.4" ,
253+ src : {
254+ type : "tarball" ,
255+ url : "https://cache.ruby-lang.org/pub/ruby/3.4/ruby-3.4.1.tar.gz" ,
256+ } ,
248257 all_default_exts : "cgi/escape,continuation,coverage,date,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,json,json/generator,json/parser,objspace,pathname,psych,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl" ,
258+ wasi_sdk_version : "22.0" ,
249259 } ,
250- "3.3" => {
251- type : "tarball" ,
252- url : "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.3.tar.gz" ,
260+ {
261+ name : "3.3" ,
262+ src : {
263+ type : "tarball" ,
264+ url : "https://cache.ruby-lang.org/pub/ruby/3.3/ruby-3.3.3.tar.gz" ,
265+ } ,
253266 all_default_exts : "bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl" ,
267+ wasi_sdk_version : "22.0" ,
254268 } ,
255- "3.2" => {
256- type : "tarball" ,
257- url : "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.4.tar.gz" ,
269+ {
270+ name : "3.2" ,
271+ src : {
272+ type : "tarball" ,
273+ url : "https://cache.ruby-lang.org/pub/ruby/3.2/ruby-3.2.4.tar.gz" ,
274+ } ,
258275 all_default_exts : "bigdecimal,cgi/escape,continuation,coverage,date,dbm,digest/bubblebabble,digest,digest/md5,digest/rmd160,digest/sha1,digest/sha2,etc,fcntl,fiber,gdbm,json,json/generator,json/parser,nkf,objspace,pathname,psych,racc/cparse,rbconfig/sizeof,ripper,stringio,strscan,monitor,zlib,openssl" ,
276+ wasi_sdk_version : "22.0" ,
259277 }
260- }
278+ ]
279+
280+ # Set the name in the source config.
281+ aliases . each do |config |
282+ config [ :src ] [ :name ] = config [ :name ]
283+ end
261284
262285 # Apply bundled and user-specified `<root>/patches` directories.
263- sources . each do |name , source |
264- source [ :name ] = name
286+ aliases . each do |config |
265287 patches_dirs = [ bundled_patches_path , File . join ( root , "patches" ) ]
266- source [ :patches ] = patches_dirs . flat_map do |patches_dir |
267- Dir [ File . join ( patches_dir , name , "*.patch" ) ]
288+ config [ :src ] [ :patches ] = patches_dirs . flat_map do |patches_dir |
289+ Dir [ File . join ( patches_dir , config [ : name] , "*.patch" ) ]
268290 . map { |p | File . expand_path ( p ) }
269291 end . uniq
270292 end
271293
294+ # Pin the revisions based on build_manifest.json if available.
272295 build_manifest = File . join ( root , "build_manifest.json" )
273296 if File . exist? ( build_manifest )
274297 begin
275298 manifest = JSON . parse ( File . read ( build_manifest ) )
276299 manifest [ "ruby_revisions" ] . each do |name , rev |
277- source = sources [ name ]
300+ source = aliases [ name ] [ :src ]
278301 next unless source [ :type ] == "github"
279302 # @type var source: RubyWasm::Packager::build_source_github
280303 source [ :rev ] = rev
@@ -283,7 +306,7 @@ def self.build_source_aliases(root)
283306 RubyWasm . logger . warn "Failed to load build_manifest.json: #{ e } "
284307 end
285308 end
286- sources
309+ aliases . to_h { | config | [ config [ :name ] , config ] }
287310 end
288311
289312 # Retrieves the root directory of the Ruby project.
0 commit comments