From a03f1f599c198f99de47b9e6ed60634ae97c2815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Aug 2017 16:36:44 +0200 Subject: [PATCH] Initial WebAssembly support. --- README.md | 2 +- doc/building.dox | 29 +++++++---- doc/changelog.dox | 1 + doc/mainpage.dox | 2 +- package/archlinux/PKGBUILD-emscripten-wasm | 50 ++++++++++++++++++ .../archlinux/PKGBUILD-emscripten-wasm-webgl2 | 51 +++++++++++++++++++ toolchains | 2 +- 7 files changed, 124 insertions(+), 13 deletions(-) create mode 100644 package/archlinux/PKGBUILD-emscripten-wasm create mode 100644 package/archlinux/PKGBUILD-emscripten-wasm-webgl2 diff --git a/README.md b/README.md index 3a4f84809..3dd81f144 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ Platforms: * **iOS** (through SDL2 toolkit) [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum) * **Android** 2.3 (API Level 9) and higher [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum) * **Windows RT** (Store/Phone) using ANGLE (through SDL2 toolkit) [![Build Status](https://ci.appveyor.com/api/projects/status/5b477m034cfaskse/branch/master?svg=true)](https://ci.appveyor.com/project/mosra/magnum/branch/master) -* **HTML5/JavaScript** (through [Emscripten](https://github.com/kripken/emscripten/wiki)) [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum) +* **Web** (asm.js or WebAssembly), through [Emscripten](http://kripken.github.io/emscripten-site/) [![Build Status](https://travis-ci.org/mosra/magnum.svg?branch=master)](https://travis-ci.org/mosra/magnum) FEATURES ======== diff --git a/doc/building.dox b/doc/building.dox index bd7c10676..0ff4a6a6b 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -485,13 +485,18 @@ make it available for depending projects. @subsection building-cross-emscripten Crosscompiling for Emscripten -You will need [Emscripten](https://github.com/kripken/emscripten/wiki/Tutorial) -installed and configured. - -Don't forget to adapt `EMSCRIPTEN_PREFIX` variable in `generic/Emscripten.cmake` -to path where Emscripten is installed. Default is `/usr/lib/emscripten`. -Emscripten supports dynamic libraries only to simplify porting and they are -generally slower, thus `BUILD_STATIC` is implicitly enabled. +You will need [Emscripten](http://kripken.github.io/emscripten-site/docs/getting_started/Tutorial.html) +installed and configured. The toolchains require CMake 3.7 or newer to properly +set compiler and linker flags. + +There are two toolchain files. The `generic/Emscripten.cmake` is for the +classical (asm.js) build, the `generic/Emscripten-wasm.cmake` is for +WebAssembly build. Don't forget to adapt `EMSCRIPTEN_PREFIX` variable in +`generic/Emscripten*.cmake` to path where Emscripten is installed; you can also +pass it explicitly on command-line using `-DEMSCRIPTEN_PREFIX`. Default is +`/usr/lib/emscripten`. Emscripten supports dynamic libraries only to simplify +porting and they are generally slower, thus `BUILD_STATIC` is implicitly +enabled. Then create build directory and run cmake and build command in it. Be sure to set `CMAKE_INSTALL_PREFIX` to path contained in `EMSCRIPTEN_TOOLCHAIN_PATH`. @@ -514,9 +519,13 @@ make it available for depending projects. If you have Node.js installed, you can also build and run unit tests using `ctest`. See `BUILD_TESTS` above. -For ArchLinux there is also prepared package file in `package/archlinux`, -named `PKGBUILD-emscripten`, see @ref building-packages-arch "above" for more -information. +For ArchLinux there are also prepared package files in `package/archlinux`, +named `PKGBUILD-emscripten`, `PKGBUILD-emscripten-webgl2`, +`PKGBUILD-emscripten-noopt`, `PKGBUILD-emscripten-noopt-webgl2`, +`PKGBUILD-emscripten-wasm` and `PKGBUILD-emscripten-wasm-webgl2`, see +@ref building-packages-arch "above" for more information. The first two are for +WebGL 1 / WebGL 2 optimized asm.js build (*slow* to compile), the second for +unoptimized build (faster to compile) and the third for WebAssembly build. See @ref Platform::Sdl2Application documentation for more information about building your projects for Emscripten. diff --git a/doc/changelog.dox b/doc/changelog.dox index 38aba57cb..2fa9f05e0 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -46,6 +46,7 @@ namespace Magnum { - ANGLE ES2/ES3 support, ability to create desktop GLES contexts on Windows - Windows Phone/Store support via ANGLE - iOS support +- WebAssembly support when building for Emscripten - WebGL 2.0 support - New OpenGL extension support: - @extension{EXT,draw_buffers} ES2 extension diff --git a/doc/mainpage.dox b/doc/mainpage.dox index 5b6f2aa5a..5708b81e3 100644 --- a/doc/mainpage.dox +++ b/doc/mainpage.dox @@ -83,7 +83,7 @@ Platforms: - **iOS** (through SDL2 toolkit) - **Android** 2.3 (API Level 9) and higher - **Windows RT** (Store/Phone) using ANGLE (through SDL2 toolkit) -- **HTML5/JavaScript** (through [Emscripten](https://github.com/kripken/emscripten/wiki)) +- **Web** (asm.js or WebAssembly), through [Emscripten](http://kripken.github.io/emscripten-site/) @section mainpage-features Features diff --git a/package/archlinux/PKGBUILD-emscripten-wasm b/package/archlinux/PKGBUILD-emscripten-wasm new file mode 100644 index 000000000..a14ce7983 --- /dev/null +++ b/package/archlinux/PKGBUILD-emscripten-wasm @@ -0,0 +1,50 @@ +# Author: mosra +pkgname=emscripten-magnum +pkgver=dev.wasm +pkgrel=1 +pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (Emscripten, wasm)" +arch=('any') +url="http://magnum.graphics" +license=('MIT') +depends=('emscripten-corrade') +makedepends=('cmake' 'emscripten' 'corrade' 'ninja') +options=('!strip' '!buildflags') + +_rootdir=$startdir/../../ + +build() { + if [ ! -d "$_rootdir/build-emscripten-wasm" ] ; then + mkdir "$_rootdir/build-emscripten-wasm" + cd "$_rootdir/build-emscripten-wasm" + + cmake .. \ + -DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/Emscripten-wasm.cmake" \ + -DCMAKE_PREFIX_PATH=/usr/lib/emscripten/system \ + -G Ninja + fi + + cd "$_rootdir/build-emscripten-wasm" + + cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/lib/emscripten/system \ + -DWITH_AUDIO=ON \ + -DWITH_SDL2APPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_OBJIMPORTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -DBUILD_TESTS=ON + ninja +} + +check() { + cd "$_rootdir/build-emscripten-wasm" + CORRADE_TEST_COLOR=ON ctest --output-on-failure -E ALTest +} + +package() { + cd "$_rootdir/build-emscripten-wasm" + DESTDIR="$pkgdir/" ninja install +} diff --git a/package/archlinux/PKGBUILD-emscripten-wasm-webgl2 b/package/archlinux/PKGBUILD-emscripten-wasm-webgl2 new file mode 100644 index 000000000..30b321075 --- /dev/null +++ b/package/archlinux/PKGBUILD-emscripten-wasm-webgl2 @@ -0,0 +1,51 @@ +# Author: mosra +pkgname=emscripten-magnum +pkgver=dev.wasm.webgl2 +pkgrel=1 +pkgdesc="C++11/C++14 and OpenGL 2D/3D graphics engine (Emscripten WebGL 2.0, wasm)" +arch=('any') +url="http://magnum.graphics" +license=('MIT') +depends=('emscripten-corrade') +makedepends=('cmake' 'emscripten' 'corrade' 'ninja') +options=('!strip' '!buildflags') + +_rootdir=$startdir/../../ + +build() { + if [ ! -d "$_rootdir/build-emscripten-wasm-webgl2" ] ; then + mkdir "$_rootdir/build-emscripten-wasm-webgl2" + cd "$_rootdir/build-emscripten-wasm-webgl2" + + cmake .. \ + -DCMAKE_TOOLCHAIN_FILE="$_rootdir/toolchains/generic/Emscripten-wasm.cmake" \ + -DCMAKE_PREFIX_PATH=/usr/lib/emscripten/system \ + -G Ninja + fi + + cd "$_rootdir/build-emscripten-wasm-webgl2" + + cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=/usr/lib/emscripten/system \ + -DTARGET_GLES2=OFF \ + -DWITH_AUDIO=ON \ + -DWITH_SDL2APPLICATION=ON \ + -DWITH_MAGNUMFONT=ON \ + -DWITH_OBJIMPORTER=ON \ + -DWITH_TGAIMAGECONVERTER=ON \ + -DWITH_TGAIMPORTER=ON \ + -DWITH_WAVAUDIOIMPORTER=ON \ + -DBUILD_TESTS=ON + ninja +} + +check() { + cd "$_rootdir/build-emscripten-wasm-webgl2" + CORRADE_TEST_COLOR=ON ctest --output-on-failure -E ALTest +} + +package() { + cd "$_rootdir/build-emscripten-wasm-webgl2" + DESTDIR="$pkgdir/" ninja install +} diff --git a/toolchains b/toolchains index 1e2799dc3..5f1b09a6f 160000 --- a/toolchains +++ b/toolchains @@ -1 +1 @@ -Subproject commit 1e2799dc30540b5d0a90395d654aec63116e9d6e +Subproject commit 5f1b09a6f953a375e03991b2b408175d13f20888