Skip to content

Instantly share code, notes, and snippets.

//
// Build with
//
// -pthread -s PROXY_TO_PTHREAD -s EXIT_RUNTIME
//
#include <stdlib.h>
#include <emscripten.h>
#include <emscripten/threading.h>
# 1 "tests/core/test_atomic_cxx.cpp"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 355 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "tests/core/test_atomic_cxx.cpp" 2
# 13 "tests/core/test_atomic_cxx.cpp"
# 1 "/home/azakai/Dev/emscripten/cache/sysroot/include/c++/v1/atomic" 1 3
# 577 "/home/azakai/Dev/emscripten/cache/sysroot/include/c++/v1/atomic" 3
@kripken
kripken / .gitignore
Last active July 9, 2021 19:58
Interface Types IOI
*.wasm
temp
@kripken
kripken / README.markdown
Last active May 23, 2021 17:36
Building binaryen with zig cc

Building binaryen with zig cc

  1. Add zigcc, zigc++ scripts because cmake doens't accept a compiler with spaces in the name like "zig cc".
  2. The zigcc/zigc++ scripts can also add a target for cross-compiling as shown here.
  3. Disable threads (perhaps cmake cross-compiling needs to be set up?).
  4. Use a static build (otherwise cmake emits a .so - again, do we need cmake cross-compiling here?).
  5. ninja stalls on the final links: it just hangs. To solve that, run ninja wasm-opt and so forth manually, as a specific build target works.
extern "C" int foo();
int main() {
foo();
}
(func $ThreadMain\28void*\29 (param $0 i32) (result i32)
(local $1 i32)
(local $2 i32)
(loop $label$1
(local.set $0
(call $__cxa_allocate_exception
(i32.const 4)
)
)
(block $label$2
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index 221629557..8381b0bb6 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -49,21 +49,21 @@ int main(int argc, const char* argv[]) {
std::string dataSegmentFile;
bool emitBinary = true;
bool debugInfo = false;
bool DWARF = false;
bool sideModule = false;
(module
(type $i32_=>_i32 (func (param i32) (result i32)))
(type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
(type $i32_=>_none (func (param i32)))
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(type $none_=>_i32 (func (result i32)))
(type $i32_i32_i32_i32_=>_i32 (func (param i32 i32 i32 i32) (result i32)))
(type $i32_f64_i32_i32_i32_i32_=>_i32 (func (param i32 f64 i32 i32 i32 i32) (result i32)))
(type $i32_i32_=>_none (func (param i32 i32)))

Simple WasmBoxC Library Example

This shows how to easily sandbox a real-world library using WasmBoxC. Specifically we sandbox the zlib compression library.

To follow along with this, you can clone this gist and then do the following commands.

First, get the emsdk:

Sizes

(html+js+wasm)

Non-emscripten: 19,964 bytes
Emscripten:     11,086 bytes