Skip to content

Include HIDAPI functions in SDL2 port#26297

Open
zturtleman wants to merge 1 commit intoemscripten-core:mainfrom
zturtleman:sdl2_hidapi
Open

Include HIDAPI functions in SDL2 port#26297
zturtleman wants to merge 1 commit intoemscripten-core:mainfrom
zturtleman:sdl2_hidapi

Conversation

@zturtleman
Copy link

This pull request updates the SDL2 port to include the stub implementations for SDL_hid_init() and related functions in SDL_hidapi.c that were added in SDL 2.0.18.

These functions are built for Emscritpen using the official SDL2 build systems. Including them in Emscripten's SDL2 port solves linker errors for software that use them.

Fixes: #26282


Additional source files for SDL 2.32.8 don't export any SDL2 API functions so I didn't add them to the source list in sdl2.py.

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but perhaps we could include this in a test? Maybe modify one of the existing SDL1 tests.

Also, presumably there is no way to actually use the HID API from emscripten without first hooking it up to browser, so its not currently very useful other than to prevent linker errors?

@zturtleman zturtleman marked this pull request as ready for review February 18, 2026 21:44
@zturtleman
Copy link
Author

You are correct. It fixes linker errors and doesn't provide HID device access.

The functions are listed in the library (with this pull request) using this command in the emsdk directory:

$ ./upstream/bin/llvm-nm ./upstream/emscripten/cache/sysroot/lib/wasm32-emscripten/libSDL2.a | grep SDL_hid_

00000a3b T SDL_hid_ble_scan
00000635 T SDL_hid_close
00000049 T SDL_hid_device_change_count
0000004e T SDL_hid_enumerate
0000001b T SDL_hid_exit
00000053 T SDL_hid_free_enumeration
0000054b T SDL_hid_get_feature_report
0000094f T SDL_hid_get_indexed_string
00000691 T SDL_hid_get_manufacturer_string
0000077b T SDL_hid_get_product_string
00000865 T SDL_hid_get_serial_number_string
00000001 T SDL_hid_init
000000b2 T SDL_hid_open
000000b7 T SDL_hid_open_path
0000028f T SDL_hid_read
000001a3 T SDL_hid_read_timeout
00000461 T SDL_hid_send_feature_report
00000379 T SDL_hid_set_nonblocking
000000bc T SDL_hid_write

For what it's worth, there are around ~900 public API functions in SDL2's dynapi list if someone wanted to verify they all exist.

Would you like the following added to test_sdl2_misc.c to confirm linking works for two of the functions?

  // Check if linking works with some of the HIDAPI functions added in SDL 2.0.18.
  SDL_hid_init();
  SDL_hid_exit();

@sbc100
Copy link
Collaborator

sbc100 commented Feb 18, 2026

Would you like the following added to test_sdl2_misc.c to confirm linking works for two of the functions?

Yes that sounds good.

Include the stub implementations for SDL_hid_init() and related functions
in SDL_hidapi.c that were added in SDL 2.0.18.

These functions are built for Emscritpen using the official SDL2 build
systems. Including them in Emscripten's SDL2 port solves linker errors
for software that use them.

Fixes: emscripten-core#26282
@sbc100 sbc100 enabled auto-merge (squash) February 19, 2026 00:09
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.

SDL2 port doesn't include SDL_hid_* functions

2 participants

Comments