diff --git a/.circleci/config.yml b/.circleci/config.yml index ec7b6eb368..294ff225d4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,7 +30,7 @@ jobs: - run: name: Install Emscripten (for GDevelop.js) - command: git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 1.39.6 && ./emsdk activate 1.39.6 && cd .. + command: git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 3.1.21 && ./emsdk activate 3.1.21 && cd .. # GDevelop.js dependencies - restore_cache: @@ -107,7 +107,7 @@ jobs: - run: name: Install Emscripten (for GDevelop.js) - command: git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 1.39.6 && ./emsdk activate 1.39.6 && cd .. + command: git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 3.1.21 && ./emsdk activate 3.1.21 && cd .. - run: name: Install system dependencies for Electron builder @@ -127,7 +127,8 @@ jobs: # Build GDevelop.js (and run tests to ensure it works) - run: name: Build GDevelop.js - command: cd GDevelop.js && source ../emsdk/emsdk_env.sh && npm run build && npm test && cd .. + # Use "--runInBand" as it's faster and avoid deadlocks on CircleCI Linux machines (probably because limited in processes number). + command: cd GDevelop.js && source ../emsdk/emsdk_env.sh && npm run build && npm test -- --runInBand && cd .. # GDevelop IDE dependencies (after building GDevelop.js to avoid downloading a pre-built version) - run: @@ -184,7 +185,7 @@ jobs: - run: name: Install Emscripten (for GDevelop.js) - command: git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 1.39.6 && ./emsdk activate 1.39.6 && cd .. + command: git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 3.1.21 && ./emsdk activate 3.1.21 && cd .. # GDevelop.js dependencies - restore_cache: @@ -200,7 +201,8 @@ jobs: # Build GDevelop.js (and run tests to ensure it works) - run: name: Build GDevelop.js - command: cd GDevelop.js && source ../emsdk/emsdk_env.sh && npm run build && npm test && cd .. + # Use "--runInBand" as it's faster and avoid deadlocks on CircleCI Linux machines (probably because limited in processes number). + command: cd GDevelop.js && source ../emsdk/emsdk_env.sh && npm run build && npm test -- --runInBand && cd .. - save_cache: paths: diff --git a/.gitpod.yml b/.gitpod.yml index f6b7c13f96..348b6b5916 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -14,7 +14,7 @@ tasks: init: | sudo apt-get update sudo apt install cmake python-is-python3 python3-distutils -y - git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 1.39.6 && ./emsdk activate 1.39.6 && cd .. + git clone https://github.com/juj/emsdk.git && cd emsdk && ./emsdk install 3.1.21 && ./emsdk activate 3.1.21 && cd .. cd GDevelop.js npm install source ../emsdk/emsdk_env.sh && npm run build -- --dev diff --git a/.travis.yml b/.travis.yml index eac39ccb16..98ec2f1d36 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ install: - cd .. # Install Emscripten (for GDevelop.js) - git clone https://github.com/juj/emsdk.git - - cd emsdk && ./emsdk install 1.39.6 && ./emsdk activate 1.39.6 && cd .. + - cd emsdk && ./emsdk install 3.1.21 && ./emsdk activate 3.1.21 && cd .. # Install GDevelop.js dependencies - cd GDevelop.js && npm install && cd .. # Build GDevelop.js diff --git a/GDevelop.js/CMakeLists.txt b/GDevelop.js/CMakeLists.txt index 23f53a7f01..8ab72e1071 100644 --- a/GDevelop.js/CMakeLists.txt +++ b/GDevelop.js/CMakeLists.txt @@ -12,8 +12,17 @@ if(NOT EMSCRIPTEN) endif() # Compilation flags (https://emscripten.org/docs/tools_reference/emcc.html): -add_compile_options(-O2) # Optimizations during compilation -#add_compile_options(-g --profiling) # Uncomment for debugging + profiling support +add_compile_options(-O3 -flto) # Optimizations during compilation +# add_compile_options(-fwasm-exceptions) # Enable exceptions +if(NOT DISABLE_EMSCRIPTEN_LINK_OPTIMIZATIONS) + add_compile_options(-flto) # The compiler needs to know if there will be link time optimisations +endif() + +# Compiler debugging options +# +# add_compile_options(-fsanitize=address) # Uncomment to auto-detect occurences of memory bugs (memory leak, use after free, overflows, ...) - also enable linking below! +# add_compile_options(-fsanitize=undefined) # Uncomment to auto-detect occurences of undefined behavior - also enable linking below! +# add_compile_options(-g) # Uncomment for debugging support # add_compile_options(--profiling) # Uncomment for profiling support # Common directories: @@ -64,7 +73,7 @@ if(DISABLE_EMSCRIPTEN_LINK_OPTIMIZATIONS) message(STATUS "Disabling optimization at link time for (slightly) faster build") target_link_libraries(GD "-O0") else() - target_link_libraries(GD "-O2") + target_link_libraries(GD "-O3 -flto") endif() target_link_libraries(GD "--post-js ${GD_base_dir}/GDevelop.js/Bindings/glue.js") target_link_libraries(GD "--post-js ${GD_base_dir}/GDevelop.js/Bindings/postjs.js") @@ -73,7 +82,17 @@ target_link_libraries(GD "-s EXPORT_NAME=\"initializeGDevelopJs\"") # Global fun target_link_libraries(GD "-s TOTAL_MEMORY=48MB") # Get some initial memory size that is a bit bigger than the default. target_link_libraries(GD "-s ALLOW_MEMORY_GROWTH=1") target_link_libraries(GD "-s ERROR_ON_UNDEFINED_SYMBOLS=0") -target_link_libraries(GD "-s \"EXTRA_EXPORTED_RUNTIME_METHODS=['addOnPreMain', 'calledRun', 'UTF8ToString']\"") +target_link_libraries(GD "-s \"EXPORTED_FUNCTIONS=['_free']\"") + +# Linker debugging options +# +# target_link_libraries(GD "-s DEMANGLE_SUPPORT=1") # Demangle stack traces +# target_link_libraries(GD "-s ASSERTIONS=1") # Basic runtime memory allocation checks (necessary for wasm exceptions stack traces) +# target_link_libraries(GD "-s ASSERTIONS=2 -s SAFE_HEAP=1") # Uncomment to do runtime checks for memory allocations and access errors +# target_link_libraries(GD "-fsanitize=address") # Uncomment to auto-detect occurences of memory bugs (memory leak, use after free, overflows, ...) - also enable compiling above! +# target_link_libraries(GD "-fsanitize=undefined") # Uncomment to auto-detect occurences of undefined behavior - also enable compiling above! +# target_link_libraries(--cpuprofiler) # Uncomment for interactive performance profiling +# target_link_libraries(--memoryprofiler) # Uncomment for interactive memory profiling # Even if we're building an "executable", prefix it by lib as it's used as a library. set_target_properties(GD PROPERTIES PREFIX "lib") diff --git a/GDevelop.js/Gruntfile.js b/GDevelop.js/Gruntfile.js index 8d468fad70..a5c6151a43 100644 --- a/GDevelop.js/Gruntfile.js +++ b/GDevelop.js/Gruntfile.js @@ -10,7 +10,7 @@ module.exports = function (grunt) { const buildOutputPath = '../Binaries/embuild/GDevelop.js/'; const buildPath = '../Binaries/embuild'; - let cmakeBinary = 'emconfigure cmake'; + let cmakeBinary = 'emcmake cmake'; let cmakeGeneratorArgs = []; let makeBinary = 'emmake make'; let makeArgs = ['-j 4']; @@ -44,11 +44,11 @@ module.exports = function (grunt) { // Find CMake in usual folders or fallback to PATH. if (fs.existsSync('C:\\Program Files\\CMake\\bin\\cmake.exe')) { - cmakeBinary = 'emconfigure "C:\\Program Files\\CMake\\bin\\cmake"'; + cmakeBinary = 'emcmake "C:\\Program Files\\CMake\\bin\\cmake"'; } else if ( fs.existsSync('C:\\Program Files (x86)\\CMake\\bin\\cmake.exe') ) { - cmakeBinary = 'emconfigure "C:\\Program Files (x86)\\CMake\\bin\\cmake"'; + cmakeBinary = 'emcmake "C:\\Program Files (x86)\\CMake\\bin\\cmake"'; } else { console.log( "⚠️ Can't find CMake in its usual Program Files folder. Make sure you have cmake in your PATH instead." diff --git a/GDevelop.js/README.md b/GDevelop.js/README.md index 3bf45ced4c..f884a11b32 100644 --- a/GDevelop.js/README.md +++ b/GDevelop.js/README.md @@ -9,24 +9,30 @@ This is the port of GDevelop core classes to WebAssembly+JavaScript. This allows > 👋 Usually, if you're working on the GDevelop editor or extensions in JavaScript, you don't need to rebuild GDevelop.js. If you want to make changes in C++ extensions or classes, read this section. - Prerequisite tools installed: + - [CMake 3.17+](http://www.cmake.org/) (3.5+ should work on Linux/macOS). On macOS, you can install it via Homebrew (recommended for Apple M1 Architectures). - [Node.js](https://nodejs.org/). (We recommend using [nvm](https://github.com/nvm-sh/nvm) to be able to switch between Node versions easily). - Python (via [pyenv](https://github.com/pyenv/pyenv) for versions management). -- Install [Emscripten](https://github.com/kripken/emscripten), as explained below or on the [Emscripten installation instructions](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html): +- Install [Emscripten](https://github.com/kripken/emscripten) version `3.1.21`, as explained below or on the [Emscripten installation instructions](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html): -| Linux/macOS | Windows | -| -------------------------------------------- | -------------------------------------------- | -| `git clone https://github.com/juj/emsdk.git` | `git clone https://github.com/juj/emsdk.git` | -| `cd emsdk` | `cd emsdk` | -| `git pull` | `git pull` | -| `./emsdk install 1.39.6` | `emsdk install 1.39.6` | -| `./emsdk activate 1.39.6` | `emsdk activate 1.39.6` | -| `source ./emsdk_env.sh` | `emsdk_env.bat` | +```bash +git clone https://github.com/emscripten-core/emsdk/ +cd emsdk +git pull +./emsdk install 3.1.21 +./emsdk activate 3.1.21 +``` > ⚠️ If you are on Apple M1, this version of emsdk may not be available for this architecture and you will get an error when installing it, indicating a missing binary. If this is the case, a workaround is to modify the `emsdk.py` line 132 with `machine = 'x86_64'` to ensure a correct binary is downloaded. -- Launch the build from GDevelop.js folder: +- Whenever you try to build GDevelop.js in the future, you will have to load the emsdk environement into your terminal window again by running: + +| Linux/macOS | Windows (Powershell) | Windows (cmd.exe) | +| ----------------------- | -------------------- | ----------------- | +| `source ./emsdk_env.sh` | `./emsdk_env.ps1` | `./emsdk_env.bat` | + +- With the emscripten environement loaded into your terminal, launch the build from GDevelop.js folder: ```bash cd GDevelop.js @@ -38,6 +44,8 @@ npm run build > ℹ️ Output is created in _/path/to/GD/Binaries/embuild/GDevelop.js/_ and also copied to GDevelop 5 IDE (`newIDE` folder). +> ℹ️ You only need to run `npm install` the first time you make a build. + -> ⏱ The linking (last step) of the build can be made a few seconds faster by specifying `-- --dev`. Be sure to remove it before building a release version, as this disable "link-time optimizations" of the generated WebAssembly module. - You can then launch GDevelop 5 that will use your build of GDevelop.js: diff --git a/GDevelop.js/ninja/ninja.exe b/GDevelop.js/ninja/ninja.exe index 3c95c0a3c7..e4fafa04c3 100644 Binary files a/GDevelop.js/ninja/ninja.exe and b/GDevelop.js/ninja/ninja.exe differ diff --git a/appveyor.yml b/appveyor.yml index 77ebe04e48..53100cfd97 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,8 +19,6 @@ init: install: # Build GDevelop.js (and run tests to ensure it works). # (in a subshell to avoid Emscripten polluting the Node.js and npm version for the rest of the build) - # Also install setuptools as our old version of Emscripten uses distutils which was removed in Python 3.12. - # setuptools will make distutils available again (but we should migrate to a newer Emscripten version). - cmd: >- cd GDevelop.js @@ -30,16 +28,18 @@ install: cd emsdk - emsdk install 1.39.6 - - CMD /C "emsdk activate 1.39.6 && pip install setuptools && cd .. && npm run build" - + emsdk install 3.1.21 + CMD /C "emsdk activate 3.1.21 && cd .. && npm run build" cd ..\.. - # Build GDevelop IDE + # Build GDevelop IDE. + # Also install setuptools as something requires distutils in electron-app, and it was removed in Python 3.12. + # setuptools will make distutils available again (but we should migrate our packages probably). - cmd: >- + pip install setuptools + cd newIDE\app npm -v && npm install