Skip to content

Implement monolithic static libretro build#2905

Open
imsys wants to merge 6 commits intonesbox:mainfrom
imsys:patch-8
Open

Implement monolithic static libretro build#2905
imsys wants to merge 6 commits intonesbox:mainfrom
imsys:patch-8

Conversation

@imsys
Copy link
Contributor

@imsys imsys commented Mar 9, 2026

Basically, libretro official binaries are stuck in a very old build.

We are trying to update it to the newest version at: libretro#28 @RobLoach

I was able to compile and build for all the systems, but then in the last one (emscripten), I noticed a thing: There are many systems with -DLIBRETRO_STATIC=ON build pipelines expecting a single .a static file as the output of cmake --build.

Like in: GameCube, 3DS, Wii, WiiU and Emscripten.

Currently, after building for those systems, I get many files. like:

ls build/ngc/lib/
libblipbuf.a          libjanet.a            liblua.a              libpng.a              libquickjs.a          libwasm.a             libzlib.a             
libfennel.a           libjs.a               libluaapi.a           libpocketpy.a         libsquirrel.a         libwren.a             tic80_libretro_ngc.a  
libgiflib.a           liblpeg.a             libmoon.a             libpython.a           libtic80core.a        libyuescript.a

and:

ls build/emscripten/lib/
libblipbuf.a  libgiflib.a  liblua.a     libmoon.a  libpocketpy.a  libsquirrel.a   libwasm.a  libzlib.a
libfennel.a   liblpeg.a    libluaapi.a  libpng.a   libpython.a    libtic80core.a  libwren.a  tic80_libretro_emscripten.bc

I noticed the problem because the emscripten pipeline has a build step using the .bc file, and I was getting:

2.973 LD tic80_libretro.js <obj> libretro_emscripten.a -s USE_ZLIB=1 -lm -L. --no-heap-copy -s STACK_SIZE=4194304 -s INITIAL_MEMORY=134217728 -s EXPORTED_RUNTIME_METHODS=callMain,FS,PATH,ERRNO_CODES,ENV,stringToNewUTF8,UTF8ToString,Browser,EmscriptenSendCommand,EmscriptenReceiveCommandReply -s EXIT_RUNTIME=1 -s ALLOW_MEMORY_GROWTH=1 -s EXPORTED_FUNCTIONS=_main,_malloc,_free,_cmd_savefiles,_cmd_save_state,_cmd_load_state,_cmd_undo_save_state,_cmd_undo_load_state,_cmd_toggle_fullscreen,_cmd_take_screenshot, _cmd_toggle_menu,_cmd_reload_config,_cmd_toggle_grab_mouse,_cmd_toggle_game_focus,_cmd_reset,_cmd_toggle_pause,_cmd_pause,_cmd_unpause, _cmd_set_volume,_cmd_set_shader,_cmd_cheat_set_code,_cmd_cheat_get_code,_cmd_cheat_toggle_index,_cmd_cheat_get_code_state,_cmd_cheat_realloc, _cmd_cheat_get_size,_cmd_cheat_apply_cheats,EmscriptenSendCommand,EmscriptenReceiveCommandReply -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME=libretro_tic80 -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 -s ENVIRONMENT=web,worker -s WASM_BIGINT=1 --extern-pre-js emscripten/extern_pre.js --js-library emscripten/library_rwebcam.js --js-library emscripten/library_platform_emscripten.js -s FULL_ES2=1 -s MIN_WEBGL_VERSION=1 -s MAX_WEBGL_VERSION=2 --js-library emscripten/library_rwebaudio.js -O3
3.087 cache:INFO: generating system asset: symbol_lists/720b9b294f8ae8db0b8298add470417d49e0dc79.json... (this will be cached in "/wrk/.cache/emscripten/symbol_lists/720b9b294f8ae8db0b8298add470417d49e0dc79.json" for subsequent builds)
3.256 cache:INFO:  - ok
3.257 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libGL-webgl2.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libGL-webgl2.a" for subsequent builds)
3.464 system_libs:INFO: compiled 4 inputs
3.514 cache:INFO:  - ok
3.514 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libal.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libal.a" for subsequent builds)
3.630 system_libs:INFO: compiled 1 inputs
3.680 cache:INFO:  - ok
3.680 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libhtml5.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libhtml5.a" for subsequent builds)
3.798 system_libs:INFO: compiled 3 inputs
3.850 cache:INFO:  - ok
3.850 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libstubs.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libstubs.a" for subsequent builds)
3.967 system_libs:INFO: compiled 2 inputs
4.016 cache:INFO:  - ok
4.017 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libc.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libc.a" for subsequent builds)
22.49 system_libs:INFO: compiled 1025 inputs
22.59 cache:INFO:  - ok
22.59 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libdlmalloc.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libdlmalloc.a" for subsequent builds)
22.96 system_libs:INFO: compiled 1 inputs
23.01 cache:INFO:  - ok
23.01 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libcompiler_rt.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libcompiler_rt.a" for subsequent builds)
25.57 system_libs:INFO: compiled 175 inputs
25.63 cache:INFO:  - ok
25.63 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libc++-noexcept.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libc++-noexcept.a" for subsequent builds)
31.26 system_libs:INFO: compiled 49 inputs
31.33 cache:INFO:  - ok
31.33 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libc++abi-noexcept.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libc++abi-noexcept.a" for subsequent builds)
32.80 system_libs:INFO: compiled 16 inputs
32.86 cache:INFO:  - ok
32.86 cache:INFO: generating system library: sysroot/lib/wasm32-emscripten/libsockets.a... (this will be cached in "/wrk/.cache/emscripten/sysroot/lib/wasm32-emscripten/libsockets.a" for subsequent builds)
33.19 system_libs:INFO: compiled 21 inputs
33.24 cache:INFO:  - ok
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_delete
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_delete
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic_api_reset
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_tick
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_sound
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_delete
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_create
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_load
33.64 wasm-ld: error: libretro_emscripten.a(tic80_libretro.c.o): undefined symbol: tic80_delete
33.64 emcc: error: '/opt/emsdk/upstream/bin/wasm-ld @/tmp/emscripten_3opme5_x.rsp.utf-8' failed (returned 1)
33.65 Makefile.emscripten:347: recipe for target 'tic80_libretro.js' failed
33.65 make: *** [tic80_libretro.js] Error 1
33.65 emmake: error: 'make -f Makefile.emscripten -j LIBRETRO=tic80 MEMORY=134217728' failed (returned 2)

So I used the Antigravity editor with Gemini, and got it to do these changes to libretro.cmake

With these changes, it compiles for all those systems. I can attach the dockerfile for each system if requested. (I'm not attaching to not make this much longer.)

Anyway, I don't know if this is the appropriated way to fix this. But this is what I got.

Collect sources, includes, and defines for a monolithic library build.
@imsys
Copy link
Contributor Author

imsys commented Mar 9, 2026

root@be42198bed11:/wrk/core# ls build/wii/lib/
tic80_libretro_wii.a
root@be42198bed11:/wrk/core# du -h build/wii/lib/tic80_libretro_wii.a 
27M     build/wii/lib/tic80_libretro_wii.a

@imsys
Copy link
Contributor Author

imsys commented Mar 9, 2026


make[1]: Leaving directory '/__w/TIC-80/TIC-80/vendor/circle-stdlib/libs/circle/boot/armstub'
Downloading LICENCE.broadcom ...
Downloading COPYING.linux ...
Downloading bootcode.bin ...
Downloading start.elf ...
Downloading fixup.dat ...
Downloading start4.elf ...
Downloading fixup4.dat ...
Downloading start_cd.elf ...
Downloading fixup_cd.dat ...
Downloading start4cd.elf ...
Downloading fixup4cd.dat ...
Downloading bcm2710-rpi-zero-2-w.dtb ...
Downloading bcm2711-rpi-4-b.dtb ...
Downloading bcm2711-rpi-400.dtb ...
Downloading bcm2711-rpi-cm4.dtb ...
Downloading bcm2712-rpi-5-b.dtb ...
make: *** [Makefile:29: firmware] Error 8

Baremetal basically failed on this Makefile:

# Use firmware revision built/committed on: Feb 29 2024
FIRMWARE ?= dc94391863445ab867782d25ca6ae1e88579df5d

BASEURL = https://github.com/raspberrypi/firmware/blob/$(FIRMWARE)/boot

FILES = LICENCE.broadcom COPYING.linux \
        bootcode.bin start.elf fixup.dat start4.elf fixup4.dat \
        start_cd.elf fixup_cd.dat start4cd.elf fixup4cd.dat \
        bcm2710-rpi-zero-2-w.dtb bcm2711-rpi-4-b.dtb bcm2711-rpi-400.dtb bcm2711-rpi-cm4.dtb \
        bcm2712-rpi-5-b.dtb

FILES32 = armstub7-rpi4.bin kernel.img kernel7.img kernel7l.img
FILES64 = armstub8-rpi4.bin kernel8.img kernel8-rpi4.img kernel_2712.img

firmware: clean
        @for file in $(FILES) ; \
        do \
                echo Downloading $$file ... ; \
                wget -q -O $$file $(BASEURL)/$$file?raw=true ; \
        done

@imsys imsys mentioned this pull request Mar 10, 2026
1 task
@imsys imsys marked this pull request as draft March 10, 2026 14:01
Copy link
Contributor

@RobLoach RobLoach left a comment

Choose a reason for hiding this comment

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

Is there anything else needed for this?

Copy link
Contributor

@RobLoach RobLoach left a comment

Choose a reason for hiding this comment

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

Oh, I guess just get bare metal to pass.

@imsys imsys marked this pull request as ready for review March 16, 2026 14:12
@imsys
Copy link
Contributor Author

imsys commented Mar 16, 2026

Oh, I guess just get bare metal to pass.

That was an unrelated thing. I already fixed in another PR.

Copy link
Contributor

@RobLoach RobLoach left a comment

Choose a reason for hiding this comment

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

🔥

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