Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKG Add pygame-ce #4602

Merged
merged 32 commits into from Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9596a36
Add pygame-ce
ryanking13 May 4, 2023
98a7af3
Fix readability
ryanking13 May 4, 2023
75ff0e1
Merge remote-tracking branch 'upstream/main' into pygame-ce
ryanking13 May 6, 2023
af6d119
Merge remote-tracking branch 'upstream/main' into pygame-ce
ryanking13 May 7, 2023
c66cb4c
Update build script
ryanking13 May 7, 2023
c12a435
Merge branch 'pyodide:main' into pygame-ce
ryanking13 Jul 29, 2023
402d56e
Sync upstream
ryanking13 Jul 29, 2023
ddd37e4
Merge branch 'pyodide:main' into pygame-ce
ryanking13 Nov 27, 2023
00c6e72
Bump pygame version
ryanking13 Nov 27, 2023
393865b
typo
ryanking13 Nov 28, 2023
55a8045
Merge remote-tracking branch 'upstream/main' into pygame-ce
ryanking13 Feb 11, 2024
91ce858
Build latest versions of libsdl2
ryanking13 Feb 11, 2024
b2444fc
Add test
ryanking13 Feb 15, 2024
9ab4c1b
Merge remote-tracking branch 'upstream/main' into pygame-ce
ryanking13 Feb 16, 2024
f0fefa7
wip
ryanking13 Feb 17, 2024
8055e67
Remove unused files
ryanking13 Feb 17, 2024
99d8dcc
Add font related patches
ryanking13 Feb 20, 2024
b876d05
Merge remote-tracking branch 'upstream/main' into pygame-ce
ryanking13 Feb 21, 2024
13317a2
Support zero dely sleep
ryanking13 Feb 21, 2024
307a112
Remove typehint
ryanking13 Feb 21, 2024
b1630aa
Revert "Remove typehint"
ryanking13 Mar 8, 2024
acd9ff2
Revert "Support zero dely sleep"
ryanking13 Mar 8, 2024
0e7a564
Merge remote-tracking branch 'upstream/main' into pygame-ce
ryanking13 Mar 8, 2024
e281ea8
Skip test in ci
ryanking13 Mar 8, 2024
2dd154c
Remove debug statements
ryanking13 Mar 8, 2024
cafc000
Bump version to 2.4.1
ryanking13 Mar 8, 2024
cca8664
Lint
ryanking13 Mar 8, 2024
96893dc
Merge remote-tracking branch 'upstream/main' into pygame-ce
ryanking13 Mar 16, 2024
2632d44
Apply patch from upstream
ryanking13 Mar 16, 2024
ed79ffe
Update docs
ryanking13 Mar 16, 2024
4cb7d17
changelog
ryanking13 Mar 16, 2024
a149897
Merge branch 'main' into pygame-ce
ryanking13 Mar 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile.envs
Expand Up @@ -149,6 +149,7 @@ export MAIN_MODULE_LDFLAGS= $(LDFLAGS_BASE) \
-legl.js \
-lwebgl.js \
-lhtml5_webgl.js \
-lsdl.js \
hoodmane marked this conversation as resolved.
Show resolved Hide resolved
-sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0


Expand Down
93 changes: 93 additions & 0 deletions packages/pygame-ce/meta.yaml
@@ -0,0 +1,93 @@
package:
name: pygame-ce
version: 2.4.1
top-level:
- pygame
source:
url: https://files.pythonhosted.org/packages/dc/b1/64fffc2c8664497ae82b2afb4f5efe0130d38b39f2d25af0288c4261df3e/pygame-ce-2.4.1.tar.gz
sha256: 70a84aa1417c633a0fd6754ffa5dc92ee1b9aeb70baaa52c8c8c94a7c6db9cf0
patches:
- patches/0001-Replace-OpenAudioDevice-with-OpenAudio.patch
- patches/0001-freetype-init.patch
- patches/0001-Don-t-set-font_initialized.patch
build:
script: |
embuilder build sdl2 sdl2_ttf sdl2_image sdl2_mixer sdl2_gfx libjpeg libpng giflib harfbuzz vorbis mpg123 libmodplug freetype --pic
export SDL_CONFIG=$(em-config CACHE)/sysroot/bin/sdl2-config
cflags: |
-sRELOCATABLE=1
-DSDL_NO_COMPAT
-DBUILD_STATIC
-ferror-limit=1
-sUSE_SDL=2
-sUSE_SDL_MIXER=2
-sSDL2_MIXER_FORMATS=mid,mod,mpg,ogg
-sUSE_SDL_TTF=2
-sUSE_SDL_IMAGE=2
-sSDL2_IMAGE_FORMATS=bmp,gif,jpg,png
-sUSE_SDL_GFX=2
-sUSE_FREETYPE=1
-sUSE_LIBJPEG=1
-sUSE_LIBPNG=1
-sUSE_GIFLIB=1
-sUSE_HARFBUZZ=1
ldflags: |
-sRELOCATABLE=1
-sUSE_SDL=2
-sUSE_SDL_MIXER=2
-sSDL2_MIXER_FORMATS=mid,mod,mpg,ogg
-sUSE_SDL_TTF=2
-sUSE_SDL_IMAGE=2
-sSDL2_IMAGE_FORMATS=bmp,gif,jpg,png
-sUSE_SDL_GFX=2
-sUSE_FREETYPE=1
-sUSE_LIBJPEG=1
-sUSE_LIBPNG=1
-sUSE_GIFLIB=1
-sUSE_HARFBUZZ=1
post: |
# Remove docs to reduce the size of a wheel
# (Perhaps also remove typeshed and examples too?)
rm -rf ./pygame/docs

# WASM version of pygame uses a single module 'pygame_static',
# and pygame_static calls PyInit_* functions from other modules.
# This is okay when all these modules are bundled in a single module: libpython.
# But as we don't do that, we need to load these modules globally, so that
# pygame_static can see the symbols.
STATIC_OBJS=$(find ${PKG_BUILD_DIR} -name "*.o")
echo "build dir: " $PKG_BUILD_DIR
echo "static objs: " $STATIC_OBJS

SHARED_LIBS=$(find ${WHEELDIR} -name "*.so" ! -name "static*.so")
echo "shared libs: " $SHARED_LIBS

emcc \
-shared \
${SIDE_MODULE_LDFLAGS} \
-fPIC \
-lSDL2 \
-lSDL2_image_bmp-gif-jpg-png \
-lSDL2_ttf \
-lSDL2_mixer_mid-mod-mpg-ogg \
-lSDL2_gfx \
-lfreetype \
-lharfbuzz \
-lpng \
-ljpeg \
-lgif \
-lvorbis \
-lmodplug \
-lmpg123 \
-logg \
${STATIC_OBJS} \
${SHARED_LIBS} \
-o pygame_static.so

# Remove duplicated static.so module
rm -f ./pygame/static*.so
about:
home: https://www.pygame.org
PyPI: https://pypi.org/project/pygame
summary: Python Game Development
license: LGPL
27 changes: 27 additions & 0 deletions packages/pygame-ce/patches/0001-Don-t-set-font_initialized.patch
@@ -0,0 +1,27 @@
From 34b1a15e94f583fa2879830cd2b1968183d8b4fa Mon Sep 17 00:00:00 2001
From: ryanking13 <def6488@gmail.com>
Date: Tue, 20 Feb 2024 22:40:02 +0900
Subject: [PATCH 1/1] Don't set font_initialized

---
src_c/font.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src_c/font.c b/src_c/font.c
index 94b50da6..1d522892 100644
--- a/src_c/font.c
+++ b/src_c/font.c
@@ -66,9 +66,7 @@ static unsigned int current_ttf_generation = 0;
(((PyFontObject *)(x))->ttf_init_generation == current_ttf_generation)

#if defined(BUILD_STATIC)
-// SDL_Init + TTF_Init() are made in main before CPython process the module
-// inittab so the emscripten handler knows it will use SDL2 next cycle.
-static int font_initialized = 1;
+static int font_initialized = 0;
Copy link
Member Author

Choose a reason for hiding this comment

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

This comment is true for pygame-web but not true for Pyodide.

cc: @pmp-p

Copy link
Contributor

Choose a reason for hiding this comment

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

i'm making pygame-community/pygame-ce#2748 so both pygame-web and pyodide do not require patching

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you so much! I don't know anything about pygame internals, so I really appreciate the various things you do for WASM support.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, we appreciate all the work you've done on this @pmp-p -- it seems like quite a lot of effort.

#else
static int font_initialized = 0;
static const char pkgdatamodule_name[] = "pygame.pkgdata";
--
2.29.2.windows.2

@@ -0,0 +1,29 @@
From 948614b9410f57c599db98c3248314238a0d317c Mon Sep 17 00:00:00 2001
From: ryanking13 <def6488@gmail.com>
Date: Sat, 17 Feb 2024 10:55:27 +0900
Subject: [PATCH 1/1] Replace OpenAudioDevice with OpenAudio

FIXME: for some reason, Mix_OpenAudioDevice is not statically linked when building the SDL module.

---
src_c/mixer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src_c/mixer.c b/src_c/mixer.c
index 51097bba..6c79747c 100644
--- a/src_c/mixer.c
+++ b/src_c/mixer.c
@@ -441,8 +441,8 @@ _init(int freq, int size, int channels, int chunk, char *devicename,
if (SDL_InitSubSystem(SDL_INIT_AUDIO))
return RAISE(pgExc_SDLError, SDL_GetError());

- if (Mix_OpenAudioDevice(freq, fmt, channels, chunk, devicename,
- allowedchanges) == -1) {
+ // No Mix_OpenAudioCompat in emscripten
+ if (Mix_OpenAudio(freq, fmt, channels, chunk) == -1) {
SDL_QuitSubSystem(SDL_INIT_AUDIO);
return RAISE(pgExc_SDLError, SDL_GetError());
}
--
2.29.2.windows.2