Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cd39c11
fix: android guard toolchains folder creation
Totto16 Nov 14, 2024
1ffc277
feat: WIP emscripten build script
Totto16 Nov 14, 2024
fa3612c
build: adjust build for web
Totto16 Nov 14, 2024
f0b61bd
fix: fix android build script
Totto16 Nov 14, 2024
e37d5f2
fix: remove unused and invalid cpp_args from android build script
Totto16 Nov 14, 2024
df00493
fix: fix some more web build errors
Totto16 Nov 15, 2024
ce88ad8
fix: more emscripten errors + add platform specific API
Totto16 Nov 15, 2024
83393b8
fix: use sdl2 with threads, so that emscripten links successfully
Totto16 Nov 15, 2024
68d8c80
fix: add web support for emscripten, trough the fetch API
Totto16 Nov 15, 2024
1eb539b
fix: emscripten: use mulithreaded libraries and embind-rtti, so that …
Totto16 Nov 15, 2024
0f8c91f
feat: add simple server for emscripten html, so that it works with co…
Totto16 Nov 15, 2024
9740070
fix: build js and html files after another, so that nothing gets part…
Totto16 Nov 15, 2024
8900695
fix: use correct game loop implementation for emscripten
Totto16 Nov 16, 2024
42fdf76
fix: fix a few more emscripten things
Totto16 Nov 16, 2024
bab268c
fix: fix linking order issue on emscripten
Totto16 Nov 16, 2024
db7f287
ci: add web assembly
Totto16 Nov 16, 2024
247542b
ci: update windows build tools version
Totto16 Nov 16, 2024
98d2bbb
fix: use correct namespace for utility function
Totto16 Nov 16, 2024
43d6b16
fix: use correct dependencies names in emscripten
Totto16 Nov 17, 2024
2c1cf65
wrap: update icu to 76.1
Totto16 Nov 17, 2024
d354844
wrap: update magic_enum to 0.9.7
Totto16 Nov 17, 2024
2d0f123
wrap: update utfcpp to 4.0.6
Totto16 Nov 17, 2024
2898d62
fix: only use png and svgs, since jpeg isn't available with mt support
Totto16 Nov 17, 2024
007faa3
fix: patch the emscripten ports, so that the program compile
Totto16 Nov 17, 2024
b5048f1
fix: emscripten: fix default settings for sdl_2mixer port
Totto16 Nov 17, 2024
d82db75
fix emscripten ,use builtin availbale console print functions
Totto16 Nov 17, 2024
13c8e72
fix: emscripten use correct port names (not varianet names)
Totto16 Nov 17, 2024
3dfae40
feat: use LocalStorage for settings instead of a file
Totto16 Nov 17, 2024
9615b3d
fix: correctly implement the assets and root dir helper functions for…
Totto16 Nov 17, 2024
19ba113
fix: make loading render loop also emscripten compatible
Totto16 Nov 18, 2024
8cabcfb
fix: fix multiple issues with emscripten
Totto16 Nov 18, 2024
3032a37
feat: implement proxying to main thread for emscripten
Totto16 Nov 18, 2024
53c9961
fix: fix fps counter being wrong
Totto16 Nov 18, 2024
0e5338c
feat: add better shell file for emscripten
Totto16 Nov 18, 2024
1799b2e
ci: fix lint and clang-tidy errors
Totto16 Nov 19, 2024
ec22863
fix: windows, define WIN32_LEAN_AND_MEAN so that windows.h behaves co…
Totto16 Nov 19, 2024
90654f6
fix: fix the application class, add a default destructor and move fun…
Totto16 Nov 19, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64
toolset: '14.41'
toolset: '14.42'

- name: Setup MYSYS2 (Windows)
if: matrix.config.os == 'windows' && ( matrix.config.environment == 'mingw' || matrix.config.environment == 'ucrt' )
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
tidy-checks: ''
step-summary: true
file-annotations: true
ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|wrapper|src/libs/core/hash-library|tests|src/lobby/curl_client.*
ignore: subprojects|build|android|assets|recordings|docs|toolchains|platforms|wrapper|src/libs/core/hash-library|tests|src/helper/web_utils.*|src/lobby/web_client.*|src/lobby/curl_client.*

- name: Fail CI run if linter checks failed
if: steps.linter.outputs.checks-failed != 0
Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/web_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Web CI

on:
release:
types: [published]
push:
branches: ['main']
pull_request:
workflow_dispatch:

jobs:
web-build:
name: Build for the web
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'

# NOTE: meson has no dependencies, so --break-system-packages doesn't really break anything!
- name: Setup Meson
run: |
pip install meson --break-system-packages

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install ninja-build pkg-config build-essential wabt -y --no-install-recommends

- name: Build
run: |
bash ./platforms/build-web.sh
meson test -C build-web

# TODO upload page to gh-pages!
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: oopetris-assets
path: build-web/src/executables/
2 changes: 1 addition & 1 deletion .github/workflows/windows_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: TheMrMilchmann/setup-msvc-dev@v3
with:
arch: x64
toolset: '14.41'
toolset: '14.42'

- name: Setup meson
run: |
Expand Down
Binary file removed assets/authors/mgerhold.jpg
Binary file not shown.
Binary file added assets/authors/mgerhold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 20 additions & 12 deletions platforms/build-android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

set -e

mkdir -p toolchains
if [ ! -d "toolchains" ]; then
mkdir -p toolchains
fi

export NDK_VER_DOWNLOAD="r28-beta1"
export NDK_VER_DESC="r28-beta1"
Expand Down Expand Up @@ -291,6 +293,10 @@ for INDEX in "${ARCH_KEYS_INDEX[@]}"; do
MESON_CPU_FAMILY="aarch64"
fi

export COMPILE_FLAGS="'--sysroot=${SYS_ROOT:?}','-fPIE','-fPIC','--target=$ARM_COMPILER_TRIPLE','-DAUDIO_PREFER_MP3'"

export LINK_FLAGS="'-fPIE','-L$SYS_ROOT/usr/lib'"

cat <<EOF >"./platforms/crossbuild-android-$ARM_TARGET_ARCH.ini"
[host_machine]
system = 'android'
Expand Down Expand Up @@ -318,10 +324,11 @@ llvm-config = '$LLVM_CONFIG'
[built-in options]
c_std = 'gnu11'
cpp_std = 'c++23'
c_args = ['--sysroot=${SYS_ROOT:?}','-fPIE','-fPIC','--target=$ARM_COMPILER_TRIPLE','-DHAVE_USR_INCLUDE_MALLOC_H','-D_MALLOC_H','-D__BITNESS=$BITNESS']
cpp_args = ['--sysroot=${SYS_ROOT:?}','-fPIE','-fPIC','--target=$ARM_COMPILER_TRIPLE','-D__BITNESS=$BITNESS']
c_link_args = ['-fPIE','-L$SYS_ROOT/usr/lib']
cpp_link_args = ['-fPIE','-L$SYS_ROOT/usr/lib']
c_args = [$COMPILE_FLAGS]
cpp_args = [$COMPILE_FLAGS]
c_link_args = [$LINK_FLAGS]
cpp_link_args = [$LINK_FLAGS]

prefix = '$SYS_ROOT'
libdir = '$LIB_PATH'

Expand All @@ -331,12 +338,14 @@ sys_root = '${SYS_ROOT}'

EOF

if [ ! -d "$PWD/subprojects/cpu-features" ]; then
mkdir -p "$PWD/subprojects/cpu-features/src/"
mkdir -p "$PWD/subprojects/cpu-features/include/"
ln -s "$BASE_PATH/sources/android/cpufeatures/cpu-features.c" "$PWD/subprojects/cpu-features/src/cpu-features.c"
ln -s "$BASE_PATH/sources/android/cpufeatures/cpu-features.h" "$PWD/subprojects/cpu-features/include/cpu-features.h"
cat <<EOF >"$PWD/subprojects/cpu-features/meson.build"
CPU_FUTURES_ROOT="$PWD/subprojects/cpu-features"

if [ ! -d "$CPU_FUTURES_ROOT" ]; then
mkdir -p "$CPU_FUTURES_ROOT/src/"
mkdir -p "$CPU_FUTURES_ROOT/include/"
ln -s "$BASE_PATH/sources/android/cpufeatures/cpu-features.c" "$CPU_FUTURES_ROOT/src/cpu-features.c"
ln -s "$BASE_PATH/sources/android/cpufeatures/cpu-features.h" "$CPU_FUTURES_ROOT/include/cpu-features.h"
cat <<EOF >"$CPU_FUTURES_ROOT/meson.build"
project('cpu-features','c')

meson.override_dependency(
Expand Down Expand Up @@ -367,7 +376,6 @@ EOF
--cross-file "./platforms/crossbuild-android-$ARM_TARGET_ARCH.ini" \
"-Dbuildtype=$BUILDTYPE" \
-Dsdl2:use_hidapi=enabled \
-Dcpp_args=-DAUDIO_PREFER_MP3 \
-Dclang_libcpp=disabled

fi
Expand Down
163 changes: 163 additions & 0 deletions platforms/build-web.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/usr/bin/env bash

set -e

if [ ! -d "toolchains" ]; then
mkdir -p toolchains
fi

export EMSCRIPTEN_ROOT="$(pwd)/toolchains/emsdk"

if [ ! -d "$EMSCRIPTEN_ROOT" ]; then
git clone https://github.com/emscripten-core/emsdk.git "$EMSCRIPTEN_ROOT"
fi

"$EMSCRIPTEN_ROOT/emsdk" install latest
"$EMSCRIPTEN_ROOT/emsdk" activate latest

EMSCRIPTEN_UPSTREAM_ROOT="$EMSCRIPTEN_ROOT/upstream/emscripten"

EMSCRIPTEN_PACTH_FILE="$EMSCRIPTEN_UPSTREAM_ROOT/.patched_manually.meta"

PATCH_DIR="platforms/emscripten"

if ! [ -e "$EMSCRIPTEN_PACTH_FILE" ]; then
##TODO: upstream those patches
# see: https://github.com/emscripten-core/emscripten/pull/18379/commits
# and: https://github.com/emscripten-core/emscripten/pull/18379

git apply --unsafe-paths -p1 --directory="$EMSCRIPTEN_UPSTREAM_ROOT" "$PATCH_DIR/sdl2_image_port.diff"
git apply --unsafe-paths -p1 --directory="$EMSCRIPTEN_UPSTREAM_ROOT" "$PATCH_DIR/sdl2_mixer_port.diff"
git apply --unsafe-paths -p1 --directory="$EMSCRIPTEN_UPSTREAM_ROOT" "$PATCH_DIR/default_settings.diff"

touch "$EMSCRIPTEN_PACTH_FILE"
fi

# git apply path

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

## build theneeded dependencies
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

export EMSCRIPTEN_SYS_ROOT="$EMSCRIPTEN_UPSTREAM_ROOT/cache/sysroot"

export BUILD_DIR="build-web"

export CC="emcc"
export CXX="em++"
export AR="emar"
export RANLIB="emranlib"
export STRIP="emstrip"
export NM="emnm"

export ARCH="wasm32"
export CPU_ARCH="wasm32"
export ENDIANESS="little"

export ROMFS="platforms/romfs"

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'"

export COMMON_FLAGS="'-fexceptions', '-pthread', '-sUSE_PTHREADS=1', '-sEXCEPTION_CATCHING_ALLOWED=[..]', $PACKAGE_FLAGS"

# 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 crashes, that aren't handled by some third party library, which is painful
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', '-sEXIT_RUNTIME=1'"
export COMPILE_FLAGS="$COMMON_FLAGS ,'-DAUDIO_PREFER_MP3'"

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

cat <<EOF >"$CROSS_FILE"
[host_machine]
system = 'emscripten'
cpu_family = '$ARCH'
cpu = '$CPU_ARCH'
endian = '$ENDIANESS'

[target_machine]
system = 'emscripten'
cpu_family = '$ARCH'
cpu = '$CPU_ARCH'
endian = '$ENDIANESS'

[constants]
emscripten_root = '$(pwd)/emsdk'

[binaries]
c = '$CC'
cpp = '$CXX'
ar = '$AR'
ranlib = '$RANLIB'
strip = '$STRIP'
nm = '$NM'

pkg-config = ['emmake', 'pkg-config']
cmake = ['emmake', 'cmake']
sdl2-config = ['emconfigure', 'sdl2-config']

exe_wrapper = '$EMSDK_NODE'

[built-in options]
c_std = 'c11'
cpp_std = 'c++23'
c_args = [$COMPILE_FLAGS]
cpp_args = [$COMPILE_FLAGS]
c_link_args = [$LINK_FLAGS]
cpp_link_args = [$LINK_FLAGS]

[properties]
needs_exe_wrapper = true
sys_root = '$EMSCRIPTEN_SYS_ROOT'

APP_ROMFS='$ROMFS/assets/'

EOF

## options: "smart, complete_rebuild"
export COMPILE_TYPE="smart"

export BUILDTYPE="debug"

if [ "$#" -eq 0 ]; then
# nothing
echo "Using compile type '$COMPILE_TYPE'"
elif [ "$#" -eq 1 ]; then
COMPILE_TYPE="$1"
elif [ "$#" -eq 2 ]; then
COMPILE_TYPE="$1"
BUILDTYPE="$2"
else
echo "Too many arguments given, expected 1 or 2"
exit 1
fi

if [ "$COMPILE_TYPE" == "smart" ]; then
: # noop
elif [ "$COMPILE_TYPE" == "complete_rebuild" ]; then
: # noop
else
echo "Invalid COMPILE_TYPE, expected: 'smart' or 'complete_rebuild'"
exit 1
fi

if [ ! -d "$ROMFS" ]; then

mkdir -p "$ROMFS"

cp -r assets "$ROMFS/"

fi

if [ "$COMPILE_TYPE" == "complete_rebuild" ] || [ ! -e "$BUILD_DIR" ]; then

meson setup "$BUILD_DIR" \
"--wipe" \
--cross-file "$CROSS_FILE" \
"-Dbuildtype=$BUILDTYPE" \
-Ddefault_library=static \
-Dtests=false

fi

meson compile -C "$BUILD_DIR"
13 changes: 13 additions & 0 deletions platforms/emscripten/default_settings.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/settings.js b/src/settings.js
index 981c44fa..17ca0078 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -1624,7 +1624,7 @@ var SDL2_IMAGE_FORMATS = [];

// Formats to support in SDL2_mixer. Valid values: ogg, mp3, mod, mid
// [link]
-var SDL2_MIXER_FORMATS = ["ogg"];
+var SDL2_MIXER_FORMATS = [];

// 1 = use sqlite3 from emscripten-ports
// Alternate syntax: --use-port=sqlite3
57 changes: 57 additions & 0 deletions platforms/emscripten/sdl2_image_port.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
diff --git a/tools/ports/sdl2_image.py b/tools/ports/sdl2_image.py
index c72ef576..0c12feba 100644
--- a/tools/ports/sdl2_image.py
+++ b/tools/ports/sdl2_image.py
@@ -16,15 +16,17 @@ variants = {
}

OPTIONS = {
- 'formats': 'A comma separated list of formats (ex: --use-port=sdl2_image:formats=png,jpg)'
+ 'formats': 'A comma separated list of formats (ex: --use-port=sdl2_image:formats=png,jpg)',
+ 'mt': 'use pthread'
}

SUPPORTED_FORMATS = {'avif', 'bmp', 'gif', 'jpg', 'jxl', 'lbm', 'pcx', 'png',
'pnm', 'qoi', 'svg', 'tga', 'tif', 'webp', 'xcf', 'xpm', 'xv'}

# user options (from --use-port)
-opts: Dict[str, Set] = {
- 'formats': set()
+opts = {
+ 'formats': set(),
+ 'mt': 0
}


@@ -42,7 +44,7 @@ def get_lib_name(settings):
libname = 'libSDL2_image'
if formats != '':
libname += '_' + formats
- return libname + '.a'
+ return libname + ('-mt' if opts['mt'] else '') + '.a'


def get(ports, settings, shared):
@@ -70,6 +72,8 @@ def get(ports, settings, shared):

if 'jpg' in formats:
defs += ['-sUSE_LIBJPEG']
+ if opts['mt']:
+ defs += ['-pthread']

ports.build_port(src_dir, final, 'sdl2_image', flags=defs, srcs=srcs)

@@ -99,7 +103,12 @@ def handle_options(options, error_handler):
error_handler(f'{format} is not a supported format')
else:
opts['formats'].add(format)
-
+
+ mt = options['mt']
+ if mt not in ["1","0"]:
+ error_handler(f'{mt} has to be either 0 or 1')
+ else:
+ opts['mt'] = int(mt)

def show():
return 'sdl2_image (-sUSE_SDL_IMAGE=2 or --use-port=sdl2_image; zlib license)'
Loading
Loading