Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
# docker build --output type=local,dest=./wasm --target wasm .
#
# Versions:
# emsdk 5.0.6 | MobilityDB ee27da1 | GEOS 3.14.1
# emsdk 5.0.6 | MobilityDB 2c4243a | GEOS 3.14.1
# PROJ 9.8.1 | SQLite 3.46.1 | JSON-C 0.18 | GSL 2.8

# Pinned MobilityDB commit — update together with meos-idl.json when upgrading.
ARG MOBILITYDB_COMMIT=ee27da1a6d2f6cdbdd226bd66a1e7fea86c2832b
ARG MOBILITYDB_COMMIT=2c4243a2656fcef27fa0a2557234593e3e9b125b

# EMSCRIPTEN & EVERY NEEDED TOOL
FROM emscripten/emsdk:5.0.6 AS base
Expand Down Expand Up @@ -143,6 +143,10 @@ RUN npm run generate
RUN INCLUDES="-I/root/geos/include -I/root/geos/build/capi -I/root/json-c-install/include -I/root/json-c-install/include/json-c" \
&& emcmake cmake -S /root/MobilityDB -B /root/MobilityDB/build \
-DMEOS=ON \
-DCBUFFER=ON \
-DNPOINT=ON \
-DPOSE=ON \
-DRGEO=ON \
-DBUILD_SHARED_LIBS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DGEOS_INCLUDE_DIR=/root/geos/build/capi \
Expand Down Expand Up @@ -212,6 +216,8 @@ RUN mkdir -p /app/wasm \
-I/root/MobilityDB/postgis \
-I/root/MobilityDB/postgis/liblwgeom \
-I/root/PROJ/src \
-I/root/json-c-install/include \
-I/root/gsl-wasm/include \
--embed-file /usr/share/zoneinfo@/usr/share/zoneinfo \
--embed-file /root/MobilityDB/meos/src/geo/spatial_ref_sys.csv@/usr/local/share/spatial_ref_sys.csv \
--embed-file /root/PROJ/build/data/proj.db@/usr/local/share/proj/proj.db \
Expand Down
37 changes: 36 additions & 1 deletion codegen/FunctionsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ const isRawBytes = (t: string) => {
*/
const isInterval = (t: string) => clean(t) === 'Interval';

/**
* True for the PostgreSQL Datum tagged value in any pointer arity
* (Datum, Datum *, const Datum, ...). A Datum is an opaque uintptr_t whose
* interpretation depends on the runtime base type: for Float8 / text / geometry
* it holds a *pointer*, not the value (and is only 32-bit under WASM32), so it
* can never be marshalled safely to a JS scalar. Datum only ever appears on
* INTERNAL functions (meos_internal.h); the user-facing API is the typed
* *_meos.c wrappers declared in the public headers, e.g.
* temporal_start_value(Datum, internal) -> tint_start_value / tfloat_start_value / ttext_start_value
* Functions whose signature mentions Datum are therefore skipped entirely.
*/
const isDatum = (t: string) => /\bDatum\b/.test(clean(t));

/**
* True for the PostgreSQL text type passed as a single pointer (text *).
* These require cstring2text / text2cstring conversion in the C wrapper
Expand Down Expand Up @@ -352,6 +365,10 @@ function detectBoolResult(fn: IdlFunction): BoolResultInfo | null {
*
* The only cases that remain un-generatable are:
*
* - Datum return or param: Datum is an opaque, internal-only tagged value
* (see isDatum) that cannot be marshalled to a JS scalar. It appears only
* on internal functions; the user-facing API is the typed *_meos.c wrapper.
*
* - Function-pointer params: Emscripten cannot marshal C function pointers
* automatically. These require hand-written wrappers using
* Module.addFunction() and are listed in MANUAL_FUNCTIONS if needed.
Expand All @@ -361,7 +378,11 @@ function detectBoolResult(fn: IdlFunction): BoolResultInfo | null {
* handled normally as Ptr.
*/
function shouldSkip(fn: IdlFunction): string | null {
if (isDatum(fn.returnType.c))
return 'internal Datum return — use the typed *_meos.c wrapper';
for (const p of fn.params) {
if (isDatum(p.cType))
return `internal Datum param '${p.name}' — use the typed *_meos.c wrapper`;
if (isFuncPtr(p.cType)) return `function-pointer param '${p.name}'`;
if (isInterval(p.cType)) return `Interval by-value param '${p.name}'`;
}
Expand Down Expand Up @@ -819,7 +840,21 @@ function main(): void {

console.log('Reading IDL:', idlPath);
const idl: Idl = JSON.parse(fs.readFileSync(idlPath, 'utf-8'));
const fns: IdlFunction[] = idl.functions ?? [];

// The binding mirrors the PUBLIC MEOS API only. Exclude functions declared in
// non-API headers: the internal headers (meos_internal.h / meos_internal_geo.h
// — not user-facing, nothing in core/types calls them, many take/return the
// opaque Datum, see isDatum / shouldSkip) and the bundled liblwgeom external
// definitions (postgis_ext_defs.in.h — PostGIS glue, not MEOS API). The public
// meos*.h headers, and the typed *_meos.c wrappers they declare, are the API.
const NON_API_HEADERS = new Set([
'meos_internal.h',
'meos_internal_geo.h',
'postgis_ext_defs.in.h',
]);
const fns: IdlFunction[] = (idl.functions ?? []).filter(
f => !NON_API_HEADERS.has(f.file)
);

let cOut = fs.readFileSync(
path.resolve(__dirname, 'res/bindings_c_header.c.template'),
Expand Down
4 changes: 4 additions & 0 deletions codegen/res/bindings_c_header.c.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include <utils/timestamp.h>
#include <meos.h>
#include <meos_geo.h>
#include <meos_cbuffer.h>
#include <meos_npoint.h>
#include <meos_pose.h>
#include <meos_rgeo.h>
#include <emscripten.h>

/*
Expand Down
Loading