@mauricelam/selinux-wasm
v0.0.310
Published
SELinux libsepol compiled to WebAssembly
Readme
WebAssembly Build for libsepol
This document describes how to build libsepol for WebAssembly using Emscripten.
Prerequisites
- Emscripten SDK: Ensure you have Emscripten installed and available in your PATH.
- Follow the instructions at emscripten.org.
- Build Dependencies: You need
make,flex, andbisoninstalled on your system.- On Debian/Ubuntu:
sudo apt-get install make flex bison
- On Debian/Ubuntu:
Compilation Steps
To build libsepol for WebAssembly, use the provided Makefile.wasm:
cd libsepol
# Build for Node.js and static library
make -f Makefile.wasm
# Build specifically for the browser example
make -f Makefile.wasm browserBuild Artifacts
libsepol/src/libsepol.a: The static library for linking into other WASM projects.libsepol/src/libsepol_browser.js/.wasm: Unified module for browser use.libsepol/utils/*.jsandlibsepol/utils/*.wasm: The utility programs as JavaScript/WebAssembly modules (configured for Node.js).
Usage
Browser Example
A runnable browser example is provided in libsepol/wasm_example/.
- Build the browser target:
make -f Makefile.wasm browser - Serve the root directory with a web server. For example:
python3 -m http.server 8000 - Navigate to
http://localhost:8000/libsepol/wasm_example/in your browser.
The example demonstrates how to initialize the library and call sepol_check_context using Emscripten's cwrap.
Using Utilities with Node.js
You can run the built utilities using Node.js. Note that due to how WASM files are loaded, you might need to be in the same directory or use a tool that handles the resolution.
cd libsepol/utils
node chkcon.jsLinking into a WASM Project
To use libsepol in your own C/C++ project compiled with Emscripten, include the headers and link against the static library:
emcc my_app.c -Ipath/to/libsepol/include path/to/libsepol/src/libsepol.a -o my_app.jsCustomizing the Build
You can customize the Emscripten flags by editing libsepol/Makefile.wasm or by passing them on the command line:
make -f Makefile.wasm WASM_CFLAGS="-O3" WASM_LDFLAGS="-s EXPORTED_FUNCTIONS=['_sepol_policydb_read']"Compatibility Notes
reallocarray: Provided vialibsepol/src/wasm_compat.cto avoid conflicts between Emscripten'sstdlib.hdeclaration and the lack of implementation in some environments.SINGLE_FILE=1: Can be added toWASM_LDFLAGSif you wish to embed the WASM binary directly into the JS file.
