mirror of
https://github.com/gorules/zen.git
synced 2026-11-28 08:06:20 +00:00
* feat(engine): explicit evaluation context with now, timezone and seed
The compiled engine evaluates against an explicit EvaluationContext
instead of the host clock, host zone and an unseeded random source.
- zen_expression::context: EvaluationContext holds now (read once on
first use, shared by every row of a batch), the time zone (supplied
or the host zone cached per process), the locale, the seed (drawn on
the first draw) and per-row and per-item random streams created only
when a row or item draws. rows/picked/items/item/at narrow it with an
Rc clone; at and item allocate nothing. RowContext is the borrowed
per-row view builtins, kernels and function hosts read.
- the context is passed explicitly through the lane VM (LaneRunner,
Session, kernels, cells, builtins), typed Program::run, graph state,
rows, loops, sub-decisions, hosted rows, the columnar plan, policies
and their plans. There are no thread-locals for context data.
- rand draws once per lane, row and item from the row's stream, so
map(xs, rand(100)) draws per item. rand is never pure, folded,
memoised or compiled into kernels as a constant; Math.random is no
longer pure in the function purity analysis.
- function hosts (v1 and v2) install Date, Math.random and a minimal
Intl.DateTimeFormat once per runtime and read a per-call slot:
Date.now, new Date, local-time getters and setters, toString,
toLocale*String and getTimezoneOffset use the context's now, zone and
locale.
- EvaluationOptions and EvaluationSerializedOptions gain now, timezone,
seed and locale (en-US by default). Workspace gains evaluate_pinned,
evaluate_batch_pinned and evaluate_columns_pinned. In a batch, row i
draws with row_seed(seed, i) and replays alone with that seed.
- bindings: Node and Python accept and validate now, timezone, seed and
locale; C and uniffi pass them through and ignore invalid values.
- d('...') is folded at compile time only for texts with an explicit
zone; an invalid __ZEN_MOCK_UTC_TIME is ignored by the context.
- the interpreted engine and the stack VM are unchanged and ignore the
new options.
* refactor(engine): name evaluation context parameters ctx and context
* feat(engine): derive random draws from their location
A draw is now a pure function of (seed, stream, scope, field, site, n)
instead of a running counter per stream, so reordering, short-circuiting,
dead-code elimination or an extra rand elsewhere in a decision no longer
shifts other draws.
- site: occurrence index of rand( in source order, numbered at compile
time and carried on the lane call op
- field: stable label from node/rule/column/key/statement/block ids,
baked into multi-root programs at compile time or set on the context
by per-source (session) paths
- scope: chained per sub-decision call (caller node + key) and per
function node; JS Math.random uses a fixed site in that scope
- n: counter per (stream, address) for repeated evaluation only
Tables with draws run on the exact row path; fused cells and fused rules
refuse draws; object-literal expansion is skipped for drawing sources.
* refactor(expression): own the rand integer mapping
Map a draw to 0..=upper with Lemire multiply-shift and rejection, taking
further words from the same address on retry, so a dependency update can
never change rand(n) for a given seed. A negative upper bound now returns
"Invalid upper range" on both VMs instead of panicking, and the unseeded
root seed comes from a hashed counter, which drops fastrand.
* test(engine): keep evaluation context tests independent under cargo test
cargo test runs a crate's tests as threads of one process, so tests that
share process state raced:
- pinned.rs switched the global ZEN_CONFIG.compiled on and off; each
decision now picks its engine with compiled_engine() / interpreted().
- clock_reads() counted reads from every thread; it now counts the
current thread only.
- typed exact tests relied on __ZEN_MOCK_UTC_TIME, which is cached on the
first clock read by any test; they now pin now in the context.
* ci: pin Rust 1.99 for the Windows Node and UniFFI builds
Rust 1.100 makes Cargo's new build-dir layout permanent: every
dependency gets its own directory and its own -L dependency= flag.
For zen-engine with --target x86_64-pc-windows-msvc the rustc command
line passes Windows' 32,767-character limit, and sccache fails to spawn
rustc with os error 206. Cargo itself falls back to an argument file,
but sccache does not.
Other matrix entries stay on stable. Remove the pin once sccache
handles long command lines.
* refactor(engine): remove locale from the evaluation context
The locale option did not make evaluations more reproducible: QuickJS has
no ICU, so function nodes never picked up a host locale. It only added
approximate locale-aware date formatting from a hand-written table, as new
public API in every binding.
Function nodes keep the time zone of the context. toLocaleString,
toLocaleDateString and toLocaleTimeString return QuickJS's fixed format in
that zone and ignore a locale argument, as before. Intl is reduced to
DateTimeFormat().resolvedOptions(), which reports the time zone.
Drops the icu_locale_core dependency.
* test(engine): compare interpreted draws with the pinned ones
The interpreted engine's Math.random is QuickJS's own, seeded from the
clock in microseconds when a context is created. On Windows the clock is
coarser, so two evaluations in a row can get the same seed and the same
numbers. Assert instead that the interpreted engine does not return the
compiled engine's draws for the same seed.
378 lines
12 KiB
YAML
378 lines
12 KiB
YAML
name: NodeJS
|
|
|
|
env:
|
|
WORKING_DIRECTORY: bindings/nodejs
|
|
DEBUG: 'napi:*'
|
|
MACOSX_DEPLOYMENT_TARGET: '10.13'
|
|
NODE_OPTIONS: '--max-old-space-size=3072'
|
|
CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST: true
|
|
CARGO_TARGET_APPLIES_TO_HOST: false
|
|
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'bindings/nodejs/**'
|
|
- 'core/**'
|
|
- 'test-data/**'
|
|
- '.github/workflows/node.yaml'
|
|
push:
|
|
tags:
|
|
- 'nodejs-v*'
|
|
|
|
permissions:
|
|
contents: write
|
|
id-token: write
|
|
|
|
jobs:
|
|
build:
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
settings:
|
|
- host: windows-latest
|
|
target: 'x86_64-pc-windows-msvc'
|
|
toolchain: '1.99'
|
|
build: |
|
|
yarn build -- --target x86_64-pc-windows-msvc -- --locked
|
|
|
|
- host: macos-15-intel
|
|
target: 'x86_64-apple-darwin'
|
|
build: |
|
|
rustup target add x86_64-apple-darwin
|
|
yarn build -- --target x86_64-apple-darwin -- --locked
|
|
strip -x ./*.node
|
|
|
|
- host: macos-latest
|
|
target: 'aarch64-apple-darwin'
|
|
build: |
|
|
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
|
|
export CC=$(xcrun -f clang);
|
|
export CXX=$(xcrun -f clang++);
|
|
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
|
|
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
|
|
yarn build -- --target aarch64-apple-darwin -- --locked
|
|
strip -x ./*.node
|
|
|
|
- host: ubuntu-latest
|
|
target: 'x86_64-unknown-linux-gnu'
|
|
zig: true
|
|
build: |
|
|
set -e
|
|
rustup target add x86_64-unknown-linux-gnu
|
|
cargo zigbuild --release --locked -p zen-nodejs --target x86_64-unknown-linux-gnu.$GLIBC_VERSION
|
|
cp ../../target/x86_64-unknown-linux-gnu/release/libzen_nodejs.so zen-engine.linux-x64-gnu.node
|
|
strip zen-engine.linux-x64-gnu.node
|
|
|
|
- host: ubuntu-latest
|
|
target: 'aarch64-unknown-linux-gnu'
|
|
zig: true
|
|
build: |
|
|
set -e
|
|
rustup target add aarch64-unknown-linux-gnu
|
|
cargo zigbuild --release --locked -p zen-nodejs --target aarch64-unknown-linux-gnu.$GLIBC_VERSION
|
|
cp ../../target/aarch64-unknown-linux-gnu/release/libzen_nodejs.so zen-engine.linux-arm64-gnu.node
|
|
|
|
- host: ubuntu-latest
|
|
target: 'x86_64-unknown-linux-musl'
|
|
zig: true
|
|
build: |
|
|
set -e
|
|
rustup target add x86_64-unknown-linux-musl
|
|
yarn build -- --target x86_64-unknown-linux-musl --cross-compile -- --locked
|
|
strip ./*.node
|
|
|
|
- host: ubuntu-latest
|
|
target: 'aarch64-unknown-linux-musl'
|
|
zig: true
|
|
build: |
|
|
set -e
|
|
rustup target add aarch64-unknown-linux-musl
|
|
yarn build -- --target aarch64-unknown-linux-musl --cross-compile -- --locked
|
|
|
|
- host: ubuntu-latest
|
|
target: 'wasm32-wasip1'
|
|
setup: |
|
|
wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-27/wasi-sdk-27.0-x86_64-linux.tar.gz
|
|
tar -xvf wasi-sdk-27.0-x86_64-linux.tar.gz
|
|
build: |
|
|
set -e
|
|
WASI_SDK="$(pwd)/wasi-sdk-27.0-x86_64-linux"
|
|
export CMAKE_BUILD_PARALLEL_LEVEL=2
|
|
export CC_wasm32_wasip1="$WASI_SDK/bin/clang"
|
|
export AR_wasm32_wasip1="$WASI_SDK/bin/llvm-ar"
|
|
export CFLAGS_wasm32_wasip1="--target=wasm32-wasip1 --sysroot=$WASI_SDK/share/wasi-sysroot -mllvm -wasm-enable-sjlj"
|
|
export CARGO_TARGET_WASM32_WASIP1_RUSTFLAGS="-C link-arg=$WASI_SDK/share/wasi-sysroot/lib/wasm32-wasip1/libsetjmp.a"
|
|
cargo clean -p napi-async-runtime --target wasm32-wasip1 --release
|
|
yarn build -- --target wasm32-wasip1 -- --locked
|
|
|
|
name: stable - ${{ matrix.settings.target }} - node@22
|
|
runs-on: ${{ matrix.settings.host }}
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ env.WORKING_DIRECTORY }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup node
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 22
|
|
check-latest: true
|
|
cache: yarn
|
|
cache-dependency-path: 'bindings/nodejs/yarn.lock'
|
|
|
|
- name: Install
|
|
uses: dtolnay/rust-toolchain@stable
|
|
with:
|
|
toolchain: ${{ matrix.settings.toolchain || 'stable' }}
|
|
targets: ${{ matrix.settings.target }}
|
|
|
|
- name: Rust cache + sccache (+ zig for linux legs)
|
|
uses: ./.github/actions/setup-rust
|
|
with:
|
|
shared-key: nodejs-${{ matrix.settings.target }}
|
|
key: ${{ matrix.settings.target }}
|
|
zig: ${{ matrix.settings.zig }}
|
|
sccache-bucket: ${{ secrets.SCCACHE_S3_BUCKET }}
|
|
sccache-region: ${{ secrets.SCCACHE_AWS_REGION }}
|
|
sccache-role-arn: ${{ secrets.SCCACHE_AWS_ROLE_ARN }}
|
|
|
|
- name: Setup toolchain
|
|
run: ${{ matrix.settings.setup }}
|
|
if: ${{ matrix.settings.setup }}
|
|
shell: bash
|
|
|
|
- name: 'Install dependencies'
|
|
run: yarn install --immutable --mode=skip-build
|
|
|
|
- name: 'Build'
|
|
run: ${{ matrix.settings.build }}
|
|
shell: bash
|
|
|
|
- name: 'Check'
|
|
run: ls -la
|
|
shell: bash
|
|
|
|
- name: Upload typings
|
|
if: ${{ matrix.settings.target == 'aarch64-apple-darwin' }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: typings
|
|
path: bindings/nodejs/index.d.ts
|
|
if-no-files-found: error
|
|
|
|
- name: Upload artifact ${{ matrix.settings.target }}
|
|
if: ${{ matrix.settings.target != 'wasm32-wasip1' }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: bindings-${{ matrix.settings.target }}
|
|
path: bindings/nodejs/*.node
|
|
if-no-files-found: error
|
|
|
|
- name: Upload artifact ${{ matrix.settings.target }}
|
|
if: ${{ matrix.settings.target == 'wasm32-wasip1' }}
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: bindings-wasm32-wasip1
|
|
if-no-files-found: error
|
|
path: |
|
|
bindings/nodejs/zen-engine.wasm32-wasip1*
|
|
bindings/nodejs/zen-engine.wasip1*
|
|
|
|
test:
|
|
name: Test ${{ matrix.settings.target }} - node@${{ matrix.node }}
|
|
needs:
|
|
- build
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ env.WORKING_DIRECTORY }}
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
node: [ '20', '22' ]
|
|
settings:
|
|
# Native runners
|
|
- host: macos-15-intel
|
|
target: 'x86_64-apple-darwin'
|
|
- host: macos-latest
|
|
target: 'aarch64-apple-darwin'
|
|
- host: windows-latest
|
|
target: 'x86_64-pc-windows-msvc'
|
|
# Linux: run inside the matching libc container; arm adds QEMU
|
|
- host: ubuntu-latest
|
|
target: 'x86_64-unknown-linux-gnu'
|
|
image: 'node:{0}-slim'
|
|
- host: ubuntu-latest
|
|
target: 'x86_64-unknown-linux-musl'
|
|
image: 'node:{0}-alpine'
|
|
- host: ubuntu-latest
|
|
target: 'aarch64-unknown-linux-musl'
|
|
image: 'node:{0}-alpine'
|
|
arm: true
|
|
runs-on: ${{ matrix.settings.host }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
with:
|
|
submodules: true
|
|
|
|
- name: Setup node
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: ${{ matrix.node }}
|
|
check-latest: true
|
|
cache: yarn
|
|
cache-dependency-path: 'bindings/nodejs/yarn.lock'
|
|
|
|
- name: Set up QEMU
|
|
if: ${{ matrix.settings.arm }}
|
|
uses: docker/setup-qemu-action@v3
|
|
with:
|
|
platforms: arm64
|
|
- if: ${{ matrix.settings.arm }}
|
|
run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
|
|
|
|
- name: Install dependencies (arm64/musl)
|
|
if: ${{ matrix.settings.arm }}
|
|
run: |
|
|
yarn config set supportedArchitectures.cpu "arm64"
|
|
yarn config set supportedArchitectures.libc "musl"
|
|
yarn install --immutable --mode=skip-build
|
|
- name: Install dependencies
|
|
if: ${{ !matrix.settings.arm }}
|
|
run: yarn install --immutable --mode=skip-build
|
|
|
|
- name: Download artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: bindings-${{ matrix.settings.target }}
|
|
path: bindings/nodejs
|
|
|
|
- name: Download typings
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: typings
|
|
path: bindings/nodejs
|
|
|
|
- name: Test bindings (native)
|
|
if: ${{ !matrix.settings.image }}
|
|
run: |
|
|
yarn install
|
|
yarn link
|
|
yarn test
|
|
|
|
- name: Test bindings (docker)
|
|
if: ${{ matrix.settings.image }}
|
|
uses: stefan-gorules/docker-run-action@v1
|
|
with:
|
|
image: ${{ format(matrix.settings.image, matrix.node) }}
|
|
options: ${{ matrix.settings.arm && format('--platform linux/arm64 -v {0}:/workspace', github.workspace) || format('-v {0}:/workspace', github.workspace) }}
|
|
run: |
|
|
cd workspace/bindings/nodejs
|
|
yarn install
|
|
yarn link
|
|
yarn test
|
|
|
|
test-wasm:
|
|
name: Test wasm32-wasip1 - node@22
|
|
needs:
|
|
- build
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ env.WORKING_DIRECTORY }}
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup node
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 22
|
|
check-latest: true
|
|
cache: yarn
|
|
cache-dependency-path: 'bindings/nodejs/yarn.lock'
|
|
|
|
- name: Install dependencies
|
|
run: yarn install --immutable --mode=skip-build
|
|
|
|
- name: Download artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: bindings-wasm32-wasip1
|
|
path: bindings/nodejs
|
|
|
|
- name: Download typings
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: typings
|
|
path: bindings/nodejs
|
|
|
|
- name: Test bindings (wasm)
|
|
run: yarn test:wasm
|
|
|
|
release:
|
|
name: Release
|
|
runs-on: ubuntu-latest
|
|
environment: release
|
|
# Publishes only on the release-please GitHub Release for the nodejs component.
|
|
if: "github.ref_type == 'tag'"
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ env.WORKING_DIRECTORY }}
|
|
needs:
|
|
- test
|
|
- test-wasm
|
|
steps:
|
|
- uses: actions/checkout@v3
|
|
|
|
- name: Setup node
|
|
uses: actions/setup-node@v3
|
|
with:
|
|
node-version: 22
|
|
check-latest: true
|
|
cache: yarn
|
|
cache-dependency-path: 'bindings/nodejs/yarn.lock'
|
|
registry-url: 'https://registry.npmjs.org'
|
|
# Organisation
|
|
scope: '@gorules'
|
|
|
|
- name: 'Install dependencies'
|
|
run: yarn install --immutable --mode=skip-build
|
|
|
|
- name: Download all artifacts
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
pattern: bindings-*
|
|
path: artifacts
|
|
|
|
- name: Download typings
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: typings
|
|
path: bindings/nodejs
|
|
|
|
- name: List all artifacts
|
|
run: ls -la ../../artifacts
|
|
|
|
- name: Copy LICENSE
|
|
run: cp ../../LICENSE .
|
|
|
|
- name: Create dirs
|
|
run: yarn createNpmDirs
|
|
shell: bash
|
|
|
|
- name: Move artifacts
|
|
run: yarn artifacts
|
|
|
|
- name: List folder
|
|
run: ls ./
|
|
shell: bash
|
|
|
|
- name: Lerna publish
|
|
run: yarn lerna publish from-package --dist-tag ${{ contains(github.ref, '-beta') && 'beta' || 'latest' }} --no-verify-access --yes
|
|
env:
|
|
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|