Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
s0l0ist committed Mar 20, 2021
1 parent 1321d19 commit d067aa2
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,63 @@ lipo -create -output build/lib/libsealc.a build/lib/x86_64/libsealc-*.a build/li
The native libraries generated through these methods are meant to be called only through the .NET library described in the following sections.
Specifically, they do not contain any wrappers that can be used from Java (for Android) or Objective C (for iOS).

#### Building for WebAssembly

Microsoft SEAL can be compiled for the JavaScript and WebAssembly using [emscripten](https://emscripten.org). Building for the Web means SEAL can be run in any client/server environment such as all the major browsers (e.g. Edge, Chrome, Firefox, Safari) and NodeJS.

Building for WebAssembly requires the emscripten toolchain to be installed. The easiest way to configure the toolchain is to clone [emsdk](https://github.com/emscripten-core/emsdk) somewhere on your system and follow the instructions in the README.

Inside the `emsdk` repo, run the following:
```PowerShell
# Install the latest toolchain
./emsdk install latest
./emsdk activate latest
# Source the environment
source ./emsdk_env.sh
```

With the same shell, navigate to the root directory of Microsoft SEAL, run the following commands to build for WebAssembly:

```PowerShell
# Configure CMake. Example flags for a release build
emcmake cmake \
-DSEAL_USE_CXX17=ON \
-DCMAKE_CXX_FLAGS_RELEASE="-DNDEBUG -flto -O3" \
-DCMAKE_C_FLAGS_RELEASE="-DNDEBUG -flto -O3" \
-DSEAL_USE_INTRIN=OFF \
-DSEAL_USE_ZLIB=ON \
-DSEAL_USE_MSGSL=OFF \
-DSEAL_BUILD_EXAMPLES=OFF \
-DSEAL_BUILD_TESTS=OFF \
-DBUILD_SHARED_LIBS=OFF \
-DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=ON \
-DCMAKE_BUILD_TYPE=Release \
.
# Make the static library (shared libs are not supported with emscripten)
emmake make -j
# Build the WebAssembly module
emcc \
-Wall \
-flto \
-O3 \
lib/libseal-3.6.a \
--bind \
-o "bin/seal_wasm.js" \
-s WASM=1 \
-s ALLOW_MEMORY_GROWTH=1
```
**Note**: There are many flags to consider when building a WebAssembly module. Please refer to the [settings.js](https://github.com/emscripten-core/emscripten/blob/main/src/settings.js) file for advanced build flags.

Building will generate two output files in the top-level `bin/` directory:
- seal_wasm.js
- seal_wasm.wasm

Notice the file sizes for the artifacts are very small. This is because the optimization flags performed DCE as there are no JavaScript <-> WebAssembly "bindings". Defining these bindings is **necessary** in order to call into WebAssembly from the JavaScript domain; however, Microsoft SEAL does not include any definitions at this time. The build flag `--bind` expects the bindings to be specified using the [embind](https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html) syntax.

#### Basic CMake Options

The following options can be used with CMake to configure the build. The default value for each option is denoted with boldface in the **Values** column.
Expand Down

0 comments on commit d067aa2

Please sign in to comment.