Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript bindings #1734

Merged
merged 1 commit into from
Oct 26, 2023
Merged

JavaScript bindings #1734

merged 1 commit into from
Oct 26, 2023

Conversation

kddnewton
Copy link
Collaborator

No description provided.

@ianks
Copy link
Contributor

ianks commented Oct 25, 2023

Looks good overall. Couple small suggestions to make things work on Mac, and to avoid exporting a ton of symbols:

diff --git i/Makefile w/Makefile
index d64d9686..632b4dd2 100644
--- i/Makefile
+++ w/Makefile
@@ -36,7 +36,8 @@ build/librubyparser.a: $(STATIC_OBJECTS)
 
 build/prism.wasm: Makefile $(SOURCES) $(HEADERS)
 	$(ECHO) "building $@"
-	$(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-all -Wl,--no-entry -mexec-model=reactor -o $@ $(SOURCES)
+	$(Q) mkdir -p $(@D)
+	$(Q) $(WASI_SDK_PATH)/bin/clang --sysroot=$(WASI_SDK_PATH)/share/wasi-sysroot/ -I$(WASI_SDK_PATH)/share/wasi-sysroot/include $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS -D_WASI_EMULATED_MMAN -lwasi-emulated-mman $(CPPFLAGS) $(CFLAGS) -Wl,--export-dynamic -Wl,--no-entry -mexec-model=reactor -o $@ $(SOURCES)
 
 build/shared/%.o: src/%.c Makefile $(HEADERS)
 	$(ECHO) "compiling $@"

Which results in:

❯ make build/prism.wasm WASI_SDK_PATH=$HOME/Downloads/wasi-sdk-20.0
...

❯ wasm-tools print build/prism.wasm | grep 'export'
  (export "memory" (memory 0))
  (export "_initialize" (func 10))
  (export "pm_token_type_to_str" (func 13))
  (export "pm_buffer_init" (func 50))
  (export "pm_buffer_free" (func 48))
  (export "pm_string_source" (func 29))
  (export "pm_string_length" (func 41))
  (export "pm_prettyprint" (func 16))
  (export "pm_list_empty_p" (func 28))
  (export "pm_list_size" (func 29))
  (export "pm_list_free" (func 31))
  (export "pm_string_free" (func 42))
  (export "pm_string_mapped_init" (func 43))
  (export "pm_string_sizeof" (func 44))
  (export "pm_string_list_init" (func 47))
  (export "pm_string_list_free" (func 48))
  (export "pm_buffer_sizeof" (func 44))
  (export "pm_buffer_value" (func 29))
  (export "pm_buffer_length" (func 41))
  (export "pm_lex_serialize" (func 72))
  (export "pm_parser_init" (func 155))
  (export "pm_parse" (func 160))
  (export "pm_node_destroy" (func 283))
  (export "pm_parser_free" (func 158))
  (export "pm_parse_lex_serialize" (func 74))
  (export "pm_serialize" (func 163))
  (export "pm_regexp_named_capture_group_names" (func 75))
  (export "pm_pack_parse" (func 80))
  (export "pm_size_to_native" (func 81))
  (export "pm_version" (func 152))
  (export "pm_parser_register_encoding_changed_callback" (func 156))
  (export "pm_parser_register_encoding_decode_callback" (func 157))
  (export "pm_parse_serialize" (func 164))
  (export "pm_node_memsize" (func 285))
  (export "pm_node_type_to_str" (func 288))

@kddnewton kddnewton changed the title (DO NOT MERGE) Compile with WASI SDK JavaScript bindings Oct 25, 2023
@kddnewton
Copy link
Collaborator Author

@ianks that's a good point, I'm going to try to do it in a follow-up because I think I need some additional functions. Right now I'm explicitly using calloc and free, which is probably wrong but I couldn't figure out another way to do it.

@kddnewton kddnewton merged commit 6499cf5 into main Oct 26, 2023
47 of 48 checks passed
@kddnewton kddnewton deleted the wasi branch October 26, 2023 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants