From a44f3b16b33d9673e1187284eb7cd6d355d95ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Fri, 24 Jan 2025 23:56:00 -0500 Subject: [PATCH] Add SDL headers and PhysFS to libretro builds I don't think I'll be needing SDL. Pretty sure about 100% of the functionality of SDL that's currently being used here is either trivial to reimplement or needs to be replaced for the libretro core to work in the first place. For example, I already know I'm going to need to completely replace the SDL input handling with libretro's input API. Also, I'll need to get rid of the use of SDL threads in the audio code later because libretro cores need to render audio synchronously with the video rendering. I'm including the SDL headers, though, to reduce the number of compilation errors. --- meson.build | 11 +++++++++++ retro/Makefile | 9 ++++++++- src/etc/etc-internal.h | 12 +----------- subprojects/physfs.wrap | 4 ++++ 4 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 subprojects/physfs.wrap diff --git a/meson.build b/meson.build index 00c3b126..3b2cdbbd 100644 --- a/meson.build +++ b/meson.build @@ -98,6 +98,15 @@ if get_option('retro') == true 'ENABLE_ZSTD': true, }) + physfs_options = cmake.subproject_options() + physfs_options.add_cmake_defines({ + 'CMAKE_POSITION_INDEPENDENT_CODE': get_option('b_staticpic'), + 'PHYSFS_BUILD_STATIC': true, + 'PHYSFS_BUILD_SHARED': false, + 'PHYSFS_BUILD_TEST': false, + 'PHYSFS_BUILD_DOCS': false, + }) + openal_options = cmake.subproject_options() openal_options.add_cmake_defines({ 'CMAKE_POSITION_INDEPENDENT_CODE': get_option('b_staticpic'), @@ -174,6 +183,7 @@ if get_option('retro') == true cmake.subproject('liblzma', options: liblzma_options).dependency('liblzma'), cmake.subproject('zstd', options: zstd_options).dependency('libzstd_static'), cmake.subproject('libzip', options: libzip_options).dependency('zip'), + cmake.subproject('physfs', options: physfs_options).dependency('physfs-static'), cmake.subproject('openal-soft', options: openal_options).dependency('OpenAL'), ], c_args: [ @@ -200,6 +210,7 @@ if get_option('retro') == true include_directories(retro_phase1), include_directories(join_paths(retro_phase1, 'wasm2c')), include_directories(join_paths(retro_phase1, 'mkxp-retro-ruby')), + include_directories(join_paths(retro_phase1, 'sdl/include')), ], sources: [ 'src/core.cpp', diff --git a/retro/Makefile b/retro/Makefile index a119f2de..283739e8 100644 --- a/retro/Makefile +++ b/retro/Makefile @@ -6,6 +6,7 @@ LIBYAML_VERSION ?= 0.2.5 ZLIB_VERSION ?= 1.3.1 OPENSSL_VERSION ?= 3.2.0 WASM_RT_VERSION ?= 1.0.36 +SDL_VERSION ?= 2.30.11 P7ZIP_VERSION ?= 17.06 TARGET ?= wasm32-wasip1 WASI_SDK ?= /opt/wasi-sdk @@ -51,7 +52,7 @@ ruby-dist: $(OUTDIR)/mkxp-retro-dist.zip.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro- ruby-bindings: $(OUTDIR)/mkxp-sandbox-bindgen.cpp $(OUTDIR)/mkxp-sandbox-bindgen.h -deps: $(OUTDIR)/libretro.h $(OUTDIR)/wasm2c/wasm-rt.h $(OUTDIR)/wasm2c/wasm-rt-impl.c $(OUTDIR)/wasm2c/wasm-rt-mem-impl.c +deps: $(OUTDIR)/libretro.h $(OUTDIR)/wasm2c/wasm-rt.h $(OUTDIR)/wasm2c/wasm-rt-impl.c $(OUTDIR)/wasm2c/wasm-rt-mem-impl.c $(OUTDIR)/sdl/include/SDL.h clean: clean-ruby-dist clean-ruby-bindings clean-deps rm -rf $(LIBDIR)/* @@ -70,6 +71,7 @@ clean-ruby-bindings: clean-deps: rm -f $(OUTDIR)/libretro.h rm -rf $(OUTDIR)/wasm2c + rm -rf $(OUTDIR)/sdl rm -rf $(DOWNLOADS)/wabt $(OUTDIR)/libretro.h: @@ -77,11 +79,16 @@ $(OUTDIR)/libretro.h: $(CURL) -s -L -o $(OUTDIR)/libretro.h https://raw.githubusercontent.com/libretro/libretro-common/$(LIBRETRO_REF)/include/libretro.h $(OUTDIR)/wasm2c/wasm-rt.h $(OUTDIR)/wasm2c/wasm-rt-impl.c $(OUTDIR)/wasm2c/wasm-rt-mem-impl.c &: + mkdir -p $(DOWNLOADS) mkdir -p $(OUTDIR) $(CLONE) $(GITHUB)/WebAssembly/wabt $(DOWNLOADS)/wabt -b $(WASM_RT_VERSION) $(SED) -i 's/# *define * WASM_RT_C11_AVAILABLE//g' $(DOWNLOADS)/wabt/wasm2c/wasm-rt.h # Stop wasm-rt from trying to use threads because it causes compiler errors on some game console toolchains, and also because OpenAL Soft defines a header file named "threads.h" which conflicts with the C11 threads.h that this file tries to include cp -r $(DOWNLOADS)/wabt/wasm2c $(OUTDIR) +$(OUTDIR)/sdl/include/SDL.h: + mkdir -p $(OUTDIR) + $(CLONE) $(GITHUB)/libsdl-org/SDL $(OUTDIR)/sdl -b release-$(SDL_VERSION) + # Cross Ruby (targets WASI) $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby.h $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby-impl.h $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_0.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_1.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_2.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_3.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_4.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_5.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_6.c $(OUTDIR)/mkxp-retro-ruby/mkxp-retro-ruby_7.c &: $(LIBDIR)/mkxp-retro-dist/bin/ruby diff --git a/src/etc/etc-internal.h b/src/etc/etc-internal.h index c1a7e4f5..5ddce747 100644 --- a/src/etc/etc-internal.h +++ b/src/etc/etc-internal.h @@ -24,17 +24,7 @@ #include "util.h" -#ifdef MKXPZ_RETRO -struct SDL_Rect -{ - int x; - int y; - int w; - int h; -}; -#else -# include -#endif // MKXPZ_RETRO +#include struct Vec2 { diff --git a/subprojects/physfs.wrap b/subprojects/physfs.wrap new file mode 100644 index 00000000..1b4154ad --- /dev/null +++ b/subprojects/physfs.wrap @@ -0,0 +1,4 @@ +[wrap-git] +url = https://github.com/icculus/physfs +revision = release-3.2.0 +depth = 1