Compilando para Web

Requisitos

Para compilar modelos de exportação para a Web, é necessário fazer o seguinte:

Ver também

For a general overview of SCons usage for Godot, see Introduction to the buildsystem.

Building export templates

Antes de iniciar, confirme que o arquivo de configuração do Emscripten existe e especifica todas as configurações corretamente. Este arquivo está disponível como ~/.emscripten em sistemas baseados em UNIX e %USERPROFILE%\.emscripten em Windows. É geralmente escrito pelo SDK do Emscripten, por exemplo, quando chama emsdk activate latest, ou pelo seu gerenciador de pacote. É também criado quando inicia o programa emcc do Emscripten se o arquivo não existir.

Atenção

No Windows, certifique-se de escapar as barras invertidas de caminhos dentro do arquivo de configuração do Emscripten como \\ ou use caminhos tipo Unix com uma única barra /.

Open a terminal and navigate to the root directory of the engine source code. Then instruct SCons to build the JavaScript platform. Specify target as either release for a release build or release_debug for a debug build:

scons platform=javascript tools=no target=release
scons platform=javascript tools=no target=release_debug

By default, the JavaScript singleton will be built into the engine. Since eval() calls can be a security concern, the javascript_eval option can be used to build without the singleton:

scons platform=javascript tools=no target=release javascript_eval=no
scons platform=javascript tools=no target=release_debug javascript_eval=no

The engine will now be compiled to WebAssembly by Emscripten. Once finished, the resulting file will be placed in the bin subdirectory. Its name is godot.javascript.opt.zip for release or godot.javascript.opt.debug.zip for debug.

Finally, rename the zip archive to webassembly_release.zip for the release template:

mv bin/godot.javascript.opt.zip bin/webassembly_release.zip

And webassembly_debug.zip for the debug template:

mv bin/godot.javascript.opt.debug.zip bin/webassembly_debug.zip

Building per asm.js translation or LLVM backend

WebAssembly can be compiled in two ways: The default is to first compile to asm.js, a highly optimizable subset of JavaScript, using Emscripten’s fastcomp fork of LLVM. This code is then translated to WebAssembly using a tool called asm2wasm. Emscripten automatically takes care of both processes, we simply run SCons.

The other method uses LLVM’s WebAssembly backend. This backend is available starting with LLVM 8 or in development builds. Emscripten manages this process as well, so we just invoke SCons.

In order to choose one of the two methods, the LLVM_ROOT variable in the Emscripten configuration file is used. If it points to a directory containing binaries of Emscripten’s fastcomp fork of clang, asm2wasm is used. This is the default in a normal Emscripten installation. Otherwise, LLVM binaries built with the WebAssembly backend will be expected and the LLVM’s WebAssembly backend is used.