Skip to content

Commit

Permalink
Merge pull request #3 from briancullinan2/wasm-support-squashed
Browse files Browse the repository at this point in the history
Wasm support squashed
  • Loading branch information
briancullinan2 authored Jun 16, 2024
2 parents 9fd02e4 + 5efc2bb commit df26e17
Show file tree
Hide file tree
Showing 3,312 changed files with 252,537 additions and 1,016 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
53 changes: 51 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,54 @@ jobs:
if-no-files-found: error
retention-days: 5

ubuntu-wasm:
name: ${{ matrix.config }} Web Assembly ${{ matrix.arch }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
arch: [js]
config: [Release]
include:
- config: Release
rule: release
- arch: js
use_sdl: USE_SDL=0

steps:
- name: Install tools
run: |
sudo apt-get -qq update
sudo apt-get -y install libcurl4-openssl-dev mesa-common-dev libxxf86dga-dev libxrandr-dev libxxf86vm-dev libasound-dev libsdl2-dev wget
wget --no-check-certificate https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-15/wasi-sdk-15.0-linux.tar.gz -O ../wasi-sdk-15.0-linux.tar.gz
wget --no-check-certificate https://github.com/WebAssembly/binaryen/releases/download/version_109/binaryen-version_109-x86_64-linux.tar.gz -O ../binaryen-version_109-x86_64-linux.tar.gz
#npm install -g uglify-js
- uses: actions/checkout@v2
with:
submodules: recursive

- name: Build
run: |
mkdir code/wasm/linux
tar -zxvf ../wasi-sdk-15.0-linux.tar.gz -C code/wasm/linux/
tar -zxvf ../binaryen-version_109-x86_64-linux.tar.gz -C code/wasm/linux/
make release -j 8 PLATFORM=wasm ARCH=${{ matrix.arch }} \
DESTDIR=bin ${{ matrix.use_sdl }} \
USE_RENDERER_DLOPEN=0 RENDERER_DEFAULT=opengl2 \
CNAME=quake3e BUILD_SERVER=0 \
WASM-OPT=code/wasm/linux/binaryen-version_109/bin/wasm-opt
mkdir bin
mv build/release-wasm-js/*.wasm bin/
- uses: actions/upload-artifact@v2
if: matrix.config == 'Release'
with:
name: wasm-${{ matrix.arch }}
path: bin
if-no-files-found: error
retention-days: 5

macos-x86:
name: ${{ matrix.btype }} macOS ${{ matrix.arch }}
runs-on: macos-latest
Expand Down Expand Up @@ -285,7 +333,7 @@ jobs:

create-testing:
if: github.ref == 'refs/heads/master' && github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: [windows-msys, windows-msvc, ubuntu-x86, ubuntu-arm, macos-x86]
needs: [windows-msys, windows-msvc, ubuntu-x86, ubuntu-arm, ubuntu-wasm, macos-x86]
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
Expand All @@ -304,6 +352,7 @@ jobs:
7z a -r quake3e-macos-aarch64.zip ./macos-aarch64/*
# 7z a -r quake3e-linux-aarch64.zip ./linux-aarch64/*
# 7z a -r quake3e-linux-armv7.zip ./linux-armv7/*
7z a -r quake3e-wasm-js.zip ./wasm-js/*

- name: Create latest build
uses: czietz/action-automatic-releases@latest
Expand All @@ -317,7 +366,7 @@ jobs:
update-release:
if: ${{ github.event_name == 'release' }}
needs: [windows-msys, windows-msvc, ubuntu-x86, ubuntu-arm, macos-x86]
needs: [windows-msys, windows-msvc, ubuntu-x86, ubuntu-arm, ubuntu-wasm, macos-x86]
runs-on: ubuntu-latest

strategy:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@ output/
*.user
cmake-*
.idea

Makefile.local
/node_modules/
/code/wasm/darwin/
docs/demoq3/pak0.pk3dir/.DS_Store
.DS_Store
.DS_Store
181 changes: 180 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ USE_OPENGL = 1
USE_OPENGL2 = 0
USE_OPENGL_API = 1
USE_VULKAN_API = 1
USE_RENDERER_DLOPEN = 1

USE_RENDERER_DLOPEN ?= 1

# valid options: opengl, vulkan, opengl2
RENDERER_DEFAULT = opengl
Expand All @@ -59,6 +60,22 @@ echo_cmd=@echo
Q=@
endif

######################### WASM ###################################
ifeq ($(PLATFORM),wasm)
ARCH=js
RENDERER_DEFAULT=opengl2
WASM=1
CROSS_COMPILING=1
BUILD_SERVER=0
USE_SYSTEM_JPEG=0
USE_IPV6=0
USE_SDL=0
USE_CURL=0
HAVE_VM_COMPILED=false
USE_VULKAN_API=0
USE_VULKAN=0
endif

#############################################################################
#
# If you require a different configuration from the defaults below, create a
Expand Down Expand Up @@ -212,6 +229,7 @@ SDLHDIR=$(MOUNT_DIR)/libsdl/include/SDL2
CMDIR=$(MOUNT_DIR)/qcommon
UDIR=$(MOUNT_DIR)/unix
W32DIR=$(MOUNT_DIR)/win32
WASMDIR=$(MOUNT_DIR)/wasm
BLIBDIR=$(MOUNT_DIR)/botlib
JPDIR=$(MOUNT_DIR)/libjpeg
OGGDIR=$(MOUNT_DIR)/libogg
Expand Down Expand Up @@ -349,6 +367,107 @@ ARCHEXT=

CLIENT_EXTRA_FILES=

#############################################################################
# SETUP AND BUILD -- Web Assembly (WASI-SDK)
#############################################################################

ifdef WASM
ARCHEXT = .wasm

ifeq ($(COMPILE_PLATFORM),mingw)
HAS_WASI=1
endif
ifeq ($(COMPILE_PLATFORM),linux)
HAS_WASI=1
endif
ifeq ($(COMPILE_PLATFORM),darwin)
HAS_WASI=1
endif
ifndef HAS_WASI
error platform support (one of linux, mingw, darwin)
endif

WASISDK := $(lastword $(wildcard code/wasm/$(COMPILE_PLATFORM)/wasi-sdk-*))
WASI-BUILTINS := $(lastword $(wildcard $(WASISDK)/lib/clang/*))
WASM-OPT ?= $(lastword $(wildcard code/wasm/$(COMPILE_PLATFORM)/binaryen-version_*/bin/wasm-opt))
#LD := $(WASISDK)/bin/wasm-ld
CC := $(WASISDK)/bin/clang
LD := $(CC)

WASI_INCLUDES := \
--target=wasm32 \
-Icode/wasm \
-I$(WASISDK)/share/wasi-sysroot/include \
-I$(WASISDK)/share/wasi-sysroot/include/wasm32-wasi \
-Icode/wasm/SDL2-2.0.14/include \
-Icode/libogg/include -Icode/libvorbis/include

BASE_CFLAGS += -fno-rtti -Wall \
-Wimplicit -fstrict-aliasing -fno-inline \
-ftree-vectorize -fsigned-char -MMD \
-fno-short-enums -fPIC \
-DNO_VM_COMPILED=1 -fno-common \
-D_XOPEN_SOURCE=700 -D__EMSCRIPTEN__=1 \
-D__WASM__=1 -D__wasi__=1 -D__wasm32__=1 \
-D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN=1 \
-DDISABLE_IPV6=1 \
-std=gnu11 $(WASI_INCLUDES)

LDFLAGS += -D__WASM__=1 --no-standard-libraries \
-Wl,--export-dynamic -Wl,--error-limit=200 \
-Wl,--import-memory,--import-table \
$(WASI-BUILTINS)/lib/wasi/libclang_rt.builtins-wasm32.a \
$(WASISDK)/share/wasi-sysroot/lib/wasm32-wasi/libc.a


# -Wl,--initial-memory=52428800 \
-Wl,--max-memory=1048576000 \
-Wl,--export-table,--growable-table

OPTIMIZE = -O3 -ffast-math

SHLIBEXT = wasm
SHLIBCFLAGS = -fvisibility=hidden $(OPTIMIZE)
SHLIBLDFLAGS = -Wl,--no-entry $(LDFLAGS) \
-Wl,--export=malloc -Wl,--export=s_knownSfx \
-Wl,--export=stderr -Wl,--export=stdout \
-Wl,--allow-undefined-file=code/wasm/wasm.syms

# -fno-builtin -nostdlib
# -shared not supported

CLIENT_LDFLAGS = $(LDFLAGS) code/wasm/stack_ops.S \
-Wl,--export=sprintf -Wl,--export=malloc \
-Wl,--export=stderr -Wl,--export=stdout \
-Wl,--export=FS_CreatePath -Wl,--export=free \
-Wl,--export=errno,--export=R_FindPalette \
-Wl,--export=Key_ClearStates,--export=Key_GetCatcher \
-Wl,--export=Key_SetCatcher,--export=CL_PacketEvent \
-Wl,--export=CL_Try_LoadJPG,--export=CL_Fail_LoadJPG \
-Wl,--export=s_soundStarted,--export=s_soundMuted,--export=s_knownSfx \
-Wl,--export=stackRestore,--export=stackSave,--export=stackAlloc \
-Wl,--export=dma,--export=S_SoundInfo,--export=Cbuf_ExecuteText \
-Wl,--export=Cbuf_AddText,--export=gw_minimized \
-Wl,--export=gw_active,--export=Z_Free \
-Wl,--export=CL_NextDownload,--export=com_fullyInitialized \
-Wl,--export=Z_Malloc,--export=Sys_QueEvent,--export=MSG_Init \
-Wl,--export=Com_RunAndTimeServerPacket,--export=Com_Frame \
-Wl,--export=Cvar_VariableValue,--export=Cvar_VariableIntegerValue \
-Wl,--export=Cvar_VariableString,--export=Cvar_Get \
-Wl,--export=Cvar_Set,--export=Cvar_SetValue \
-Wl,--export=Cvar_SetIntegerValue,--export=Cvar_CheckRange \
-Wl,--export=FS_ReadFile,--export=VM_Call \
-Wl,--export=FS_FreeFile,--export=FS_CopyString \
-Wl,--export=FS_GetCurrentGameDir,--export=Key_KeynumToString \
-Wl,--allow-undefined-file=code/wasm/wasm.syms



DEBUG_CFLAGS = $(BASE_CFLAGS) -DDEBUG -D_DEBUG -g -O0
RELEASE_CFLAGS = $(BASE_CFLAGS) -DNDEBUG $(OPTIMIZE)

else
LD =: $(CC)

#############################################################################
# SETUP AND BUILD -- MINGW32
Expand Down Expand Up @@ -602,6 +721,8 @@ endif # *NIX platforms

endif # !MINGW

endif # !__WASM__


TARGET_CLIENT = $(CNAME)$(ARCHEXT)$(BINEXT)

Expand Down Expand Up @@ -733,6 +854,7 @@ ifdef MINGW
@echo " WINDRES: $(WINDRES)"
endif
@echo " CC: $(CC)"
@echo " LD: $(LD)"
@echo ""
@echo " CFLAGS:"
@for i in $(CFLAGS); \
Expand Down Expand Up @@ -1043,6 +1165,7 @@ Q3OBJ = \
$(B)/client/net_ip.o \
$(B)/client/huffman.o \
$(B)/client/huffman_static.o \
$(B)/client/splines.o \
\
$(B)/client/snd_adpcm.o \
$(B)/client/snd_dma.o \
Expand All @@ -1055,6 +1178,7 @@ Q3OBJ = \
$(B)/client/snd_codec_wav.o \
\
$(B)/client/sv_bot.o \
$(B)/client/sv_bsp_mini.o \
$(B)/client/sv_ccmds.o \
$(B)/client/sv_client.o \
$(B)/client/sv_filter.o \
Expand Down Expand Up @@ -1156,6 +1280,14 @@ ifeq ($(USE_CURL),1)
Q3OBJ += $(B)/client/cl_curl.o
endif

ifdef WASM

Q3OBJ += \
$(B)/client/sys_main.o $(B)/client/dlmalloc.o \
$(B)/client/sbrk.o

else

ifdef MINGW

Q3OBJ += \
Expand Down Expand Up @@ -1204,6 +1336,9 @@ ifeq ($(USE_SDL),1)
$(B)/client/sdl_input.o \
$(B)/client/sdl_snd.o
else # !USE_SDL
ifdef WASM
$(error not wasm!)
endif
Q3OBJ += \
$(B)/client/linux_glimp.o \
$(B)/client/linux_snd.o \
Expand All @@ -1222,26 +1357,56 @@ endif # !USE_SDL

endif # !MINGW

endif # !WASM

# client binary

ifeq ($(PLATFORM),wasm)


$(B)/$(TARGET_CLIENT): $(Q3OBJ) $(wildcard code/wasm/*.js) code/wasm/index.html code/wasm/index.css
$(echo_cmd) "LD $@"
$(CC) -o $@ $(Q3OBJ) $(CLIENT_LDFLAGS) \
$(LDFLAGS)
#$(WASM-OPT) -Oz -Os --zero-filled-memory --no-validation -o $@ $@
cp code/wasm/*.js docs/
cp code/wasm/*.html docs/
cp code/wasm/*.css docs/
cp $(B)/$(TARGET_CLIENT) docs/


else

$(B)/$(TARGET_CLIENT): $(Q3OBJ)
$(echo_cmd) "LD $@"
$(Q)$(CC) -o $@ $(Q3OBJ) $(CLIENT_LDFLAGS) \
$(LDFLAGS)

endif

# modular renderers

$(B)/$(TARGET_REND1): $(Q3REND1OBJ)
$(echo_cmd) "LD $@"
$(Q)$(CC) -o $@ $(Q3REND1OBJ) $(SHLIBCFLAGS) $(SHLIBLDFLAGS)

ifneq ($(PLATFORM),wasm)
$(STRINGIFY): $(MOUNT_DIR)/renderer2/stringify.c
$(echo_cmd) "LD $@"
$(Q)$(CC) -o $@ $(MOUNT_DIR)/renderer2/stringify.c $(LDFLAGS)
endif

ifeq ($(PLATFORM),wasm)
$(B)/$(TARGET_REND2): $(Q3REND2OBJ) $(Q3REND2STROBJ)
$(echo_cmd) "LD $@"
$(Q)$(CC) -o $@ $(Q3REND2OBJ) $(Q3REND2STROBJ) $(SHLIBCFLAGS) $(SHLIBLDFLAGS)
$(WASM-OPT) -Os --zero-filled-memory --no-validation -o $@ $@

else
$(B)/$(TARGET_REND2): $(Q3REND2OBJ) $(Q3REND2STROBJ)
$(echo_cmd) "LD $@"
$(Q)$(CC) -o $@ $(Q3REND2OBJ) $(Q3REND2STROBJ) $(SHLIBCFLAGS) $(SHLIBLDFLAGS)
endif

$(B)/$(TARGET_RENDV): $(Q3RENDVOBJ)
$(echo_cmd) "LD $@"
Expand All @@ -1253,6 +1418,7 @@ $(B)/$(TARGET_RENDV): $(Q3RENDVOBJ)

Q3DOBJ = \
$(B)/ded/sv_bot.o \
$(B)/ded/sv_bsp_mini.o \
$(B)/ded/sv_client.o \
$(B)/ded/sv_ccmds.o \
$(B)/ded/sv_filter.o \
Expand Down Expand Up @@ -1390,9 +1556,19 @@ $(B)/rend1/%.o: $(RCDIR)/%.c
$(B)/rend1/%.o: $(CMDIR)/%.c
$(DO_REND_CC)

ifneq ($(PLATFORM),wasm)
$(B)/rend2/glsl/%.c: $(R2DIR)/glsl/%.glsl $(STRINGIFY)
$(DO_REF_STR)

else

$(B)/rend2/glsl/%.c: $(R2DIR)/glsl/%.glsl
$(echo_cmd) "REF_STR $@"
$(Q)echo "const char *fallbackShader_$(notdir $(basename $<)) =" >> $@
$(Q)cat $< | sed -e 's/^/\"/;s/$$/\\n\"/' | tr -d '\r' >> $@
$(Q)echo ";" >> $@
endif

$(B)/rend2/glsl/%.o: $(B)/renderer2/glsl/%.c
$(DO_REND_CC)

Expand All @@ -1414,6 +1590,9 @@ $(B)/rendv/%.o: $(RCDIR)/%.c
$(B)/rendv/%.o: $(CMDIR)/%.c
$(DO_REND_CC)

$(B)/client/%.o: $(WASMDIR)/%.c
$(DO_CC)

$(B)/client/%.o: $(UDIR)/%.c
$(DO_CC)

Expand Down
Loading

0 comments on commit df26e17

Please sign in to comment.