From fbebb9d09d6df717f8da30f02c2fd0ee14d512ec Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 29 Apr 2024 14:01:18 +0000 Subject: [PATCH 1/3] Compile bindgen/ext.c with cflags To use -fPIC consistently, we need to compile all C files with CFLAGS --- packages/gems/js/ext/js/depend | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/gems/js/ext/js/depend b/packages/gems/js/ext/js/depend index 35d28008ab..33f9bd23c0 100644 --- a/packages/gems/js/ext/js/depend +++ b/packages/gems/js/ext/js/depend @@ -14,4 +14,5 @@ bindgen/legacy/%.o: $(srcdir)/bindgen/legacy/%.c bindgen/ext.o: $(srcdir)/bindgen/ext.c @mkdir -p "$(@D)" - $(CC) -c -o $@ $< + $(ECHO) compiling $(<) + $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$< From 5d6aff29a6deda3ed25372ca418f4ada5cc9291a Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 29 Apr 2024 14:13:25 +0000 Subject: [PATCH 2/3] Skip wasi-vfs initialization for PIC build by default --- packages/gems/js/ext/js/witapi-core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/gems/js/ext/js/witapi-core.c b/packages/gems/js/ext/js/witapi-core.c index fe865f4ee6..269e17e010 100644 --- a/packages/gems/js/ext/js/witapi-core.c +++ b/packages/gems/js/ext/js/witapi-core.c @@ -363,10 +363,15 @@ static inline void __wasm_call_ctors_if_needed(void) { __wasm_call_ctors_done = true; __wasm_call_ctors(); + // Initialize VFS runtime if it's used + // NOTE: We don't use wasi-vfs for PIC build. Instead, we use + // Component Model-native wasi-virt. +# ifndef __PIC__ __attribute__((weak)) extern void __wasi_vfs_rt_init(void); if (__wasi_vfs_rt_init) { __wasi_vfs_rt_init(); } +# endif } } From 0d9b42763864eb727547c6bebfd86e255a983f04 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 29 Apr 2024 14:14:39 +0000 Subject: [PATCH 3/3] Link the component type object to the shared library --- packages/gems/js/ext/js/extconf.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/gems/js/ext/js/extconf.rb b/packages/gems/js/ext/js/extconf.rb index f9e9f822e6..52a23ce0a2 100644 --- a/packages/gems/js/ext/js/extconf.rb +++ b/packages/gems/js/ext/js/extconf.rb @@ -19,7 +19,16 @@ $objs << "bindgen/legacy/rb-js-abi-host.o" $objs << "bindgen/legacy/rb-abi-guest.o" end + +component_type_obj = "$(srcdir)/bindgen/ext_component_type.o" + +unless $static + # When building shared library, we need to link the component type object + # to the shared library instead of the main ruby executable. + $libs << component_type_obj +end + create_makefile("js") do |mk| - mk << "EXTRA_OBJS = $(srcdir)/bindgen/ext_component_type.o\n" if use_component_model + mk << "EXTRA_OBJS = #{component_type_obj}\n" if use_component_model mk end