Skip to content

Commit 007faa3

Browse files
committed
fix: patch the emscripten ports, so that the program compile
it had an issue with the thread, see the listed github issues, in the section where local patches are applied
1 parent 2898d62 commit 007faa3

File tree

4 files changed

+181
-5
lines changed

4 files changed

+181
-5
lines changed

platforms/build-web.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,32 @@ fi
1515
"$EMSCRIPTEN_ROOT/emsdk" install latest
1616
"$EMSCRIPTEN_ROOT/emsdk" activate latest
1717

18+
EMSCRIPTEN_UPSTREAM_ROOT="$EMSCRIPTEN_ROOT/upstream/emscripten"
19+
20+
EMSCRIPTEN_PACTH_FILE="$EMSCRIPTEN_UPSTREAM_ROOT/.patched_manually.meta"
21+
22+
PATCH_DIR="platforms/emscripten"
23+
24+
if ! [ -e "$EMSCRIPTEN_PACTH_FILE" ]; then
25+
##TODO: upstream those patches
26+
# see: https://github.com/emscripten-core/emscripten/pull/18379/commits
27+
# and: https://github.com/emscripten-core/emscripten/pull/18379
28+
29+
git apply --unsafe-paths -p1 --directory="$EMSCRIPTEN_UPSTREAM_ROOT" "$PATCH_DIR/sdl2_image_port.diff"
30+
git apply --unsafe-paths -p1 --directory="$EMSCRIPTEN_UPSTREAM_ROOT" "$PATCH_DIR/sdl2_mixer_port.diff"
31+
32+
touch "$EMSCRIPTEN_PACTH_FILE"
33+
fi
34+
35+
# git apply path
36+
1837
# shellcheck disable=SC1091
1938
EMSDK_QUIET=1 source "$EMSCRIPTEN_ROOT/emsdk_env.sh" >/dev/null
2039

2140
## build theneeded dependencies
22-
embuilder build sdl2-mt harfbuzz-mt freetype zlib sdl2_ttf mpg123 sdl2_mixer_mp3 libpng-mt "sdl2_image:formats=png,svg" icu-mt
41+
embuilder build sdl2-mt harfbuzz-mt freetype zlib sdl2_ttf mpg123 "sdl2_mixer:formats=mp3" libpng-mt "sdl2_image:formats=png,svg:mt=1" icu-mt
2342

24-
export EMSCRIPTEN_SYS_ROOT="$EMSCRIPTEN_ROOT/upstream/emscripten/cache/sysroot"
43+
export EMSCRIPTEN_SYS_ROOT="$EMSCRIPTEN_UPSTREAM_ROOT/cache/sysroot"
2544

2645
export BUILD_DIR="build-web"
2746

@@ -38,9 +57,9 @@ export ENDIANESS="little"
3857

3958
export ROMFS="platforms/romfs"
4059

41-
export PACKAGE_FLAGS="'--use-port=sdl2', '--use-port=harfbuzz', '--use-port=freetype', '--use-port=zlib', '--use-port=sdl2_ttf', '--use-port=mpg123', '--use-port=sdl2_mixer', '-sSDL2_MIXER_FORMATS=[\"mp3\"]','--use-port=libpng', '--use-port=sdl2_image','-sSDL2_IMAGE_FORMATS=[\"png\",\"svg\"]', '--use-port=icu'"
60+
export PACKAGE_FLAGS="'--use-port=sdl2-mt', '--use-port=harfbuzz-mt', '--use-port=freetype', '--use-port=zlib', '--use-port=sdl2_ttf', '--use-port=mpg123', '--use-port=sdl2_mixer_mp3', '-sSDL2_MIXER_FORMATS=[\"mp3\"]','--use-port=libpng-mt', '--use-port=sdl2_image','-sSDL2_IMAGE_FORMATS=[\"png\",\"svg\"]', '--use-port=icu-mt'"
4261

43-
export COMMON_FLAGS="'-fexceptions', '-pthread', '-sEXCEPTION_CATCHING_ALLOWED=[..]', $PACKAGE_FLAGS"
62+
export COMMON_FLAGS="'-fexceptions', '-pthread', '-sUSE_PTHREADS=1', '-sPTHREADS=1','-sEXCEPTION_CATCHING_ALLOWED=[..]', $PACKAGE_FLAGS"
4463

4564
# TODO see if ALLOW_MEMORY_GROWTH is needed, but if we load ttf's and music it likely is and we don't have to debug OOm crahses, that aren't handled by some thrid party library, which is painful
4665
export LINK_FLAGS="$COMMON_FLAGS, '-sEXPORT_ALL=1', '-sUSE_WEBGPU=1', '-sWASM=1', '-sALLOW_MEMORY_GROWTH=1', '-sASSERTIONS=1','-sERROR_ON_UNDEFINED_SYMBOLS=1', '-sFETCH=1'"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
diff --git a/tools/ports/sdl2_image.py b/tools/ports/sdl2_image.py
2+
index c72ef576..0c12feba 100644
3+
--- a/tools/ports/sdl2_image.py
4+
+++ b/tools/ports/sdl2_image.py
5+
@@ -16,15 +16,17 @@ variants = {
6+
}
7+
8+
OPTIONS = {
9+
- 'formats': 'A comma separated list of formats (ex: --use-port=sdl2_image:formats=png,jpg)'
10+
+ 'formats': 'A comma separated list of formats (ex: --use-port=sdl2_image:formats=png,jpg)',
11+
+ 'mt': 'use pthread'
12+
}
13+
14+
SUPPORTED_FORMATS = {'avif', 'bmp', 'gif', 'jpg', 'jxl', 'lbm', 'pcx', 'png',
15+
'pnm', 'qoi', 'svg', 'tga', 'tif', 'webp', 'xcf', 'xpm', 'xv'}
16+
17+
# user options (from --use-port)
18+
-opts: Dict[str, Set] = {
19+
- 'formats': set()
20+
+opts = {
21+
+ 'formats': set(),
22+
+ 'mt': 0
23+
}
24+
25+
26+
@@ -42,7 +44,7 @@ def get_lib_name(settings):
27+
libname = 'libSDL2_image'
28+
if formats != '':
29+
libname += '_' + formats
30+
- return libname + '.a'
31+
+ return libname + ('-mt' if opts['mt'] else '') + '.a'
32+
33+
34+
def get(ports, settings, shared):
35+
@@ -70,6 +72,8 @@ def get(ports, settings, shared):
36+
37+
if 'jpg' in formats:
38+
defs += ['-sUSE_LIBJPEG']
39+
+ if opts['mt']:
40+
+ defs += ['-pthread']
41+
42+
ports.build_port(src_dir, final, 'sdl2_image', flags=defs, srcs=srcs)
43+
44+
@@ -99,7 +103,12 @@ def handle_options(options, error_handler):
45+
error_handler(f'{format} is not a supported format')
46+
else:
47+
opts['formats'].add(format)
48+
-
49+
+
50+
+ mt = options['mt']
51+
+ if mt not in ["1","0"]:
52+
+ error_handler(f'{mt} has to be either 0 or 1')
53+
+ else:
54+
+ opts['mt'] = int(mt)
55+
56+
def show():
57+
return 'sdl2_image (-sUSE_SDL_IMAGE=2 or --use-port=sdl2_image; zlib license)'
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
diff --git a/tools/ports/sdl2_mixer.py b/tools/ports/sdl2_mixer.py
2+
index f77f906d..417b2a79 100644
3+
--- a/tools/ports/sdl2_mixer.py
4+
+++ b/tools/ports/sdl2_mixer.py
5+
@@ -14,14 +14,27 @@ variants = {
6+
'sdl2_mixer_none': {'SDL2_MIXER_FORMATS': []},
7+
}
8+
9+
+OPTIONS = {
10+
+ 'formats': 'A comma separated list of formats (ex: --use-port=sdl2_mixer:formats=mp3)'
11+
+}
12+
+
13+
+SUPPORTED_FORMATS = {'mp3', 'ogg', 'mod', 'mid'}
14+
+
15+
+# user options (from --use-port)
16+
+opts = {
17+
+ 'formats': set(),
18+
+}
19+
20+
def needed(settings):
21+
return settings.USE_SDL_MIXER == 2
22+
23+
+def get_formats(settings):
24+
+ return set(settings.SDL2_MIXER_FORMATS).union(opts['formats'])
25+
+
26+
+
27+
28+
def get_lib_name(settings):
29+
- settings.SDL2_MIXER_FORMATS.sort()
30+
- formats = '-'.join(settings.SDL2_MIXER_FORMATS)
31+
+ formats = '-'.join(sorted(get_formats(settings)))
32+
33+
libname = 'libSDL2_mixer'
34+
if formats != '':
35+
@@ -44,26 +57,28 @@ def get(ports, settings, shared):
36+
'-O2',
37+
'-DMUSIC_WAV',
38+
]
39+
+
40+
+ formats = get_formats(settings)
41+
42+
- if "ogg" in settings.SDL2_MIXER_FORMATS:
43+
+ if "ogg" in formats:
44+
flags += [
45+
'-sUSE_VORBIS',
46+
'-DMUSIC_OGG',
47+
]
48+
49+
- if "mp3" in settings.SDL2_MIXER_FORMATS:
50+
+ if "mp3" in formats:
51+
flags += [
52+
'-sUSE_MPG123',
53+
'-DMUSIC_MP3_MPG123',
54+
]
55+
56+
- if "mod" in settings.SDL2_MIXER_FORMATS:
57+
+ if "mod" in formats:
58+
flags += [
59+
'-sUSE_MODPLUG',
60+
'-DMUSIC_MOD_MODPLUG',
61+
]
62+
63+
- if "mid" in settings.SDL2_MIXER_FORMATS:
64+
+ if "mid" in formats:
65+
flags += [
66+
'-DMUSIC_MID_TIMIDITY',
67+
]
68+
@@ -104,16 +119,29 @@ def clear(ports, settings, shared):
69+
70+
def process_dependencies(settings):
71+
settings.USE_SDL = 2
72+
- if "ogg" in settings.SDL2_MIXER_FORMATS:
73+
+
74+
+ formats = get_formats(settings)
75+
+
76+
+ if "ogg" in formats:
77+
deps.append('vorbis')
78+
settings.USE_VORBIS = 1
79+
- if "mp3" in settings.SDL2_MIXER_FORMATS:
80+
+ if "mp3" in formats:
81+
deps.append('mpg123')
82+
settings.USE_MPG123 = 1
83+
- if "mod" in settings.SDL2_MIXER_FORMATS:
84+
+ if "mod" in formats:
85+
deps.append('libmodplug')
86+
settings.USE_MODPLUG = 1
87+
88+
+def handle_options(options, error_handler):
89+
+ formats = options['formats'].split(',')
90+
+ for format in formats:
91+
+ format = format.lower().strip()
92+
+ if format not in SUPPORTED_FORMATS:
93+
+ error_handler(f'{format} is not a supported format')
94+
+ else:
95+
+ opts['formats'].add(format)
96+
+
97+
+
98+
99+
def show():
100+
return 'sdl2_mixer (-sUSE_SDL_MIXER=2 or --use-port=sdl2_mixer; zlib license)'

tools/dependencies/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ if meson.is_cross_build()
5353
['SDL2_ttf'],
5454
['mpg123'],
5555
['SDL2_mixer_mp3', 'SDL2_mixer'],
56-
['SDL2_image_png-svg', 'SDL2_image'],
56+
['SDL2_image_png-svg-mt', 'SDL2_image'],
5757
['icu_common-mt', 'icu-uc'],
5858
]
5959
foreach native_dependency_tuple : map_native_dependencies

0 commit comments

Comments
 (0)