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

backport wasm build to 0.H #74362

Merged
merged 12 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 31 additions & 0 deletions .github/workflows/emscripten.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Emscripten build

on:
workflow_call:

# We only care about the latest revision of a PR, so cancel previous instances.
concurrency:
group: emscripten-build-${{ github.event.pull_request.number || github.ref_name }}
cancel-in-progress: true

jobs:
build_catatclysm:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: mymindstorm/setup-emsdk@v13

- name: Build with emcc (emscripten)
run: ./build-scripts/build-emscripten.sh

- name: Assemble web bundle
run: ./build-scripts/prepare-web.sh

- name: Create artifact
uses: actions/upload-artifact@v4
with:
name: play-cdda
path: build/*
5 changes: 5 additions & 0 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,8 @@ jobs:
name: cata_test
path: tests/cata_test*
if-no-files-found: ignore
emscripten:
needs: [ varied_builds ]
uses: ./.github/workflows/emscripten.yml
if: ${{ success() && github.event.pull_request.draft == false }}
secrets: inherit
21 changes: 19 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ jobs:
artifact: android-bundle
ext: aab
content: application/aap
- name: WebAssembly Bundle
os: ubuntu-latest
mxe: none
artifact: wasm
ext: zip
content: application/zip
sound: 0
wasm: true
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
permissions: write-all
Expand Down Expand Up @@ -217,11 +225,14 @@ jobs:
shasum -a 256 -c ./build-scripts/libbacktrace-${{ matrix.mxe }}-w64-mingw32-sha256
sudo tar -xzf libbacktrace-${{ matrix.mxe }}-w64-mingw32.tar.gz --exclude=LICENSE -C /opt/mxe/usr/${{ matrix.mxe }}-w64-mingw32.static.gcc12
- name: Install dependencies (Linux)
if: runner.os == 'Linux' && matrix.mxe == 'none' && matrix.android == 'none'
if: runner.os == 'Linux' && matrix.mxe == 'none' && matrix.android == 'none' && !matrix.wasm
run: |
sudo apt-get update
sudo apt-get install libncursesw5-dev libsdl2-dev libsdl2-ttf-dev libsdl2-image-dev \
libsdl2-mixer-dev libpulse-dev ccache gettext parallel
- name: Install Emscripten (WebAssembly)
if: matrix.wasm
uses: mymindstorm/setup-emsdk@v13
- name: Install runtime dependencies (mac)
if: runner.os == 'macOS'
uses: BrettDong/setup-sdl2-frameworks@v1
Expand Down Expand Up @@ -250,10 +261,16 @@ jobs:
run: |
lang/compile_mo.sh all
- name: Build CDDA (linux)
if: runner.os == 'Linux' && matrix.mxe == 'none' && matrix.android == 'none' && matrix.artifact != 'linux-objectcreator-x64'
if: runner.os == 'Linux' && matrix.mxe == 'none' && matrix.android == 'none' && matrix.artifact != 'linux-objectcreator-x64' && !matrix.wasm
run: |
make -j$((`nproc`+0)) TILES=${{ matrix.tiles }} SOUND=${{ matrix.tiles }} RELEASE=1 LOCALIZE=1 LANGUAGES=all BACKTRACE=1 PCH=0 bindist
mv cataclysmdda-0.H.tar.gz cdda-${{ matrix.artifact }}-${{ needs.release.outputs.timestamp }}.tar.gz
- name: Build CDDA (WebAssembly)
if: matrix.wasm && success()
run: |
./build-scripts/build-emscripten.sh
./build-scripts/prepare-web.sh
(cd build && zip ../cdda-${{ matrix.artifact }}-${{ needs.release.outputs.timestamp }}.${{ matrix.ext }} *)
- name: Login to GitHub Container Registry
if: matrix.artifact == 'windows-objectcreator-x64' || matrix.artifact == 'linux-objectcreator-x64'
uses: docker/login-action@v2
Expand Down
60 changes: 58 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
# Run: make NATIVE=win32
# OS X
# Run: make NATIVE=osx
# Emscripten
# Run: make NATIVE=emscripten

# Build types:
# Debug (no optimizations)
Expand Down Expand Up @@ -112,6 +114,10 @@ WARNINGS = \
-Wno-unknown-warning-option \
-Wno-dangling-reference \
-Wno-c++20-compat
ifeq ($(NATIVE), emscripten)
# The EM_ASM macro triggers this warning.
WARNINGS += -Wno-gnu-zero-variadic-macro-arguments
endif
# Uncomment below to disable warnings
#WARNINGS = -w
DEBUGSYMS = -g
Expand Down Expand Up @@ -144,6 +150,9 @@ VERSION = 0.H

TARGET_NAME = cataclysm
TILES_TARGET_NAME = $(TARGET_NAME)-tiles
ifeq ($(NATIVE), emscripten)
TILES_TARGET_NAME = $(TARGET_NAME)-tiles.js
endif

TARGET = $(BUILD_PREFIX)$(TARGET_NAME)
TILESTARGET = $(BUILD_PREFIX)$(TILES_TARGET_NAME)
Expand Down Expand Up @@ -389,6 +398,8 @@ ifeq ($(RELEASE), 1)
else
OPTLEVEL = -O3
endif
else ifeq ($(NATIVE), emscripten)
OPTLEVEL = -Os
else
# MXE ICE Workaround
# known bad on 4.9.3 and 4.9.4, if it gets fixed this could include a version test too
Expand Down Expand Up @@ -457,7 +468,9 @@ else
# way to turn off optimization (make NOOPT=1) entirely.
OPTLEVEL = -O0
else
ifeq ($(shell $(CXX) -E -Og - < /dev/null > /dev/null 2>&1 && echo fog),fog)
ifeq ($(NATIVE),emscripten)
OPTLEVEL = -O3
else ifeq ($(shell $(CXX) -E -Og - < /dev/null > /dev/null 2>&1 && echo fog),fog)
OPTLEVEL = -Og
else
OPTLEVEL = -O0
Expand Down Expand Up @@ -618,6 +631,47 @@ ifeq ($(NATIVE), cygwin)
TARGETSYSTEM=CYGWIN
endif

# Emscripten
ifeq ($(NATIVE), emscripten)
CXX=emcc
LD=emcc

# Flags that are common across compile and link phases.
EMCC_COMMON_FLAGS = -sUSE_SDL=2 -sUSE_SDL_IMAGE=2 -sUSE_SDL_TTF=2 -sSDL2_IMAGE_FORMATS=['png'] -fexceptions

ifneq ($(RELEASE), 1)
EMCC_COMMON_FLAGS += -g
endif

CXXFLAGS += $(EMCC_COMMON_FLAGS)
LDFLAGS += $(EMCC_COMMON_FLAGS)

LDFLAGS += -sFORCE_FILESYSTEM
LDFLAGS += -sEXPORTED_RUNTIME_METHODS=['FS','stackTrace','jsStackTrace']
LDFLAGS += -sINITIAL_MEMORY=512MB
LDFLAGS += -sMAXIMUM_MEMORY=4GB
LDFLAGS += -sALLOW_MEMORY_GROWTH
LDFLAGS += -sSTACK_SIZE=262144
LDFLAGS += -sASYNCIFY
LDFLAGS += -sASYNCIFY_STACK_SIZE=16384
LDFLAGS += -sENVIRONMENT=web
LDFLAGS += -lidbfs.js
LDFLAGS += -lembind
LDFLAGS += -sWASM_BIGINT # Browser will require BigInt support.
LDFLAGS += -sMAX_WEBGL_VERSION=2

ifeq ($(RELEASE), 1)
# Release-mode Linker flags.
LDFLAGS += -Os
LDFLAGS += -sLZ4
else
# Debug mode linker flags.
LDFLAGS += -O1 # Emscripten link time is slow, so use low optimization level.
LDFLAGS += -sFS_DEBUG
LDFLAGS += -gseparate-dwarf
endif
endif

# MXE cross-compile to win32
ifneq (,$(findstring mingw32,$(CROSS)))
DEFINES += -DCROSS_LINUX
Expand Down Expand Up @@ -716,7 +770,7 @@ ifeq ($(TILES), 1)
LDFLAGS += -lSDL2_mixer
endif
endif
else # not osx
else ifneq ($(NATIVE),emscripten)
CXXFLAGS += $(shell $(PKG_CONFIG) --cflags sdl2 SDL2_image SDL2_ttf)

ifeq ($(STATIC), 1)
Expand Down Expand Up @@ -961,7 +1015,9 @@ $(TARGET): $(OBJS)
ifeq ($(RELEASE), 1)
ifndef DEBUG_SYMBOLS
ifneq ($(BACKTRACE),1)
ifneq ($(NATIVE), emscripten)
$(STRIP) $(TARGET)
endif
endif
endif
endif
Expand Down
Loading
Loading