Skip to content

Commit 730f157

Browse files
Make compilation with component model successful
But still linking fails because of missing symbols.
1 parent 1f671ee commit 730f157

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

packages/gems/js/ext/js/depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
CLEANFILES += link.filelist
12
link.filelist:
23
echo $(foreach obj,$(OBJS),$(abspath $(obj))) > $@
34
echo $(EXTRA_OBJS) >> $@

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
end
1414
create_makefile("js") do |mk|
1515
mk << "EXTRA_OBJS = $(srcdir)/bindgen/ext_component_type.o\n" if use_component_model
16+
mk
1617
end

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "ruby.h"
44

5-
#include "bindgen/legacy/rb-js-abi-host.h"
5+
#include "types.h"
66

77
// MARK: - Ruby extension
88

@@ -57,7 +57,7 @@ static VALUE jsvalue_s_allocate(VALUE klass) {
5757
return obj;
5858
}
5959

60-
static VALUE jsvalue_s_new(rb_js_abi_host_js_abi_value_t abi) {
60+
static VALUE jsvalue_s_new(rb_js_abi_host_own_js_abi_value_t abi) {
6161
struct jsvalue *p;
6262
VALUE obj = TypedData_Make_Struct(rb_cJS_Object, struct jsvalue,
6363
&jsvalue_data_type, p);
@@ -379,7 +379,7 @@ static VALUE _rb_js_obj_to_i(VALUE obj) {
379379
if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_F64) {
380380
result = rb_dbl2big(ret.val.f64);
381381
} else {
382-
result = rb_cstr2inum(ret.val.bignum.ptr, 10);
382+
result = rb_cstr2inum((const char *)ret.val.bignum.ptr, 10);
383383
}
384384
rb_js_abi_host_raw_integer_free(&ret);
385385
return result;
@@ -409,7 +409,7 @@ static VALUE _rb_js_obj_to_f(VALUE obj) {
409409
if (ret.tag == RB_JS_ABI_HOST_RAW_INTEGER_F64) {
410410
result = rb_float_new(ret.val.f64);
411411
} else {
412-
result = DBL2NUM(rb_cstr_to_dbl(ret.val.bignum.ptr, FALSE));
412+
result = DBL2NUM(rb_cstr_to_dbl((const char *)ret.val.bignum.ptr, FALSE));
413413
}
414414
rb_js_abi_host_raw_integer_free(&ret);
415415
return result;

packages/gems/js/ext/js/types.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef RUBY_WASM_JS_TYPES_H
2+
#define RUBY_WASM_JS_TYPES_H
3+
4+
#ifdef JS_ENABLE_COMPONENT_MODEL
5+
# include "bindgen/ext.h"
6+
7+
typedef exports_ruby_js_ruby_runtime_borrow_rb_abi_value_t rb_abi_guest_rb_abi_value_t;
8+
typedef exports_ruby_js_ruby_runtime_own_rb_abi_value_t rb_abi_guest_own_rb_abi_value_t;
9+
typedef exports_ruby_js_ruby_runtime_list_borrow_rb_abi_value_t rb_abi_guest_list_rb_abi_value_t;
10+
typedef exports_ruby_js_ruby_runtime_own_rb_iseq_t rb_abi_guest_rb_iseq_t;
11+
typedef exports_ruby_js_ruby_runtime_rb_id_t rb_abi_guest_rb_id_t;
12+
typedef exports_ruby_js_ruby_runtime_tuple2_own_rb_abi_value_s32_t rb_abi_guest_tuple2_rb_abi_value_s32_t;
13+
14+
typedef ruby_js_js_runtime_borrow_js_abi_value_t rb_js_abi_host_js_abi_value_t;
15+
typedef ruby_js_js_runtime_own_js_abi_value_t rb_js_abi_host_own_js_abi_value_t;
16+
typedef ruby_js_js_runtime_js_abi_result_t rb_js_abi_host_js_abi_result_t;
17+
typedef ruby_js_js_runtime_list_borrow_js_abi_value_t rb_js_abi_host_list_js_abi_value_t;
18+
typedef ruby_js_js_runtime_raw_integer_t rb_js_abi_host_raw_integer_t;
19+
20+
typedef ext_string_t rb_abi_guest_string_t;
21+
typedef ext_string_t rb_js_abi_host_string_t;
22+
typedef ext_list_string_t rb_abi_guest_list_string_t;
23+
24+
# define rb_abi_guest_rb_abi_value_new(val) exports_ruby_js_ruby_runtime_rb_abi_value_new(val)
25+
# define rb_abi_guest_rb_abi_value_get(val) (*(val))
26+
# define rb_abi_guest_rb_iseq_new(val) exports_ruby_js_ruby_runtime_rb_iseq_new(val)
27+
# define rb_js_abi_host_js_value_equal(lhs, rhs) ruby_js_js_runtime_js_value_equal(lhs, rhs)
28+
# define rb_js_abi_host_reflect_apply(target, this, args, ret) ruby_js_js_runtime_reflect_apply(target, this, args, ret)
29+
# define rb_js_abi_host_js_value_to_integer(value, ret) ruby_js_js_runtime_js_value_to_integer(value, ret)
30+
#else
31+
# include "bindgen/legacy/rb-abi-guest.h"
32+
# include "bindgen/legacy/rb-js-abi-host.h"
33+
typedef rb_abi_guest_rb_abi_value_t rb_abi_guest_own_rb_abi_value_t;
34+
typedef rb_js_abi_host_js_abi_value_t rb_js_abi_host_own_js_abi_value_t;
35+
#endif
36+
37+
#endif // RUBY_WASM_JS_TYPES_H

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static VALUE rb_eval_string_value_protect(VALUE str, int *pstate) {
1717

1818
#define TAG_NONE 0
1919

20-
#include "bindgen/legacy/rb-abi-guest.h"
20+
#include "types.h"
2121

2222
__attribute__((import_module("asyncify"), import_name("start_unwind"))) void
2323
asyncify_start_unwind(void *buf);
@@ -122,7 +122,7 @@ rb_wasm_throw_prohibit_rewind_exception(const char *c_msg, size_t msg_len);
122122
{ \
123123
new_args = alloca(sizeof(char *) * ((list)->len + 1)); \
124124
for (size_t i = 0; i < (list)->len; i++) { \
125-
new_args[i] = (list)->ptr[i].ptr; \
125+
new_args[i] = (char *)((list)->ptr[i].ptr); \
126126
} \
127127
}
128128

@@ -176,6 +176,15 @@ void rb_abi_guest_rb_abi_value_dtor(void *data) {
176176
assert(state == TAG_NONE && "rb_abi_guest_rb_abi_value_dtor_internal failed");
177177
}
178178

179+
#ifdef JS_ENABLE_COMPONENT_MODEL
180+
void exports_ruby_js_ruby_runtime_rb_iseq_destructor(exports_ruby_js_ruby_runtime_rb_iseq_t *rep) {
181+
}
182+
183+
void exports_ruby_js_ruby_runtime_rb_abi_value_destructor(exports_ruby_js_ruby_runtime_rb_abi_value_t *rep) {
184+
rb_abi_guest_rb_abi_value_dtor((void *)rep);
185+
}
186+
#endif
187+
179188
// MARK: - Exported functions
180189
// NOTE: Assume that callers always pass null terminated string by
181190
// rb_abi_guest_string_t
@@ -209,7 +218,7 @@ rb_abi_guest_ruby_options(rb_abi_guest_list_string_t *args) {
209218
}
210219

211220
void rb_abi_guest_ruby_script(rb_abi_guest_string_t *name) {
212-
RB_WASM_LIB_RT(ruby_script(name->ptr))
221+
RB_WASM_LIB_RT(ruby_script((const char *)name->ptr))
213222
}
214223

215224
void rb_abi_guest_ruby_init_loadpath(void) {
@@ -220,7 +229,7 @@ void rb_abi_guest_rb_eval_string_protect(
220229
rb_abi_guest_string_t *str, rb_abi_guest_tuple2_rb_abi_value_s32_t *ret0) {
221230
VALUE retval;
222231
RB_WASM_DEBUG_LOG("rb_eval_string_protect: str = %s\n", str->ptr);
223-
VALUE utf8_str = rb_utf8_str_new(str->ptr, str->len);
232+
VALUE utf8_str = rb_utf8_str_new((const char *)str->ptr, str->len);
224233
RB_WASM_LIB_RT(retval = rb_eval_string_value_protect(utf8_str, &ret0->f1));
225234
RB_WASM_DEBUG_LOG("rb_eval_string_protect: retval = %p, state = %d\n",
226235
(void *)retval, ret0->f1);
@@ -266,10 +275,10 @@ void rb_abi_guest_rb_funcallv_protect(
266275
}
267276

268277
rb_abi_guest_rb_id_t rb_abi_guest_rb_intern(rb_abi_guest_string_t *name) {
269-
return rb_intern(name->ptr);
278+
return rb_intern((const char *)name->ptr);
270279
}
271280

272-
rb_abi_guest_rb_abi_value_t rb_abi_guest_rb_errinfo(void) {
281+
rb_abi_guest_own_rb_abi_value_t rb_abi_guest_rb_errinfo(void) {
273282
VALUE retval;
274283
RB_WASM_LIB_RT(retval = rb_errinfo());
275284
rb_abi_lend_object(retval);

0 commit comments

Comments
 (0)