Skip to content

Commit 12eaf3b

Browse files
build: Accept --patch option to apply patches to the Ruby source
1 parent 3d12684 commit 12eaf3b

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lib/ruby_wasm/cli.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def build(args)
5353
target_triplet: "wasm32-unknown-wasi",
5454
profile: "full",
5555
stdlib: true,
56-
disable_gems: false
56+
disable_gems: false,
57+
patches: [],
5758
}
5859
OptionParser
5960
.new do |opts|
@@ -106,6 +107,10 @@ def build(args)
106107
options[:disable_gems] = true
107108
end
108109

110+
opts.on("-p", "--patch PATCH", "Apply a patch") do |patch|
111+
options[:patches] << patch
112+
end
113+
109114
opts.on("--format FORMAT", "Output format") do |format|
110115
options[:format] = format
111116
end
@@ -174,10 +179,15 @@ def build_config(options)
174179
def compute_build_source(options)
175180
src_name = options[:ruby_version]
176181
aliases = self.class.build_source_aliases(root)
177-
aliases[src_name] ||
182+
source = aliases[src_name]
183+
unless source
178184
raise(
179185
"Unknown Ruby source: #{src_name} (available: #{aliases.keys.join(", ")})"
180186
)
187+
end
188+
# Apply user-specified patches in addition to <root>/patches.
189+
source[:patches].concat(options[:patches])
190+
source
181191
end
182192

183193
# Retrieves the alias definitions for the Ruby sources.
@@ -210,7 +220,10 @@ def self.build_source_aliases(root)
210220
begin
211221
manifest = JSON.parse(File.read(build_manifest))
212222
manifest["ruby_revisions"].each do |name, rev|
213-
sources[name][:rev] = rev
223+
source = sources[name]
224+
next unless source[:type] == "github"
225+
# @type var source: RubyWasm::Packager::build_source_github
226+
source[:rev] = rev
214227
end
215228
rescue StandardError => e
216229
RubyWasm.logger.warn "Failed to load build_manifest.json: #{e}"

sig/ruby_wasm/cli.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ module RubyWasm
1515
profile: String,
1616
stdlib: bool,
1717
disable_gems: bool,
18+
patches: Array[String],
1819
format: String,
1920
}
21+
2022
DEFAULT_RUBIES_DIR: string
2123

2224
@stdout: IO

sig/ruby_wasm/packager.rbs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11

22
class RubyWasm::Packager
3-
type build_source = Hash[Symbol, (string | Array[String])]
3+
type build_source_github = {
4+
type: "github",
5+
repo: String,
6+
rev: String,
7+
}
8+
type build_source_tarball = {
9+
type: "tarball",
10+
url: String,
11+
}
12+
type build_source_local = {
13+
type: "local",
14+
path: String,
15+
}
16+
type build_source = (build_source_github | build_source_tarball | build_source_local) & {
17+
name: string,
18+
patches: Array[String],
19+
}
20+
421
type build_config = Hash[untyped, untyped]
522

623
@definition: untyped

0 commit comments

Comments
 (0)