@@ -61,6 +61,100 @@ def artifact
6161 end
6262
6363 class DynamicLinking < BuildStrategy
64+ def build ( executor , options )
65+ build = derive_build
66+ force_rebuild =
67+ options [ :remake ] || options [ :clean ] || options [ :reconfigure ]
68+ if File . exist? ( build . crossruby . artifact ) && !force_rebuild
69+ return build . crossruby . artifact
70+ end
71+ build . crossruby . clean ( executor ) if options [ :clean ]
72+
73+ do_build =
74+ proc do
75+ build . crossruby . build (
76+ executor ,
77+ remake : options [ :remake ] ,
78+ reconfigure : options [ :reconfigure ]
79+ )
80+ end
81+
82+ __skip__ =
83+ if defined? ( Bundler )
84+ Bundler . with_unbundled_env ( &do_build )
85+ else
86+ do_build . call
87+ end
88+ build . crossruby . artifact
89+ end
90+
91+ def build_exts ( build )
92+ specs_with_extensions . flat_map do |spec , exts |
93+ exts . map do |ext |
94+ ext_feature = File . dirname ( ext ) # e.g. "ext/cgi/escape"
95+ ext_srcdir = File . join ( spec . full_gem_path , ext_feature )
96+ ext_relative_path = File . join ( spec . full_name , ext_feature )
97+ RubyWasm ::CrossRubyExtProduct . new (
98+ ext_srcdir ,
99+ build . toolchain ,
100+ ext_relative_path : ext_relative_path
101+ )
102+ end
103+ end
104+ end
105+
106+ def cache_key ( digest )
107+ derive_build . cache_key ( digest )
108+ end
109+
110+ def artifact
111+ derive_build . crossruby . artifact
112+ end
113+
114+ def target
115+ RubyWasm ::Target . new ( @packager . full_build_options [ :target ] , pic : true )
116+ end
117+
118+ def derive_build
119+ return @build if @build
120+ __skip__ =
121+ build ||= RubyWasm ::Build . new (
122+ name , **@packager . full_build_options ,
123+ target : target ,
124+ # NOTE: We don't need linking libwasi_vfs because we use wasi-virt instead.
125+ wasi_vfs : nil
126+ )
127+ build . crossruby . cflags = %w[ -fPIC -fvisibility=default ]
128+ if @packager . full_build_options [ :target ] != "wasm32-unknown-emscripten"
129+ build . crossruby . debugflags = %w[ -g ]
130+ build . crossruby . wasmoptflags = %w[ -O3 -g ]
131+ build . crossruby . ldflags = %w[
132+ -Xlinker
133+ --stack-first
134+ -Xlinker
135+ -z
136+ -Xlinker
137+ stack-size=16777216
138+ ]
139+ build . crossruby . xldflags = %w[
140+ -Xlinker -shared
141+ -Xlinker --export-dynamic
142+ -Xlinker --export-all
143+ -Xlinker --experimental-pic
144+ -Xlinker -export-if-defined=__main_argc_argv
145+ ]
146+ end
147+ @build = build
148+ build
149+ end
150+
151+ def name
152+ require "digest"
153+ options = @packager . full_build_options
154+ src_channel = options [ :src ] [ :name ]
155+ target_triplet = options [ :target ]
156+ "ruby-#{ src_channel } -#{ target_triplet } -pic#{ options [ :suffix ] } "
157+ end
64158 end
65159
66160 class StaticLinking < BuildStrategy
@@ -100,7 +194,7 @@ def artifact
100194 end
101195
102196 def target
103- RubyWasm ::Target . new ( @packager . full_build_options [ :target ] , pic : true )
197+ RubyWasm ::Target . new ( @packager . full_build_options [ :target ] )
104198 end
105199
106200 def derive_build
0 commit comments