Skip to content

Commit fa3612c

Browse files
committed
build: adjust build for web
1 parent 1ffc277 commit fa3612c

File tree

4 files changed

+127
-36
lines changed

4 files changed

+127
-36
lines changed

platforms/build-web.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ if [ ! -d "$EMSCRIPTEN_ROOT" ]; then
1212
git clone https://github.com/emscripten-core/emsdk.git "$EMSCRIPTEN_ROOT"
1313
fi
1414

15-
"$EMSCRIPTEN_ROOT/emsdk" install latest >/dev/null
16-
"$EMSCRIPTEN_ROOT/emsdk" activate latest >/dev/null
15+
"$EMSCRIPTEN_ROOT/emsdk" install latest
16+
"$EMSCRIPTEN_ROOT/emsdk" activate latest
1717

1818
# shellcheck disable=SC1091
1919
EMSDK_QUIET=1 source "$EMSCRIPTEN_ROOT/emsdk_env.sh" >/dev/null
2020

21+
## build theneeded dependencies
22+
embuilder build sdl2 harfbuzz freetype zlib sdl2_ttf vorbis mpg123 ogg libmodplug sdl2_mixer libpng libjpeg "sdl2_image:formats=png,jpg,svg" icu
23+
2124
export EMSCRIPTEN_SYS_ROOT="$EMSCRIPTEN_ROOT/upstream/emscripten/cache/sysroot"
2225

2326
export BUILD_DIR="build-emcc"
@@ -27,6 +30,7 @@ export CXX="em++"
2730
export AR="emar"
2831
export RANLIB="emranlib"
2932
export STRIP="emstrip"
33+
export NM="emnm"
3034

3135
export ARCH="wasm32"
3236
export CPU_ARCH="wasm32"
@@ -36,7 +40,7 @@ export COMMON_EMSCRIPTEN_OPTIONS="'-fexceptions', '-sEXCEPTION_CATCHING_ALLOWED=
3640

3741
# 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
3842
export LINK_EMSCRIPTEN_OPTIONS="$COMMON_EMSCRIPTEN_OPTIONS, '-sEXPORT_ALL=1', '-sUSE_GLFW=3', '-sUSE_WEBGPU=1', '-sWASM=1', '-sALLOW_MEMORY_GROWTH=1', '-sNO_EXIT_RUNTIME=0', '-sASSERTIONS=1'"
39-
export COMPILE_EMSCRIPTEN_OPTIONS="$COMMON_EMSCRIPTEN_OPTIONS"
43+
export COMPILE_EMSCRIPTEN_OPTIONS="$COMMON_EMSCRIPTEN_OPTIONS , '-sUSE_SDL=2'"
4044

4145
export CROSS_FILE="./platforms/crossbuild-web.ini"
4246

@@ -62,15 +66,17 @@ cpp = '$CXX'
6266
ar = '$AR'
6367
ranlib = '$RANLIB'
6468
strip = '$STRIP'
65-
pkg-config = ['emmake', 'env', 'PKG_CONFIG_PATH=PREFIX_GOES_HERE/lib/pkgconfig', 'pkg-config']
69+
nm = '$NM'
70+
71+
pkg-config = ['emmake', 'pkg-config']
6672
cmake = ['emmake', 'cmake']
6773
sdl2-config = ['emconfigure', 'sdl2-config']
6874
6975
exe_wrapper = '$EMSDK_NODE'
7076
7177
[built-in options]
7278
c_std = 'c11'
73-
cpp_std = 'c++20'
79+
cpp_std = 'c++23'
7480
c_args = [$COMPILE_EMSCRIPTEN_OPTIONS]
7581
c_link_args = [$LINK_EMSCRIPTEN_OPTIONS]
7682
cpp_args = [$COMPILE_EMSCRIPTEN_OPTIONS]

src/executables/meson.build

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,49 @@ if build_application
44

55
subdir('game')
66

7-
if meson.is_cross_build() and host_machine.system() == 'android'
8-
9-
library(
10-
'oopetris',
11-
main_files,
12-
dependencies: [liboopetris_graphics_dep, graphic_application_deps],
13-
override_options: {
14-
'warning_level': '3',
15-
'werror': true,
16-
},
17-
)
18-
19-
elif meson.is_cross_build() and host_machine.system() == 'switch'
20-
switch_options = [
21-
app_name,
22-
main_files,
23-
[liboopetris_graphics_dep, graphic_application_deps],
24-
]
25-
subdir('platforms/switch')
26-
elif meson.is_cross_build() and host_machine.system() == '3ds'
27-
_3ds_options = [
28-
app_name,
29-
main_files,
30-
[liboopetris_graphics_dep, graphic_application_deps],
31-
]
32-
subdir('platforms/3ds')
7+
if meson.is_cross_build()
8+
9+
if host_machine.system() == 'android'
10+
11+
library(
12+
'oopetris',
13+
main_files,
14+
dependencies: [liboopetris_graphics_dep, graphic_application_deps],
15+
override_options: {
16+
'warning_level': '3',
17+
'werror': true,
18+
},
19+
)
20+
21+
elif host_machine.system() == 'switch'
22+
switch_options = [
23+
app_name,
24+
main_files,
25+
[liboopetris_graphics_dep, graphic_application_deps],
26+
]
27+
subdir('platforms/switch')
28+
elif host_machine.system() == '3ds'
29+
_3ds_options = [
30+
app_name,
31+
main_files,
32+
[liboopetris_graphics_dep, graphic_application_deps],
33+
]
34+
subdir('platforms/3ds')
35+
elif host_machine.system() == 'emscripten'
36+
oopetris_exe = executable(
37+
'oopetris',
38+
main_files,
39+
dependencies: [liboopetris_graphics_dep, graphic_application_deps],
40+
link_args: ['--preload-file', '../assets@/assets/'],
41+
override_options: {
42+
'warning_level': '3',
43+
'werror': true,
44+
},
45+
install: true,
46+
)
47+
else
48+
error('Unhandled cross built system: ' + host_machine.system())
49+
endif
3350
else
3451

3552
if host_machine.system() == 'windows'

src/lobby/meson.build

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
if online_multiplayer_user_fallback
1+
if online_multiplayer_system == 'curl'
22
graphics_src_files += files(
33
'curl_client.cpp',
44
'curl_client.hpp',
55
)
6-
else
6+
elif online_multiplayer_system == 'httplib'
77
graphics_src_files += files(
88
'httplib_client.cpp',
99
'httplib_client.hpp',
1010
)
11+
elif online_multiplayer_system == 'web'
12+
graphics_src_files += files(
13+
'web_client.cpp',
14+
'web_client.hpp',
15+
)
16+
else
17+
error(
18+
'Unhandled online_multiplayer_system: \''
19+
+ online_multiplayer_system
20+
+ '\'',
21+
)
1122
endif
1223

1324
graphics_src_files += files(

tools/dependencies/meson.build

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,63 @@ if meson.is_cross_build()
2828
# language: ['cpp'],
2929
# )
3030
# endif
31+
elif host_machine.system() == 'android'
32+
# noop
33+
elif host_machine.system() == 'emscripten'
34+
only_allow_native_libs = true
35+
36+
## map native libraries to dependencies
37+
map_native_dependencies = ['SDL2', 'SDL2_ttf', 'mpg123', 'SDL2_mixer', 'SDL2_image']
38+
foreach map_native_dependency : map_native_dependencies
39+
native_dep = cpp.find_library(map_native_dependency, required: true)
40+
41+
if map_native_dependency == 'SDL2'
42+
43+
major_version = cpp.get_define(
44+
'SDL_MAJOR_VERSION',
45+
prefix: '#include <SDL2/SDL_version.h>',
46+
).strip('"')
47+
assert(
48+
major_version != '',
49+
'failed to get major_version from SDL_version.h',
50+
)
51+
52+
minor_version = cpp.get_define(
53+
'SDL_MINOR_VERSION',
54+
prefix: '#include <SDL2/SDL_version.h>',
55+
).strip('"')
56+
assert(
57+
minor_version != '',
58+
'failed to get minor_version from SDL_version.h',
59+
)
60+
61+
patch_version = cpp.get_define(
62+
'SDL_PATCHLEVEL',
63+
prefix: '#include <SDL2/SDL_version.h>',
64+
).strip('"')
65+
assert(
66+
patch_version != '',
67+
'failed to get patch_version from SDL_version.h',
68+
)
3169

70+
native_dep_with_version = declare_dependency(
71+
dependencies: native_dep,
72+
version: major_version
73+
+ '.'
74+
+ minor_version
75+
+ '.'
76+
+ patch_version,
77+
)
78+
meson.override_dependency(map_native_dependency, native_dep_with_version)
79+
else
80+
meson.override_dependency(map_native_dependency, native_dep)
81+
82+
endif
83+
84+
endforeach
85+
86+
else
87+
error('Unhandled cross built system: ' + host_machine.system())
3288
endif
3389
endif
3490

@@ -254,15 +310,16 @@ if build_application
254310
},
255311
)
256312

257-
online_multiplayer_user_fallback = false
313+
online_multiplayer_system = 'httplib'
258314

259315
if cpp_httlib_dep.found()
260316

261317
graphics_lib += {'deps': [graphics_lib.get('deps'), cpp_httlib_dep]}
262-
318+
elif meson.is_cross_build() and host_machine.system() == 'emscripten'
319+
online_multiplayer_system = 'web'
263320
else
264321

265-
online_multiplayer_user_fallback = true
322+
online_multiplayer_system = 'curl'
266323

267324
curl_cpp_wrapper = dependency(
268325
'cpr',

0 commit comments

Comments
 (0)