WebAssembly build on Linux, macOS, and Windows¶
Initialize PqCpAbe or a scheme class with its asynchronous .create() method.
Use instance.api for functional methods, including file operations in WASM.
The default Emscripten factory is available for compatibility. JavaScript SDK guide
The build includes AC17, TKN20, CoverCrypt, parameterized AES-GCM, ML-DSA and standalone ML-KEM, and the CLI entry point.
Rust archives use panic=unwind with native WebAssembly exception handling.
The C++ core and Crypto++ are built with -fwasm-exceptions to match. The
runtime must support native WASM exceptions; use the Node version supplied by
the activated Emscripten SDK for build verification. Custom consumers must
rebuild and link all archives with this exception mode consistently.
Run all commands from the repository root. Choose the section for your platform and keep setup, activation, build and tests in the same terminal.
configure --wasm checks the toolchain without installing anything.
configure --wasm --install installs missing host tools, Rust nightly with
rust-src, and Emscripten SDK 7.0.0 when no compatible SDK is activated.
It reuses a compatible active SDK; otherwise it uses $EMSDK if set, or creates
build/tools/emsdk/. The SDK is obtained from the
official Emscripten repository.
If check-only reports all tools as [OK] and prints Ready, use the existing
environment to build directly. Check-only does not create activation scripts.
Only source/call the generated scripts after running --install successfully,
or when those scripts already exist from an earlier setup.
Configure runs as a child
process, so its environment changes do not reach your current terminal. It
writes activation scripts with the detected SDK path; you do not need to locate
emsdk_env.sh or emsdk_env.bat manually. Go must satisfy
bindings/ffi/circl/go.mod; Node.js 18+ is required (the SDK also provides Node).
Linux, WSL, and macOS¶
Use one Unix shell, from the repository root. Check only:
sh ./configure --wasm
If the check succeeds, build directly in this shell:
make wasm -j8
make wasm-test -j8
If tools are missing, install them and generate activation:
sh ./configure --wasm --install
After installation, activate, then build and test in the same shell:
. ./build/tools/activate.sh
. ./build/tools/activate-wasm.sh
make wasm -j8
make wasm-test -j8
activate.sh adds the host tools, including the Homebrew GNU Make path on macOS;
activate-wasm.sh adds the WASM SDK environment. Both files are generated by
the install command. Check-only mode does not create them.
On macOS, finish any Apple Command Line Tools installer before rerunning configure. Intel and Apple Silicon use the SDK for the host architecture. Run activation again in each new shell; installing toolchains is only necessary when tools are missing or need updating.
Windows x64 with MSYS2¶
Start in x64 Native Tools Command Prompt and keep that one cmd session for setup, activation, build and tests. Install Visual Studio or Build Tools from Microsoft with Desktop development with C++, MSVC x64/x86 tools and a Windows SDK.
Follow the native Windows setup in this
same cmd to install the base tools (including MSYS2) and generate
build\tools\activate.cmd. From the repository root:
call build\tools\activate.cmd
set "MSYSTEM=MINGW64"
Check only (does not install missing WASM tools):
C:\msys64\usr\bin\bash.exe -c "sh ./configure --wasm"
If the check succeeds, build directly:
C:\msys64\usr\bin\bash.exe -c "make wasm -j8"
C:\msys64\usr\bin\bash.exe -c "make wasm-test -j8"
If tools are missing, install them and generate activation:
C:\msys64\usr\bin\bash.exe -c "sh ./configure --wasm --install"
This installs missing MSYS2 build tools, Rust nightly with rust-src, and
Emscripten. Adjust C:\msys64 if MSYS2 is installed elsewhere.
Activate the generated WASM environment, then build and test in the same cmd:
call build\tools\activate-wasm.cmd
C:\msys64\usr\bin\bash.exe -c "make wasm -j8"
C:\msys64\usr\bin\bash.exe -c "make wasm-test -j8"
Bash runs as a child process and returns to this same x64 cmd. It inherits the activated MSVC, Go, Rust and Emscripten environment; no additional terminal is needed. Repeat activation in each new build session. Windows liboqs uses Ninja.
If already using an MSYS2 MINGW64 terminal, stay in that terminal:
The Microsoft C++ tools and Windows SDK must already be installed. Windows Go and Rust/rustup must be accessible, or the install command will invoke the native Windows installer for them. Use the Windows MSVC Rust toolchain, not an MSYS-targeted Rust installation. For a fresh machine, use the x64 cmd setup above.
sh ./configure --wasm
If the check succeeds, run the Make commands below directly. If tools are missing, first install and activate:
sh ./configure --wasm --install
. ./build/tools/activate-wasm.sh
Build and test:
make wasm -j8
make wasm-test -j8
Build targets and outputs¶
Verified on Linux/WSL with Emscripten 7.0.0, Rust 1.99.0 nightly, Go 1.25.0 and Node.js 18.19.1. Tests cover all three schemes through file/buffer APIs, policy denial, ML-DSA signing/verification, and rejection of modified ciphertext.
From a repository checkout with a WASM build in lib/wasm, run the full Node.js
self-test directly:
node bindings/wasm/cli.mjs --test
The bundled command runs the compatibility self-test in WASM's in-memory
filesystem. make wasm-test also checks all public export names, the functional
and object APIs, and the 6.1 CLI.
Run node bindings/wasm/cli.mjs --help for file-based commands including setup,
key generation, encryption, and decryption. The
npm CLI examples
also work from the repository when you replace npx @wanthinnn/pq-cp-abe with
node /path/to/repo/bindings/wasm/cli.mjs.
Standalone targets, from an activated Unix/MSYS2 shell:
make -f Makefile.wasm -j8 # static archive + JS/WASM package
make -f Makefile.wasm deps JOBS=8 # build/check all dependencies
make -f Makefile.wasm static
make -f Makefile.wasm shared # JS/WASM package
make -f Makefile.wasm executable # same package, exposes callMain
make -f Makefile.wasm test
make -f Makefile.wasm clean
make -f Makefile.wasm clean-deps
In x64 cmd, invoke these through MSYS2 Bash, as in the build sequence above; for example:
C:\msys64\usr\bin\bash.exe -c "make -f Makefile.wasm static"
JOBS controls dependency compiler jobs (default 8); -j controls C++ objects.
Normal builds reuse the dependency cache. Run make wasm-deps after dependency
source or toolchain changes. Build directories are selected by host:
| Host | Directory name under build/deps/ and build/artifacts/ |
|---|---|
| Linux and WSL | wasm |
| Windows MSYS2 | wasm-windows |
| macOS Intel | wasm-macos-x86_64 |
| macOS Apple Silicon | wasm-macos-arm64 |
Each build copies its deployment package to lib/wasm:
| File | Purpose |
|---|---|
loader.mjs |
Async factory initializing both runtimes |
hybrid-pq-cp-abe.mjs |
Emscripten module factory |
hybrid-pq-cp-abe.wasm |
C++/Rust/Crypto++/liboqs module |
circl_ffi.wasm |
Canonical CIRCL Go runtime for TKN20 and Ed448 |
tkn20.wasm |
v6.1 compatibility alias of circl_ffi.wasm |
wasm_exec.js |
Runtime support matching the Go compiler |
libhybrid-pq-cp-abe.a |
Merged archive for Emscripten C/C++ consumers |
Deploy the JavaScript modules and WASM files together, keeping the lib/wasm
subdirectories from the build. The static archive serves C/C++ linking.
Import loader.mjs from Node.js or a browser served over HTTP(S). npm package guide
import { PqCpAbe, Scheme } from './lib/wasm/loader.mjs';
const { api } = await PqCpAbe.create();
console.log(api.getVersion());
api.native.FS.mkdir('/keys');
api.setupFiles({ outputPath: '/keys/demo', scheme: Scheme.TKN20 });
File APIs use Emscripten's in-memory filesystem. Transfer data with
api.native.FS.writeFile and api.native.FS.readFile. For CoverCrypt in memory,
pass config to CoverCryptABE.create or call api.covercryptSetup with JSON.
For CoverCrypt file setup, write the JSON to the WASM filesystem and set
module.ENV.HCPABE_COVERCRYPT_CONFIG in a preRun callback.
TKN20 uses Go js/wasm instead of a native CGO archive. Its callback copies data
between Go and Emscripten memory. All schemes remain enabled. The static archive
also requires this runtime callback (Module.tkn20) in a consuming Emscripten
application; it is not a standalone WASI module. Loader instances share one Go
runtime. Rust panics abort the module; regular FFI error returns remain available.
References: Go WebAssembly, Rust Emscripten ABI.