Skip to content

Commit 3cd8627

Browse files
Merge pull request #450 from ruby/pr-2fcb4e784ebc17ba2ab007511987950b1e020b25
PIC support in js gem
2 parents 148b81c + 0d9b427 commit 3cd8627

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

packages/gems/js/ext/js/depend

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ bindgen/legacy/%.o: $(srcdir)/bindgen/legacy/%.c
1414

1515
bindgen/ext.o: $(srcdir)/bindgen/ext.c
1616
@mkdir -p "$(@D)"
17-
$(CC) -c -o $@ $<
17+
$(ECHO) compiling $(<)
18+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<

packages/gems/js/ext/js/extconf.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@
1919
$objs << "bindgen/legacy/rb-js-abi-host.o"
2020
$objs << "bindgen/legacy/rb-abi-guest.o"
2121
end
22+
23+
component_type_obj = "$(srcdir)/bindgen/ext_component_type.o"
24+
25+
unless $static
26+
# When building shared library, we need to link the component type object
27+
# to the shared library instead of the main ruby executable.
28+
$libs << component_type_obj
29+
end
30+
2231
create_makefile("js") do |mk|
23-
mk << "EXTRA_OBJS = $(srcdir)/bindgen/ext_component_type.o\n" if use_component_model
32+
mk << "EXTRA_OBJS = #{component_type_obj}\n" if use_component_model
2433
mk
2534
end

packages/gems/js/ext/js/witapi-core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,15 @@ static inline void __wasm_call_ctors_if_needed(void) {
363363
__wasm_call_ctors_done = true;
364364
__wasm_call_ctors();
365365

366+
// Initialize VFS runtime if it's used
367+
// NOTE: We don't use wasi-vfs for PIC build. Instead, we use
368+
// Component Model-native wasi-virt.
369+
# ifndef __PIC__
366370
__attribute__((weak)) extern void __wasi_vfs_rt_init(void);
367371
if (__wasi_vfs_rt_init) {
368372
__wasi_vfs_rt_init();
369373
}
374+
# endif
370375
}
371376
}
372377

0 commit comments

Comments
 (0)