Skip to content

Commit

Permalink
feat: improved way of building for emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
tolstenko committed Nov 23, 2022
1 parent 0b15292 commit d651c9c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:

jobs:
linux-emscripten:
runs-on: ubuntu-latest
runs-on: emscripten/emsdk

steps:
- uses: actions/checkout@v2
Expand All @@ -26,8 +26,8 @@ jobs:
# path: /home/runner/.hunter
# key: ${{ runner.os }}-mobagen

- name: Emscripten Install
run: ./scripts/emscripten-install.sh || true
# - name: Emscripten Install
# run: ./scripts/emscripten-install.sh || true

- name: Emscripten Build
run: ./scripts/emscripten-build.sh
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.23.2)
cmake_minimum_required(VERSION 3.16.3)

# CPM downloader
include(external/cpm.cmake)
Expand Down Expand Up @@ -30,8 +30,10 @@ IF(EMSCRIPTEN)
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/assets/ -s WASM=0 -s DISABLE_EXCEPTION_CATCHING=2 --proxy-to-worker -s FETCH=1")
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/assets/")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -s WASM=0 -s FULL_ES2=1 -s USE_SDL=0 -s EXPORT_ALL=1")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -s WASM=0 -s FULL_ES2=1 -s USE_SDL=0 -s EXPORT_ALL=1")
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -s WASM=0 -s FULL_ES2=1 -s USE_SDL=0 -s EXPORT_ALL=1")
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -s WASM=0 -s FULL_ES2=1 -s USE_SDL=0 -s EXPORT_ALL=1")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=0 -s EXPORT_ALL=1")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_SDL=0 -s EXPORT_ALL=1")

add_definitions(-DASSET_DIR="${CMAKE_CURRENT_SOURCE_DIR}/assets/")

Expand Down
Empty file removed core2/CMakeLists.txt
Empty file.
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3"
services:
emsdk:
container_name: mobagen-emsdk
image: emscripten/emsdk
working_dir: /usr/src/mobagen
ports:
- "8000:8000"
volumes:
- .:/usr/src/mobagen
command: ./scripts/emscripten-build-and-run.sh
5 changes: 3 additions & 2 deletions external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include(filament.cmake)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)
Expand Down Expand Up @@ -30,9 +30,10 @@ ENDIF()

add_definitions(-DHAVE_LIBC=OFF)

#include(filament.cmake)
include(sdl.cmake)
include(glm.cmake)
#include(glew.cmake)
include(imgui.cmake)
include(assimp.cmake)
include(bullet.cmake)
include(bullet.cmake)
4 changes: 3 additions & 1 deletion scripts/emscripten-build-and-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ cd $DIRECTORY

cd $DIRECTORY/../bin-emscripten/bin

open "http://localhost:8000"
#open "http://localhost:8000"

echo hosting build at http://localhost:8000

python3 -m http.server
14 changes: 9 additions & 5 deletions scripts/emscripten-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

mkdir -p "${DIRECTORY}"/../bin-emscripten/bin/

cd $DIRECTORY/../external/emsdk

source ./emsdk_env.sh

export EMSCRIPTEN=${EMSDK}/upstream/emscripten
if which emcmake >/dev/null; then
echo emsdk exists in path
else
echo installing emsdk
./emscripten-install.sh
cd $DIRECTORY/../external/emsdk
source ./emsdk_env.sh
export EMSCRIPTEN=${EMSDK}/upstream/emscripten
fi

cd $DIRECTORY/../

Expand Down

0 comments on commit d651c9c

Please sign in to comment.