Commit graph

1967 commits

Author SHA1 Message Date
刘皓
e346343be4
Fix memory leaks in sandbox-bindgen 2025-01-19 21:10:53 -05:00
刘皓
379c22833f
Store coroutine variables in the Ruby stack in libretro builds
To stop Ruby's garbage collector from freeing Ruby `VALUE`s while we're
in the middle of using them in libretro builds, we need to make sure all
the `VALUE`s we use are on the sandbox's stack.

Also, to allow Ruby to recognize `VALUE`s on the sandbox's stack on
big-endian targets, I've changed the serialization of `VALUE`s. Before,
any `VALUE`s returned by a sandbox function were always converted to the
target's endian, and any `VALUE`s passed to sandbox functions as
argument were then converted back to WebAssembly's endianness,
little-endian. Now, `VALUE`s are always little-endian; they are no
longer converted to the target's endianness. That should be fine since
`VALUE`s are supposed to be opaque values.
2025-01-19 19:08:03 -05:00
刘皓
835795a0c6
Use different Ruby command-line arguments in libretro builds
I've decided to stop gambling with ways to make `-e` not crash Ruby on
startup in libretro builds (see commit
1473416a5a for context). Making Ruby load
a dummy script seems to work better.
2025-01-19 11:56:47 -05:00
刘皓
d7d460d6b0
Small fixes to the sandbox bindings 2025-01-19 11:30:55 -05:00
刘皓
fe5a94aea7
Implement loading scripts from Scripts.rxdata for libretro 2025-01-18 18:51:29 -05:00
刘皓
f10dc81410
Add more sandbox bindings 2025-01-18 13:51:58 -05:00
刘皓
94e8d4607d
Fix sandbox bindings for Ruby globals
It has come to light that the global bindings generated by wasm2c are
not the globals themselves, but rather pointers to the memory locations
where the globals are stored. I've updated sandbox-bindgen.rb to take
this into account.
2025-01-18 01:43:52 -05:00
刘皓
9edac122fb
Add sandbox bindings for Ruby constants and use zstd compression for libretro Ruby dist 2025-01-17 22:04:42 -05:00
刘皓
e4acdeb9e7
Switch libretro phase 1 CI from ubuntu-24.04 to ubuntu-latest
Now that GitHub has finished upgrading the `ubuntu-latest` image to
Ubuntu 24.04, we can just use `ubuntu-latest`. We need at least Ubuntu
24.04 because the version of WABT from earlier versions of Ubuntu is too
old.
2025-01-17 11:13:57 -05:00
刘皓
1473416a5a
Fix crashes when starting up libretro Ruby sandbox (hopefully)
Guys, I think I'm going insane. Every time I build the libretro Ruby
sandbox with a different version of Ruby, or even when I build Ruby at a
different path on my computer, there's some chance that the builds
produced with that version of Ruby and/or that path on my computer
result in Ruby crashing on startup in libretro builds. I've been
tweaking these command-line arguments that are passed to Ruby for a
while now, and I *think* these are the correct ones that will stop Ruby
from crashing.
2025-01-17 01:23:18 -05:00
刘皓
510f1b0211
Move sandbox files to binding-sandbox directory 2025-01-16 22:16:14 -05:00
刘皓
474e1f536a
Fix libretro Alpine Linux armv6 build 2025-01-16 18:48:23 -05:00
刘皓
53a638ab74
Update non-libretro CI
GitHub has deprecated some of the v3 actions, so I've updated them to
v4.
2025-01-16 14:43:37 -05:00
刘皓
16f21ff043
Disable -fPIC when building for PlayStation Portable
The PSPDEV toolchain doesn't seem to support position independent code.
2025-01-16 11:49:11 -05:00
刘皓
0602c97a0a
Fix dependency compilation errors when compiling for Nintendo consoles 2025-01-16 01:33:44 -05:00
刘皓
44b8d13ff8
Add Nintendo consoles, PS2 and PSP to libretro CI
I'll also add PlayStation Vita and Xbox once I figure out how.

Other than that, I think that's all the game consoles RetroArch supports
that aren't Linux-based!
2025-01-15 22:10:50 -05:00
刘皓
fe5e23a5bc
Fix crash when libretro core is reset 2025-01-15 18:28:22 -05:00
刘皓
de0c5b8f4a
Raise Android API version to 24 for 32-bit Android targets 2025-01-14 21:34:23 -05:00
刘皓
b1131c1a7b
Fix Android libretro builds 2025-01-14 18:51:56 -05:00
刘皓
688544096f
Add Alpine Linux and Android to libretro CI 2025-01-13 23:09:39 -05:00
刘皓
e31dd0f32e
Improve compilation flags for libretro builds 2025-01-10 17:57:10 -05:00
刘皓
4c0ab3639b
Implement handling of fibers and exception catching in libretro sandbox runtime 2025-01-10 00:47:52 -05:00
刘皓
2a204178fe
Implement stackful coroutine-based executor for libretro builds
This executor has the advantage of being able to work correctly when
there are Ruby stack frames underneath C/C++ stack frames in the stack.

Still need to implement handling Ruby fibers.
2025-01-08 19:39:48 -05:00
刘皓
4a94a326b5
Fix libretro phase 1 Makefile and enable stripping in libretro CI
Apparently passing extra tools into `NATIVE_TOOLCHAIN` and
`WASI_TOOLCHAIN` in the phase 1 Makefile breaks libretro builds in
GitHub Actions - binaries built using those phase 1 files are unable to
start up the Ruby VM, although there are no compilation errors. Doesn't
happen when I build phase 1 on my computer though... Nonetheless, I've
removed the extra stuff from `NATIVE_TOOLCHAIN` and `WASI_TOOLCHAIN` in
the Makefile.

Also I've added code into the GitHub Actions workflows to strip the
libretro cores. Enabling LTO in GitHub Actions caused the libretro cores
produced to swell to enormous size compared to when built without LTO
due to the extra debug information added by LTO. However, with stripping
enabled, stripped binaries built with LTO are actually somewhat smaller
than stripped binaries built without LTO.
2025-01-07 18:44:05 -05:00
刘皓
c4d5d8af97
Turn all sandbox bindings into coroutines
We can't have them as normal functions because reentrant calls into the
Ruby API don't work if you do that, i.e. calling into the Ruby API and
that calls mkxp-z's bindings and that calls back into the Ruby API.
2025-01-07 00:02:09 -05:00
刘皓
c4cb891e37
Enable LTO in libretro CI 2025-01-06 20:38:31 -05:00
刘皓
1413feec51
Improve the Makefile for phase 1
* Ruby is no longer required to be already installed to build phase 1
* Commands and versions for everything are now configurable
* The `-j` Make flag is now respected
2025-01-05 22:14:24 -05:00
刘皓
2dbbfd57b4
Use WASI SDK C compiler for preprocessing Ruby headers instead of native C compiler 2025-01-05 17:03:17 -05:00
刘皓
1439b3181d
Use C compiler to preprocess Ruby headers before passing to Ctags
Ctags by itself misses a few functions defined in the Ruby API.
2025-01-05 16:42:48 -05:00
刘皓
19cafa332c
Fix array indexing in sandbox-bindgen.rb 2025-01-05 13:08:33 -05:00
刘皓
7de761873c
Fix _sbindgen_create_func_ptr() implementation 2025-01-04 22:27:02 -05:00
刘皓
3e79e8b390
Add binding generator for Ruby in libretro builds 2025-01-04 18:13:44 -05:00
刘皓
adf4fbf758
Rename lzma subproject to liblzma 2025-01-03 17:42:44 -05:00
刘皓
5cf4e8716b
Improve path normalization in wasi.cpp 2025-01-03 17:29:58 -05:00
刘皓
886fa6b96f
Remove malloc() and free() as much as possible in wasi.cpp 2025-01-03 14:06:35 -05:00
刘皓
d18704d76f
Fix memory leaks in wasi.cpp 2025-01-03 12:22:29 -05:00
刘皓
acb55e42bd
Add the -static flag back into Windows builds
Meson documentation lied to me...
2025-01-03 01:35:35 -05:00
刘皓
e6a6288fc4
Fix libretro Linux builds 2025-01-03 01:20:22 -05:00
刘皓
075a997d8c
Fix undefined behaviour in w2c_wasi__snapshot__preview1 constructor 2025-01-03 00:57:20 -05:00
刘皓
caf0f7ef32
Statically link C++ standard library and libpthread on libretro Windows 2025-01-03 00:04:21 -05:00
刘皓
e581b58305
Use GNU patch in libretro macOS CI instead of BSD patch 2025-01-02 20:40:11 -05:00
刘皓
ff6d72f617
Fix LZMA compilation error on Windows 2025-01-02 19:15:15 -05:00
刘皓
cc52f2e332
Make libzip Meson subproject use header files from the other Meson subprojects 2025-01-02 18:54:50 -05:00
刘皓
77b7dda096
Add all dependencies of libretro build as Meson subprojects 2025-01-02 17:51:22 -05:00
刘皓
54f9055ee1
Remove useless enormous file from Ruby in libretro builds 2025-01-02 12:10:31 -05:00
刘皓
d099f485fd
Change Ruby command-line arguments in libretro builds
The old arguments were invoking undefined behaviour that may or may not
cause crashes when initializing Ruby depending on which path on the
build machine Ruby was built on!
2025-01-02 11:51:55 -05:00
刘皓
7f4a5f46f8
Add -v to ninja command in libretro CI
To help with debugging.
2025-01-02 00:17:30 -05:00
刘皓
ee7ea872a3
Fix libretro Windows builds not being uploaded 2025-01-01 18:14:40 -05:00
刘皓
a32646ff72
Define WABT_BIG_ENDIAN=1 on big-endian hosts
WebAssembly is little-endian regardless of what machine you run it on,
so the WebAssembly implementation needs to know if the machine is
big-endian or little-endian to function properly.
2025-01-01 17:36:52 -05:00
刘皓
ca6fb125c1
Make sure exported libretro/WASI functions match the required signatures
Apparently `environ` is some kind of reserved word in MSYS2's build
environment, which caused hard-to-understand linking errors on Windows
due to one of the functions in wasi.cpp having an argument named
`environ`. I've changed the name of the offending argument to `env`.

I've also added `extern "C"` to all exported functions to make sure
something like this doesn't happen again - the compiler should now
refuse to compile the code if there are function signature mismatches in
exported functions.
2025-01-01 17:17:52 -05:00