Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025

This PR adds a complete pygame-ce recipe for building the pygame Community Edition on the emscripten-wasm32 platform (WebAssembly).

The recipe includes:

  • Proper meson cross-compilation setup: Uses meson-python with a dedicated emscripten.meson.cross file and proper cross-file configuration to enable cross-compilation for WebAssembly
  • SDL2 dependencies setup: Configures SDL2 and its extensions (SDL2_image, SDL2_mixer, SDL2_ttf) using emscripten's embuilder with correct port names (using underscores instead of hyphens)
  • Python integration: Comprehensive import tests to verify pygame modules are correctly built and accessible
  • Dependency alignment: All dependencies properly configured to match pygame-ce requirements for the WebAssembly target
  • Upstream patch: Includes a patch to enable experimental emscripten support in pygame-ce's meson.build by converting the emscripten error to a warning

The build process leverages emscripten's built-in SDL2 ports and uses the standard meson cross-compilation workflow for Python extensions targeting WebAssembly. The cross-compilation configuration ensures meson properly detects this as a cross-compilation build, resolving the "Emscripten compiler can only be used for cross compilation" error. The patch addresses pygame-ce's upstream restriction that prevents building for emscripten by modifying the build system to allow experimental WebAssembly support.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@DerThorsten
Copy link
Contributor

@copilot try again

Copy link
Contributor Author

Copilot AI commented Sep 3, 2025

@copilot try again

I've created the pygame-ce recipe for emscripten-wasm32. The recipe includes:

  • Proper meson-python build system configuration
  • SDL2 and SDL2 extensions setup via embuilder
  • Import tests for pygame modules
  • Dependencies aligned with pygame-ce requirements

The recipe is now ready for testing. Commit: 349ca5c

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/pygame-community/pygame-ce
    • Triggering command: python -c import requests try: response = requests.get('REDACTED', timeout=10) if response.status_code == 200: data = response.json() print('GitHub URL:', data['html_url']) print('Clone URL:', data['clone_url']) print('Description:', data['description']) print('Language:', data['language']) print('Stars:', data['stargazers_count']) else: print('Failed to fetch GitHub info') except Exception as e: print('Error:', e) (http block)
  • pixi.sh
    • Triggering command: curl -fsSL REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@Copilot Copilot AI changed the title [WIP] pygame-ce Add pygame-ce recipe for emscripten-wasm32 Sep 3, 2025
Copilot finished work on behalf of DerThorsten September 3, 2025 08:05
@IsabelParedes
Copy link
Member

@copilot fix embuilder:ERROR: unfamiliar build target: sdl2-image

Copy link
Contributor Author

Copilot AI commented Sep 5, 2025

@copilot fix embuilder:ERROR: unfamiliar build target: sdl2-image

Fixed the SDL2 extension target naming issue. Changed from hyphens to underscores (sdl2-imagesdl2_image, etc.) to match Emscripten's port naming convention. Commit: 233b669

Copy link
Member

@IsabelParedes IsabelParedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot add an emscripten.meson.cross file

Copy link
Contributor Author

Copilot AI commented Sep 5, 2025

@copilot add an emscripten.meson.cross file

Added emscripten.meson.cross file with the standard configuration for meson-python cross-compilation to WebAssembly. This includes the necessary host machine settings, execution wrapper, and build properties. Commit: 8e47ac9

Copy link
Member

@IsabelParedes IsabelParedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot enable cross-compilation

../meson.build:1:0: ERROR: Emscripten compiler can only be used for cross compilation.

Copy link
Contributor Author

Copilot AI commented Sep 5, 2025

@copilot enable cross-compilation

../meson.build:1:0: ERROR: Emscripten compiler can only be used for cross compilation.

...

Fixed the cross-compilation issue by properly configuring the meson cross-file. Added MESON_CROSS_FILE environment variable and passed it to pip install with -Csetup-args="--cross-file=$MESON_CROSS_FILE". Also reorganized the cross file to match the format of other successful recipes. Commit: 0abb9c2

@Copilot Copilot AI changed the title Add pygame-ce recipe for emscripten-wasm32 Add pygame-ce recipe for emscripten-wasm32 with cross-compilation support Sep 5, 2025
@Copilot Copilot AI requested a review from IsabelParedes September 5, 2025 12:31
Copy link
Member

@IsabelParedes IsabelParedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot create a patch for fix

 ../meson.build:38:4: ERROR: Problem encountered: The meson buildconfig of pygame-ce does not support emscripten for now.  However it may be added in the future

Copy link
Contributor Author

Copilot AI commented Sep 9, 2025

@copilot create a patch for fix

 ../meson.build:38:4: ERROR: Problem encountered: The meson buildconfig of pygame-ce does not support emscripten for now.  However it may be added in the future

...

Created a patch to fix the emscripten support issue. Changed the error() call to warning() in pygame-ce's meson.build file to allow building for WebAssembly. The patch specifically targets the emscripten check at line 38 and enables experimental emscripten support. Commit: a2267a4

@Copilot Copilot AI changed the title Add pygame-ce recipe for emscripten-wasm32 with cross-compilation support Add pygame-ce recipe for emscripten-wasm32 with cross-compilation support and upstream patch Sep 9, 2025
@Copilot Copilot AI requested a review from IsabelParedes September 9, 2025 12:38
Copilot finished work on behalf of IsabelParedes September 9, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants