Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions meson-cross-emscripten.ini
Original file line number Diff line number Diff line change
@@ -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'
25 changes: 19 additions & 6 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
Expand Down Expand Up @@ -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 : [
'',
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -341,6 +353,7 @@ if portmidi_dep.found()
portmidi_deps += porttime_dep
endif
endif
endif

pg_base_deps = [sdl_dep, py_dep]

Expand Down
10 changes: 9 additions & 1 deletion src_c/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# first the "required" modules

base = py.extension_module(
'base',
'base.c',
Expand All @@ -9,6 +8,8 @@ base = py.extension_module(
subdir: pg,
)

if host_machine.system() != 'emscripten'

color = py.extension_module(
'color',
'color.c',
Expand Down Expand Up @@ -458,3 +459,10 @@ if portmidi_dep.found()
subdir: pg,
)
endif

else # !emscripten
# TODO: sizes !
if sdl_api != 3
subdir('_sdl2')
endif
endif # emscripten