From 099558d7adc015c749c9b44c7c43a6425ed5fb5d Mon Sep 17 00:00:00 2001 From: pmp-p Date: Fri, 18 Jul 2025 13:04:26 +0200 Subject: [PATCH 1/2] meson (python-wasm-sdk) --- dev.py | 20 ++++++++++++++++++++ meson-python-cross-file.ini | 13 +++++++++++++ meson.build | 15 +++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 meson-python-cross-file.ini diff --git a/dev.py b/dev.py index 7ed720a134..05c43e6a10 100644 --- a/dev.py +++ b/dev.py @@ -34,6 +34,7 @@ # We assume this script works with any pip version above this. PIP_MIN_VERSION = "23.1" +WASM = __import__("sysconfig").get_config_var("HOST_GNU_TYPE").find('wasm') >= 0 class Colors(Enum): @@ -231,6 +232,15 @@ def cmd_build(self): f"-Cbuild-dir=.mesonpy-build{build_suffix}", ] + if WASM: + stripped = True + install_args.append( + f'--config-settings=setup-args=--cross-file={os.getcwd()}/meson-python-cross-file.ini' + ) + install_args.append( + "-Csetup-args=-Dmidi=disabled", + ) + wheel_dir = Path("./whl") if not wheel_dir: # editable install if not quiet: @@ -261,6 +271,7 @@ def cmd_build(self): info_str = ( f"with {debug=}, {lax=}, {sdl3=}, {stripped=}, {coverage=} and {sanitize=}" ) + if wheel_dir: pprint(f"Building wheel at '{wheel_dir}' ({info_str})") cmd_run( @@ -467,6 +478,9 @@ def prep_env(self): bin = venv_path / "Scripts" if os.name == "nt" else venv_path / "bin" self.py = bin / "python" else: + if WASM: + if os.environ.get('EMSDK', None): + self.py = Path(os.environ.get('SDKROOT') + "/python3-wasm") pprint(f"Using python '{self.py}'") # set PATH to give high priority to executables in the python bin folder @@ -487,6 +501,12 @@ def prep_env(self): deps = self.deps.get(self.args["command"], set()) ignored_deps = self.args["ignore_dep"] + + if WASM: + print("IGNORING:", deps) + ignored_deps = list(deps) + deps.clear() + deps_filtered = deps.copy() if ignored_deps: for constr in deps: diff --git a/meson-python-cross-file.ini b/meson-python-cross-file.ini new file mode 100644 index 0000000000..ff40f27510 --- /dev/null +++ b/meson-python-cross-file.ini @@ -0,0 +1,13 @@ +[host_machine] +system = 'emscripten' +cpu_family = 'wasm' +cpu = 'wasm' +endian = 'little' + +[binaries] +c = 'emcc' +cpp = 'em++' +ar = 'llvm-ar' +strip = 'llvm-strip' +exe_wrapper = 'node' + diff --git a/meson.build b/meson.build index 890336cdcf..44472b459e 100644 --- a/meson.build +++ b/meson.build @@ -35,7 +35,7 @@ elif host_machine.system() == 'android' ) elif host_machine.system() == 'emscripten' plat = 'emscripten' - error( + warning( 'The meson buildconfig of pygame-ce does not support emscripten for now. ', 'However it may be added in the future', ) @@ -229,7 +229,8 @@ if plat == 'win' and host_machine.cpu_family().startswith('x86') install_data(dlls, install_dir: pg_dir, install_tag: 'pg-tag') else - bases = ['/usr/local', '/usr', '/opt/homebrew', '/opt/local'] +# bases = ['/usr/local', '/usr', '/opt/homebrew', '/opt/local'] + bases = ['/opt/python-wasm-sdk/emsdk/upstream/emscripten/cache/sysroot', '/opt/python-wasm-sdk/devices/emsdk/usr'] foreach inc_dir : bases foreach sub_inc : [ '', @@ -311,7 +312,14 @@ if not freetype_dep.found() ) endif + portmidi_dep = dependency('portmidi', required: false) + +portmidi_deps = [] + +if get_option('midi').disabled() + # disable pypm build +else if not portmidi_dep.found() portmidi_dep = declare_dependency( include_directories: pg_inc_dirs, @@ -323,8 +331,6 @@ if not portmidi_dep.found() ) endif -portmidi_deps = [portmidi_dep] - if portmidi_dep.found() # porttime can be a separate library, or be inbuilt in portmidi. # So if it is available as a separate library, include it as a dependency @@ -341,6 +347,7 @@ if portmidi_dep.found() portmidi_deps += porttime_dep endif endif +endif pg_base_deps = [sdl_dep, py_dep] From f5d84af6d37af7b096cd7bf73f3fe4a6198dba07 Mon Sep 17 00:00:00 2001 From: pmp-p Date: Sat, 19 Jul 2025 03:10:59 +0200 Subject: [PATCH 2/2] no _sdl2/* but static load ok --- dev.py | 3 +++ meson-python-cross-file.ini | 3 ++- meson.build | 10 ++++++++-- src_c/meson.build | 9 ++++++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/dev.py b/dev.py index 05c43e6a10..6368dfdff9 100644 --- a/dev.py +++ b/dev.py @@ -240,6 +240,9 @@ def cmd_build(self): install_args.append( "-Csetup-args=-Dmidi=disabled", ) + install_args.append( + '-Csetup-args=-Dc_link_args=-lfreetype -lharfbuzz -lSDL2_ttf', + ) wheel_dir = Path("./whl") if not wheel_dir: # editable install diff --git a/meson-python-cross-file.ini b/meson-python-cross-file.ini index ff40f27510..474de1c0d5 100644 --- a/meson-python-cross-file.ini +++ b/meson-python-cross-file.ini @@ -4,10 +4,11 @@ cpu_family = 'wasm' cpu = 'wasm' endian = 'little' + [binaries] c = 'emcc' cpp = 'em++' ar = 'llvm-ar' strip = 'llvm-strip' exe_wrapper = 'node' - +pkgconfig_path = '/opt/python-wasm-sdk/devices/x86_64/usr/bin/pkgconfig' diff --git a/meson.build b/meson.build index 44472b459e..df59c45862 100644 --- a/meson.build +++ b/meson.build @@ -245,7 +245,7 @@ else endforeach foreach lib_dir : bases - foreach sub_lib : ['lib', 'lib64'] + foreach sub_lib : ['lib', 'lib64', 'lib/wasm32-emscripten/pic', 'lib/wasm32-emscripten'] full_lib = lib_dir / sub_lib if fs.exists(full_lib) pg_lib_dirs += full_lib @@ -300,7 +300,11 @@ if not sdl_ttf_dep.found() ) endif -freetype_dep = dependency('freetype2', required: false) +if plat == 'emscripten' + freetype_dep = dependency('freetype2', required: false) +else + freetype_dep = dependency('freetype2', required: true) +endif if not freetype_dep.found() freetype_dep = declare_dependency( include_directories: pg_inc_dirs, @@ -313,6 +317,8 @@ if not freetype_dep.found() endif + + portmidi_dep = dependency('portmidi', required: false) portmidi_deps = [] diff --git a/src_c/meson.build b/src_c/meson.build index 0c1479a812..d590af37cf 100644 --- a/src_c/meson.build +++ b/src_c/meson.build @@ -1,14 +1,15 @@ # first the "required" modules - base = py.extension_module( - 'base', + 'pygame_static', 'base.c', c_args: warnings_error, dependencies: pg_base_deps, install: true, - subdir: pg, +# subdir: pg, ) +if host_machine.system() != 'emscripten' + color = py.extension_module( 'color', 'color.c', @@ -458,3 +459,5 @@ if portmidi_dep.found() subdir: pg, ) endif + +endif