Files
pdf/wasm/hello.cpp
T

36 lines
943 B
C++
Raw Normal View History

2026-05-16 11:01:20 +05:30
// Phase 0 WASM hello-world.
//
// Scope (Rule R5: WASM never blocks shipping):
// Prove the Emscripten toolchain compiles a C++ function callable from JS.
// Nothing more. The real engine-in-WASM build happens in Phase 2 and depends
// on PDFium/Skia/FreeType/HarfBuzz cross-compiled with Emscripten plus the
// frozen interface contracts from Gate G0b — all of which are out of scope
// for Phase 0.
//
// The exported C symbols here are loaded from JS via cwrap()/ccall(); see
// hello.test.mjs.
#include <cstdint>
#include <cstring>
#if defined(__EMSCRIPTEN__)
#include <emscripten/emscripten.h>
#define WASM_EXPORT EMSCRIPTEN_KEEPALIVE
#else
#define WASM_EXPORT
#endif
extern "C" {
// Smallest possible "does it run?" probe.
WASM_EXPORT int add(int a, int b) {
return a + b;
}
// A version probe so the JS side can sanity-check the module it loaded.
WASM_EXPORT int hello_version() {
return 1;
}
} // extern "C"