This is example boilerplate code of how to write code in C++ that is compiled using make and mingw32-make and then how to transpile it into javascript. Finally, it provides two example test projects, one for the javascript output and one for the C++ output.
- client-shared-cpp - The C++ library code
- client-shared-cpp-test - The C++ test code for the library
- client-shared-js - The transpiled javascript code associated with the C++ library
- client-shared-js-test-jest - A jest based javascript test suite for the transpiled library
- client-shared-js-test-jest - A mocha based javascript test suite for the transpiled library
- client-web-raw - A sample web application that uses basic web technologies to load the transpiled library
- client-web-webpack - A webpack sample application that uses webpack for two websites; one in React and one in Knockout
git clone --recursive https://github.com/snowcoders/boilerplate-emscripten-typescript/
or if you already cloned it just run
git submodule update --init --recursive
in the root directory
There are several dependencies to compiling this project.
Emscripten is a C++ to JavaScript compiler which converts C++ code into JavaScript. http://kripken.github.io/emscripten-site/ You'll need the SDK at minimum
Mingw64 allows for make to be run on windows. http://mingw-w64.org/
Note: I've been doing this on Windows but it should compile on unix or linux with a few minor fixes. Most likely, it's the npm scripts that would give you the biggest hurdles.
On Windows
- Open a prompt window
- Setup the emscripten sdk by running
emsdk_env.bat
from wherever you installed - Set the path to include your MinGW location (e.g.
PATH = %PATH%;D:/MinGW/mingw64/bin
) - Run
mingw32-make
On Unix (or Unix based system)
- Open a terminal window
- Setup the emscripten sdk by running
source ./emsdk_env.sh
from wherever you installed - Run
make
Other notes:
- You can also run make from the root directory, and it will recurse into all the sub directories.
- Use the -jN feature to run multiple processors for faster builds
- Build client-shared-js
- Run npm install
After building there should be two files
- client-shared-cpp-test/debug/client-shared-test.exe
- client-shared-cpp-test/ship/client-shared-test.exe
You can change the reporter status to get more details from the tests. --reporter=spec
is a pretty good start, more information can be found via banditcpp's documentation
- Go into the directory
- Run
npm run test
.
- Go into the directory
- Run
npm run start
.
This example code was last verified on Windows on October 1st, 2018
Tool | Version |
---|---|
Windows | 10 Version 1803 |
EMCC | 1.38.12 (commit 0d8576c0e8f5ee09a36120b9d44184b5da2f2e7a) |
Node | 8.9.1 |
mingw32-make | v5.0.0 |
This example code was last verified on OSX on October 1st, 2018
Tool | Version |
---|---|
macOS | Version 10.13.6 |
EMCC | 1.38.12 (commit 0d8576c0e8f5ee09a36120b9d44184b5da2f2e7a) |
Node | 8.12.0 |
make | GNU Make 3.81 |
October 2018
- Removed karma test example
- Added jest test example
- Renamed several folders for consistency
- Updated to the latest Emscripten