Skip to content

Commit f65d545

Browse files
committed
Upgrade to Emscripten💩 3.1.50 in order to enable mimalloc
Upgrade to Emscripten💩 3.1.50 in order to enable mimalloc. The default allocator (dlmalloc) has dog-shit for performance under multiple threads due to plenty of locking happening inside the allocator. The better allocator is mimalloc that requires Emscripten💩 3.1.50 Emscripten💩 3.1.27 changed the default stack size to 64kb. Restore the original 5MB stack size with -sSTACK_SIZE=5MB Upgrading Emscripten comes with a new clang that is based on a new LLVM version that has a regression so sol2 build fails: ThePhD/sol2#1614 Adding a WAR in sol.hpp to change the offendin function signatures to unconditonal noexcept. mimalloc performance: emscripten-core/emscripten#20651
1 parent 40ab83f commit f65d545

File tree

4 files changed

+75
-59
lines changed

4 files changed

+75
-59
lines changed

BUILDING.md

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,25 @@ Build Instructions 👨🏼‍💻
1010
![Screenshot](logo/emscripten.png)
1111

1212
## Getting Started 👈
13+
14+
> [!TIP]
15+
> The build process assumes some familiarity with building C++ based projects using
16+
> toolchains and tools such as GCC, MSVS, Emscripten💩 and CMake.
17+
18+
> [!TIP]
19+
> You'll need to have Qt5 in order to build the Editor.
20+
21+
22+
### Build Steps:
1323
1. First build the engine and editor for your target platform.
1424
2. If you want to deploy / package your game for web then build the engine for HTML5/WASM
1525
3. If you want to work on the engine itself it's advisory to also run the (unit) tests.
1626

17-
<i>
18-
<strong>
19-
The build process assumes some familiarity with building C++ based projects using
20-
toolchains and tools such as GCC, MSVS, Emscripten💩 and CMake.
21-
<br><br>
22-
You'll need to have Qt5 in order to build the Editor.
23-
</strong>
24-
</i>
25-
26-
* If you're using Linux you can get Qt from your distribution's repositories.
27-
* `sudo pacman -S qt5-base`
28-
* If you're using Windows you'll need to download a prebuilt Qt5 package (installer) from the Qt Company's website.<br>
29-
You can try the link below. If that doesn't work you'll need an account with the Qt Company
30-
* http://download.qt.io/official_releases/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.zip
31-
3227

3328
## Step 1) Building the Editor & Engine for Desktop Windows 🪟
3429

35-
These build instructions are for MSVS 2019 Community Edition 64bit build.
30+
> [!IMPORTANT]
31+
> These build instructions are for MSVS 2019 Community Edition 64bit build.
3632
3733
<details><summary>How to install dependencies</summary>
3834

@@ -45,8 +41,10 @@ These build instructions are for MSVS 2019 Community Edition 64bit build.
4541

4642

4743
- Install prebuilt Qt 5.15.2<br>
44+
If the link doesn't work you'll need to create an account with the Qt company<br>
45+
and download the installer for the LGPL version (they like to hide this) from their site.<br>
4846
http://download.qt.io/official_releases/qt/5.15/5.15.2/single/qt-everywhere-src-5.15.2.zip
49-
47+
5048

5149
- Install Conan package manager (VERSION 2)<br>
5250
https://docs.conan.io/en/latest/installation.html
@@ -78,11 +76,10 @@ These build instructions are for MSVS 2019 Community Edition 64bit build.
7876

7977
<details><summary>How to build the project in DEBUG [OPTIONAL]</summary>
8078

81-
<br><i>
82-
Note that on MSVS the library interfaces change between debug/release build configs. (e.g. iterator debug levels).
83-
This means that in order to link to 3rd party libraries the debug versions of those libraries must be used.
84-
</i>
85-
</br>
79+
> [!WARNING]
80+
> Note that on MSVS the library interfaces change between debug/release build configs. (e.g. iterator debug levels).
81+
> This means that in order to link to 3rd party libraries the debug versions of those libraries must be used.
82+
8683

8784
- Open `Developer Command Prompt for VS 2019`
8885

@@ -126,7 +123,7 @@ Install these packages:
126123
- CMake build tool
127124
- Conan💩💩 package manager (VERSION 2)
128125
- On Archlinux you can use 'yay' to install conan + its dependencies from AUR*
129-
- See below for installing yay + conan💩💩
126+
- See below for installing yay + conan💩💩
130127
- Git version control system
131128
- Qt5 application framework
132129

@@ -229,24 +226,21 @@ you can try edit ~/.conan/settings.yaml. Search for the GCC versions and edit th
229226

230227
</details>
231228

232-
233-
234229
## Step 2) Building the Engine for HTML5/WASM 💩
235230

236-
<strong>
237-
<i>HTML5/WASM build is only required if you want to build and package your game for the web.<br>
238-
If you just want to try the editor or build native games you don't need this.
239-
</i>
240-
</strong>
241-
<br><br>
231+
> [!NOTE]
232+
> HTML5/WASM build is only required if you want to build and package your game for the web.<br>
233+
> If you just want to try the editor or build native games you don't need this.
234+
235+
<br>
242236
Some notes about building to HTML5/WASM.
243237

244238
* Building to HTML5/WASM is currently supported only for the engine but not the editor.
245-
* Current Emscripten💩 version is 3.1.10. Using other version will likely break things.
239+
* Current Emscripten💩 version is 3.1.50. Using other version will likely break things.
246240
* Building to HTML5/WASM will produce the required JS and WASM files to run games in the browser,<br>
247241
but you still need to build the editor in order to develop the game and package it.<br>
248-
* When you package your game through the editor, the HTML5/WASM game files are copied by the editor<br>
249-
during the packaging process in order to produce the final deployable game package.
242+
* When you package your game with the editor, the HTML5/WASM game files are copied by the editor<br>
243+
during the packaging process in order to produce the final deployable game package.
250244

251245
<details><summary>How to build on Linux 🐧</summary>
252246

@@ -256,16 +250,16 @@ Some notes about building to HTML5/WASM.
256250
$ git clone https://github.com/emscripten-core/emsdk.git
257251
$ cd emsdk
258252
$ git pull
259-
$ ./emsdk install 3.1.10
260-
$ ./emsdk activate 3.1.10
253+
$ ./emsdk install 3.1.50
254+
$ ./emsdk activate 3.1.50
261255
$ source ./emsdk_env.sh
262256
```
263257
- Check your Emscripten💩 installation
264258
```
265259
$ which emcc
266260
$ /home/user/emsdk/upstream/emscripten/emcc
267261
$ emcc --version
268-
$ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.0.0 (3fd52e107187b8a169bb04a02b9f982c8a075205)
262+
$ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.50 (047b82506d6b471873300a5e4d1e690420b582d0)
269263
```
270264
- Build the DETONATOR 2D engine into a WASM blob. Make sure that you have the Emscripten💩 tools in your path,
271265
i.e. you have sourced emsdk_env.sh in your current shell.
@@ -294,8 +288,8 @@ Some notes about building to HTML5/WASM.
294288
$ git clone https://github.com/emscripten-core/emsdk.git
295289
$ cd emsdk
296290
$ git pull
297-
$ emsdk.bat install 3.1.10
298-
$ emsdk.bat activate 3.1.10
291+
$ emsdk.bat install 3.1.50
292+
$ emsdk.bat activate 3.1.50
299293
$ emsdk_env.bat
300294
```
301295
- Check your Emscripten💩 and Ninja🥷 installation
@@ -304,7 +298,7 @@ Some notes about building to HTML5/WASM.
304298
$ C:\coding\detonator\emsdk\upstream\emscripten\emcc
305299
$ C:\coding\detonator\emsdk\upstream\emscripten\emcc.bat
306300
$ emcc --version
307-
$ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.10 (c3fe57af0504fe24fc4ba697feb8c204f3c80022)
301+
$ emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.50 (047b82506d6b471873300a5e4d1e690420b582d0)
308302
$ where ninja
309303
$ C:\coding\detonator\emsdk\ninja.exe
310304
$ ninja --version
@@ -327,7 +321,7 @@ Some notes about building to HTML5/WASM.
327321

328322
<details><summary>Build troubleshooting 💩</summary>
329323

330-
Windows: Emscripten💩 3.0.0 build fails with
324+
Windows: Emscripten💩 3.0.0 build fails with
331325

332326
```
333327
error: undefined symbol: _get_daylight (referenced by tzset_impl__deps: ['_get_daylight','_get_timezone','_get_tzname'], referenced by tzset__deps: ['tzset_impl'], referenced by localtime_r__deps: ['tzset'], referenced by __localtime_r__deps: ['localtime_r'], referenced by top-level compiled C/C++ code)
@@ -341,44 +335,52 @@ warning: __get_tzname may need to be added to EXPORTED_FUNCTIONS if it arrives f
341335
* https://github.com/emscripten-core/emscripten/issues/15958
342336
* Current fix is to upgrade to Emscripten💩 3.1.10
343337

344-
Build fails with
338+
Build fails with
345339
```
346340
wasm-ld: error: --shared-memory is disallowed by ldo.c.o because it was not compiled with 'atomics' or 'bulk-memory' features.
347341
```
348342

349343
* https://github.com/emscripten-core/emsdk/issues/790
350344
* This is trying to communicate that something was built without thread support when thread support should be enabled.<br>
351345
In other words trying to mix + match translation units / libs built with different build configuration.
352-
* Make sure to double check the build flags including `third_party/CMakeLists.txt`
346+
* Make sure to double check the build flags including `third_party/CMakeLists.txt`
353347

354348
</details>
355349

356350
If your build was successful there should now be `GameEngine.js`, `GameEngine.wasm` and `GameEngine.worker.js` files in the editor's `dist` folder.<br>
357351

358352
### Step 2.1) Deploying the Game for the Web 💩
359353

360-
When you package your game for the web the editor will copy all the required files to your chosen output directory.
354+
When you package your game for the web the editor will copy all the required files to your chosen output directory.
361355

362356
* GameEngine.js
363357
* GameEngine.wasm
364358
* GameEngine.worker.js
365359
* FILESYSTEM
366-
* FILESYSTEM.js
367-
* game.html
360+
* FILESYSTEM.js
361+
* game.html
368362

369363
These 6 files are then all the files that you need to deploy/copy over to your web server.<br><br>
370-
<i>Hint: You can rename `game.html` to whatever you want, for example `my-amazing-game.html`. Just don't change the names of any other files</i>
371-
364+
365+
366+
> [!HINT]
367+
> You can rename `game.html` to whatever you want, for example `my-amazing-game.html`. Just don't change the names of any other files
368+
369+
372370
<details><summary>1. Configure Your Web Server</summary>
373371

374-
<strong><i>You must enable the correct web policies💩 in order to enable SharedArrayBuffer💩 in order to enable threads !! </i>💩💩</strong><br>
375-
<strong><i>Without SharedArrayBuffer web worker threads can't run and the engine cannot work. </i>💩💩</strong><br>
376-
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
377372

378-
You must set the HTTP `Cross-Origin-Opener-Policy` to `same-origin` and `Cross-Origin-Embedder-Policy` to `require-corp`.<br>
373+
> [!IMPORTANT]
374+
> You must enable the correct web policies💩 in order to enable SharedArrayBuffer💩 in order to enable threads !! 💩💩
375+
> Without SharedArrayBuffer web worker threads can't run and the engine cannot work. 💩💩
376+
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
379377
380-
You can achieve this with a `.htaccess` file.<br>
381378

379+
> [!IMPORTANT]
380+
> You must set the HTTP `Cross-Origin-Opener-Policy` to `same-origin`
381+
> You must set the HTTP `Cross-Origin-Embedder-Policy` to `require-corp`
382+
>
383+
> You can achieve this with a `.htaccess` file.<br>
382384
383385
```
384386
Header set Access-Control-Allow-Origin "https://your-domain.com"
@@ -387,6 +389,7 @@ Header set Cross-Origin-Resource-Policy "same-site"
387389
Header set Cross-Origin-Opener-Policy "same-origin"
388390
Header set Access-Control-Allow-Headers "range"
389391
```
392+
390393
</details>
391394

392395
<details><summary>2. Deploy Your Game to Your Web Server</summary>
@@ -507,15 +510,15 @@ to indicate completion.
507510

508511
Download the yay package from AUR<br>
509512
https://aur.archlinux.org/packages/yay
510-
513+
511514
WARNING! BOTH YAY AND CONAN💩💩 WILL LIKELY HAVE MISSING DEPENDENCIES
512515

513516
install missing yay dependencies
514517
```
515518
$ sudo pacman -S debugedit
516519
```
517520

518-
build yay
521+
build yay
519522
```
520523
$ cd yay
521524
$ makepkg
@@ -530,8 +533,8 @@ use yay to install Conan💩💩
530533
```
531534
$ yay -S conan
532535
$ yay -S python-patch-ng
533-
$ ...
536+
$ ...
534537
$ conan --version
535538
$ Conan version 2.6.0
536-
$
539+
$
537540
```

emscripten/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/../third_party/libsamplera
2525
include_directories(BEFORE "${CMAKE_CURRENT_LIST_DIR}/../third_party/lua/src")
2626
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third_party "whatever")
2727

28+
add_link_options(-sMALLOC=mimalloc)
29+
add_link_options(-sSTACK_SIZE=5MB)
30+
2831
add_executable(UnitTest
2932
../base/test_minimal.cpp
3033
../base/unit_test/unit_test_math.cpp

third_party/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ if (CMAKE_SYSTEM_NAME MATCHES "Emscripten")
3535

3636
message(STATUS " -pthread")
3737
add_compile_options(-pthread)
38-
add_link_options(-pthread)
3938

39+
add_link_options(-pthread)
40+
add_link_options(-sMALLOC=mimalloc)
41+
add_link_options(-sSTACK_SIZE=5MB)
4042
endif()
4143
# Lua 5.4.3
4244
add_library(Lua

third_party/sol/sol.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19400,7 +19400,11 @@ namespace sol { namespace function_detail {
1940019400
struct upvalue_this_member_variable {
1940119401
typedef std::remove_pointer_t<std::decay_t<Function>> function_type;
1940219402

19403+
#if SOL_IS_ON(SOL_COMPILER_CLANG)
19404+
static int real_call(lua_State* L) noexcept {
19405+
#else
1940319406
static int real_call(lua_State* L) noexcept(std::is_nothrow_copy_assignable_v<T>) {
19407+
#endif
1940419408
// Layout:
1940519409
// idx 1...n: verbatim data of member variable pointer
1940619410
auto memberdata = stack::stack_detail::get_as_upvalues<function_type>(L);
@@ -19416,7 +19420,11 @@ namespace sol { namespace function_detail {
1941619420
}
1941719421

1941819422
template <bool is_yielding, bool no_trampoline>
19419-
static int call(lua_State* L) noexcept(std::is_nothrow_copy_assignable_v<T>) {
19423+
#if SOL_IS_ON(SOL_COMPILER_CLANG)
19424+
static int call(lua_State* L) noexcept {
19425+
#else
19426+
static int call(lua_State* L) noexcept(std::is_nothrow_copy_assignable_v<T>) {
19427+
#endif
1942019428
int nr;
1942119429
if constexpr (no_trampoline) {
1942219430
nr = real_call(L);

0 commit comments

Comments
 (0)