diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml new file mode 100644 index 0000000000..cb272c4d73 --- /dev/null +++ b/.github/workflows/web.yml @@ -0,0 +1,47 @@ +name: 🌎 Web +on: [push, pull_request] + +concurrency: + group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}-web + cancel-in-progress: true + +jobs: + web: + name: Web + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + build-type: + - Release + #- Debug + steps: + - name: Checkout + uses: actions/checkout@v3 + + # - name: Cache + # id: cache-system-libraries + # uses: actions/cache@v2 + # with: + # path: emsdk-cache + # key: emsdk-${{ runner.os }} + + - name: Emscripten + uses: mymindstorm/setup-emsdk@v11 + with: + #actions-cache-folder: 'emsdk-cache' + no-cache: true + version: 3.1.17 + + - name: Verify Emscripten + run: emcc -v + + - name: CMake + run: emcmake script/cmake_emscripten.sh build -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DURHO3D_LIB_TYPE=static -DURHO3D_PROFILING=0 + + - name: Build + run: cmake --build build --parallel 2 --config ${{ matrix.build-type }} + + - name: Publish + if: 0 + # TODO: port the ci_publish_web: task from the rakefile diff --git a/Docs/GettingStarted.dox b/Docs/GettingStarted.dox index 14a30e8f77..054eeec547 100644 --- a/Docs/GettingStarted.dox +++ b/Docs/GettingStarted.dox @@ -300,9 +300,9 @@ Execute cmake_mingw.sh then go to the build tree to execute make command. After This section assumes you have already updated, installed, and activated the latest Emscripten cross-compiler toolchain with upstream LLVM WASM backend on your host system as per described in https://emscripten.org/docs/getting_started/downloads.html. -Set the EMSCRIPTEN_ROOT_PATH environment variable or build option to point to the root path of Emscripten cross-compiler tools. Alternatively, call the emsdk_env script to set the EMSCRIPTEN environment variable for you. The Emscripten sysroot path will be derived from the root path, usually from 'system' subdir relative to the root path. However, you can optionally set the EMSCRIPTEN_SYSROOT environment variable or build option to point to another system root path. +Use the emcmake or emcmake.bat wrapper to set the emscripten toolchain file for you. This will set the needed cmake build options for the Emscripten cross-compiler tools. This can be called from the installed emsdk as an absolute path within the emsdk or you can source the emsdk_env script (extension depending on your shell) to add the tools to the path. -On Windows host, execute cmake_emscripten.bat. On MacOS or Linux host, execute cmake_emscripten.sh. Then go to the build tree and execute the 'make' command to start the build as usual. You may want to set the URHO3D_SAMPLES build option to build all the samples. You may also optionally set the URHO3D_LUA build option to enable Lua scripting support. If you encounter "Too many open files" warning when archiving the Urho3D static library, follow by "Unresolved symbol" errors on MacOS then you have to increase the soft-limit in your host system before rebuilding the library and all the main targets. +On Windows host, execute "emcmake.bat cmake_emscripten.bat". On MacOS or Linux host, execute "emcmake cmake_emscripten.sh". Then go to the build tree and execute the 'make' command to start the build as usual. If you encounter "Too many open files" warning when archiving the Urho3D static library, follow by "Unresolved symbol" errors on MacOS then you have to increase the soft-limit in your host system before rebuilding the library and all the main targets. For example, to double the limit (which normally defaults to 256 on MacOS): \verbatim diff --git a/Source/ThirdParty/SDL/src/video/emscripten/SDL_emscriptenvideo.c b/Source/ThirdParty/SDL/src/video/emscripten/SDL_emscriptenvideo.c index 458d67afdb..a298451609 100644 --- a/Source/ThirdParty/SDL/src/video/emscripten/SDL_emscriptenvideo.c +++ b/Source/ThirdParty/SDL/src/video/emscripten/SDL_emscriptenvideo.c @@ -347,8 +347,12 @@ Emscripten_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * di static void Emscripten_SetWindowTitle(_THIS, SDL_Window * window) { + // Urho3D: newer emscripten uses a free function and not one in the module. Taken from newer SDL. EM_ASM_INT({ - if (typeof Module['setWindowTitle'] !== 'undefined') { + if (typeof setWindowTitle !== 'undefined') { + setWindowTitle(UTF8ToString($0)); + } + else if (typeof Module['setWindowTitle'] !== 'undefined') { Module['setWindowTitle'](UTF8ToString($0)); } return 0; diff --git a/Source/Urho3D/CMakeLists.txt b/Source/Urho3D/CMakeLists.txt index 43cf8f3982..a57b9fe6f5 100644 --- a/Source/Urho3D/CMakeLists.txt +++ b/Source/Urho3D/CMakeLists.txt @@ -645,3 +645,10 @@ endif () if (URHO3D_FORCE_AS_MAX_PORTABILITY) add_definitions (-DAS_MAX_PORTABILITY) endif () + +# Symlink/copy html shell for use by downstream projects +if (WEB) + # Ensure the output directory exist before creating the symlink + file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + create_symlink (${CMAKE_SOURCE_DIR}/bin/shell.html ${CMAKE_BINARY_DIR}/bin/shell.html FALLBACK_TO_COPY) +endif () diff --git a/bin/shell.html b/bin/shell.html index f6a4a16cd5..2a59477e03 100644 --- a/bin/shell.html +++ b/bin/shell.html @@ -6,12 +6,23 @@ U3D