From 0bbadd6883c835f8d403747125ae9d6069c72fdb Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sun, 1 Oct 2023 19:44:46 +0200 Subject: [PATCH] [Web] Fix dlink_enabled build After changing the default visibility to hidden to avoid generating thousands of import/export symbols (browsers have a hard limit of 10k), explicitly setting visibility for "boundary functions" (i.e. wasm callbacks called by JS via pointer) is required to ensure the function can be retrieved via pointer from the function table. --- platform/web/audio_driver_web.h | 5 +-- platform/web/display_server_web.h | 32 +++++++++++--------- platform/web/godot_js.h | 2 ++ platform/web/javascript_bridge_singleton.cpp | 10 +++--- platform/web/os_web.h | 10 +++--- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/platform/web/audio_driver_web.h b/platform/web/audio_driver_web.h index 7bfed834e101..12a61746c381 100644 --- a/platform/web/audio_driver_web.h +++ b/platform/web/audio_driver_web.h @@ -32,6 +32,7 @@ #define AUDIO_DRIVER_WEB_H #include "godot_audio.h" +#include "godot_js.h" #include "core/os/mutex.h" #include "core/os/thread.h" @@ -55,8 +56,8 @@ class AudioDriverWeb : public AudioDriver { int mix_rate = 0; int channel_count = 0; - static void _state_change_callback(int p_state); - static void _latency_update_callback(float p_latency); + WASM_EXPORT static void _state_change_callback(int p_state); + WASM_EXPORT static void _latency_update_callback(float p_latency); static AudioDriverWeb *singleton; diff --git a/platform/web/display_server_web.h b/platform/web/display_server_web.h index a4fd75f33b30..1653deff8061 100644 --- a/platform/web/display_server_web.h +++ b/platform/web/display_server_web.h @@ -33,6 +33,8 @@ #include "servers/display_server.h" +#include "godot_js.h" + #include #include @@ -88,28 +90,28 @@ class DisplayServerWeb : public DisplayServer { static const char *godot2dom_cursor(DisplayServer::CursorShape p_shape); // events - static void fullscreen_change_callback(int p_fullscreen); - static int mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers); - static void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers); - static int mouse_wheel_callback(double p_delta_x, double p_delta_y); - static void touch_callback(int p_type, int p_count); - static void key_callback(int p_pressed, int p_repeat, int p_modifiers); - static void vk_input_text_callback(const char *p_text, int p_cursor); - static void gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid); + WASM_EXPORT static void fullscreen_change_callback(int p_fullscreen); + WASM_EXPORT static int mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers); + WASM_EXPORT static void mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers); + WASM_EXPORT static int mouse_wheel_callback(double p_delta_x, double p_delta_y); + WASM_EXPORT static void touch_callback(int p_type, int p_count); + WASM_EXPORT static void key_callback(int p_pressed, int p_repeat, int p_modifiers); + WASM_EXPORT static void vk_input_text_callback(const char *p_text, int p_cursor); + WASM_EXPORT static void gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid); void process_joypads(); - static void _js_utterance_callback(int p_event, int p_id, int p_pos); + WASM_EXPORT static void _js_utterance_callback(int p_event, int p_id, int p_pos); static Vector get_rendering_drivers_func(); static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Error &r_error); static void _dispatch_input_event(const Ref &p_event); - static void request_quit_callback(); - static void window_blur_callback(); - static void update_voices_callback(int p_size, const char **p_voice); - static void update_clipboard_callback(const char *p_text); - static void send_window_event_callback(int p_notification); - static void drop_files_js_callback(char **p_filev, int p_filec); + WASM_EXPORT static void request_quit_callback(); + WASM_EXPORT static void window_blur_callback(); + WASM_EXPORT static void update_voices_callback(int p_size, const char **p_voice); + WASM_EXPORT static void update_clipboard_callback(const char *p_text); + WASM_EXPORT static void send_window_event_callback(int p_notification); + WASM_EXPORT static void drop_files_js_callback(char **p_filev, int p_filec); protected: int get_current_video_driver() const; diff --git a/platform/web/godot_js.h b/platform/web/godot_js.h index 3341cf8a6726..f172148bf9ce 100644 --- a/platform/web/godot_js.h +++ b/platform/web/godot_js.h @@ -31,6 +31,8 @@ #ifndef GODOT_JS_H #define GODOT_JS_H +#define WASM_EXPORT __attribute__((visibility("default"))) + #ifdef __cplusplus extern "C" { #endif diff --git a/platform/web/javascript_bridge_singleton.cpp b/platform/web/javascript_bridge_singleton.cpp index 45bce1b48050..2296176e77dc 100644 --- a/platform/web/javascript_bridge_singleton.cpp +++ b/platform/web/javascript_bridge_singleton.cpp @@ -68,11 +68,11 @@ class JavaScriptObjectImpl : public JavaScriptObject { int _js_id = 0; Callable _callable; - static int _variant2js(const void **p_args, int p_pos, godot_js_wrapper_ex *r_val, void **p_lock); - static void _free_lock(void **p_lock, int p_type); - static Variant _js2variant(int p_type, godot_js_wrapper_ex *p_val); - static void *_alloc_variants(int p_size); - static void _callback(void *p_ref, int p_arg_id, int p_argc); + WASM_EXPORT static int _variant2js(const void **p_args, int p_pos, godot_js_wrapper_ex *r_val, void **p_lock); + WASM_EXPORT static void _free_lock(void **p_lock, int p_type); + WASM_EXPORT static Variant _js2variant(int p_type, godot_js_wrapper_ex *p_val); + WASM_EXPORT static void *_alloc_variants(int p_size); + WASM_EXPORT static void _callback(void *p_ref, int p_arg_id, int p_argc); protected: bool _set(const StringName &p_name, const Variant &p_value) override; diff --git a/platform/web/os_web.h b/platform/web/os_web.h index b9570f9ca1ab..cb1897a2fe2f 100644 --- a/platform/web/os_web.h +++ b/platform/web/os_web.h @@ -33,6 +33,8 @@ #include "audio_driver_web.h" +#include "godot_js.h" + #include "core/input/input.h" #include "drivers/unix/os_unix.h" #include "servers/audio_server.h" @@ -48,11 +50,11 @@ class OS_Web : public OS_Unix { bool idb_needs_sync = false; bool pwa_is_waiting = false; - static void main_loop_callback(); + WASM_EXPORT static void main_loop_callback(); - static void file_access_close_callback(const String &p_file, int p_flags); - static void fs_sync_callback(); - static void update_pwa_state_callback(); + WASM_EXPORT static void file_access_close_callback(const String &p_file, int p_flags); + WASM_EXPORT static void fs_sync_callback(); + WASM_EXPORT static void update_pwa_state_callback(); protected: void initialize() override;