diff --git a/dev.py b/dev.py index 7ed720a134..e330507a4c 100644 --- a/dev.py +++ b/dev.py @@ -36,6 +36,15 @@ PIP_MIN_VERSION = "23.1" +if __import__("sysconfig").get_config_var("HOST_GNU_TYPE").find('wasm') >= 0: + if __import__("sysconfig").get_config_var("HOST_GNU_TYPE").find('wasi') >= 0: + WASM = 'wasi' + else: + WASM = 'emscripten' +else: + WASM = '' + + class Colors(Enum): RESET = "\033[0m" RED = "\033[31m" @@ -231,6 +240,18 @@ def cmd_build(self): f"-Cbuild-dir=.mesonpy-build{build_suffix}", ] + if WASM: + stripped = True + install_args.extend( + [ + f'--config-settings=setup-args=--cross-file={os.getcwd()}/meson-cross-{WASM}.ini', + "-Csetup-args=-Dmidi=disabled", + '-Csetup-args=-Dc_args=-DBUILD_STATIC -DNO_SDL2', + '-Csetup-args=-Dc_link_args=-lfreetype -lharfbuzz -lSDL2_ttf -lSDL2_image -logg -lvorbis -lSDL2_mixer_ogg', + ] + ) + wheel_dir = Path("./whl") + if not wheel_dir: # editable install if not quiet: @@ -261,6 +282,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 +489,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 +512,12 @@ def prep_env(self): deps = self.deps.get(self.args["command"], set()) ignored_deps = self.args["ignore_dep"] + + if WASM: + ignored_deps = list(deps) + print("IGNORING:", ignored_deps) + deps.clear() + deps_filtered = deps.copy() if ignored_deps: for constr in deps: diff --git a/meson-cross-emscripten.ini b/meson-cross-emscripten.ini new file mode 100644 index 0000000000..474de1c0d5 --- /dev/null +++ b/meson-cross-emscripten.ini @@ -0,0 +1,14 @@ +[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' +pkgconfig_path = '/opt/python-wasm-sdk/devices/x86_64/usr/bin/pkgconfig' diff --git a/meson.build b/meson.build index 890336cdcf..df59c45862 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 : [ '', @@ -244,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 @@ -299,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, @@ -311,7 +316,16 @@ 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 +337,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 +353,7 @@ if portmidi_dep.found() portmidi_deps += porttime_dep endif endif +endif pg_base_deps = [sdl_dep, py_dep] diff --git a/src_c/meson.build b/src_c/meson.build index 0c1479a812..ac95338b4d 100644 --- a/src_c/meson.build +++ b/src_c/meson.build @@ -1,5 +1,4 @@ # first the "required" modules - base = py.extension_module( 'base', 'base.c', @@ -9,6 +8,8 @@ base = py.extension_module( subdir: pg, ) +if host_machine.system() != 'emscripten' + color = py.extension_module( 'color', 'color.c', @@ -458,3 +459,10 @@ if portmidi_dep.found() subdir: pg, ) endif + +else # !emscripten +# TODO: sizes ! +if sdl_api != 3 +subdir('_sdl2') +endif +endif # emscripten