Building with VS Code tasks

We're going to configure the build in two ways: with VS Code tasks and a Makefile. Makefiles are nice if you prefer to use a different editor than VS Code. The /.vscode/tasks.json file already contains the tasks you'll need to build the project. The Emscripten build step is the default (a set of native build tasks is also present). Let's walk through each task in the tasks array and review what's taking place. The first task deletes any existing compiled output files prior to building:

{
"label": "Remove Existing Web Files",
"type": "shell",
"command": "rimraf",
"options": {
"cwd": "${workspaceRoot}/public"
},
"args": [
"index.js",
"index.wasm"
]
}

The second task performs the build with the emcc command:

{
"label": "Build WebAssembly",
"type": "shell",
"command": "emcc",
"args": [
"--bind", "src/board.cpp", "src/piece.cpp", "src/main.cpp",
"-std=c++14",
"-O3",
"-s", "WASM=1",
"-s", "USE_SDL=2",
"-s", "MODULARIZE=1",
"-o", "public/index.js"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"dependsOn": ["Remove Existing Web Files"]
}

The related arguments are placed on the same line. The only new and unfamiliar addition to the args array is the --bind argument with the corresponding .cpp files. This tells Emscripten that all the files after --bind are required to build the project. Test out the build by selecting Tasks | Run Build Task... from the menu or using the keyboard shortcut Cmd/Ctrl + Shift + B. It takes a few seconds to build, but the terminal will let you know when the compilation process is complete. If successful, you should see an index.js and index.wasm file in the /public folder.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset