Skip to content

Compile C Hooks locally with hooks-compiler and drop JS Hooks support - #61

Merged
tequdev merged 3 commits into
Xahau:mainfrom
tequdev:feat/hooks-compiler
Oct 19, 2026
Merged

tequdev merged 3 commits into
Xahau:mainfrom
tequdev:feat/hooks-compiler

Conversation

@tequdev

@tequdev tequdev commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Remove JS Hooks support: compile-js, js2qjsc-cli, init js, the js2qjsc and 2bytes modules, and the esbuild/pako/base64-js dependencies. The init command keeps its type argument (only c is valid) so another hook type can be added later.
  • Compile C Hooks in-process with hooks-compiler@0.2.0 instead of the remote compile server. HOOKS_COMPILE_HOST and the --xrpl flag are gone; no network access is needed to build.
  • Vendor hook/*.h from the xahaud release branch into the init c template at contracts/include (8 files, including ls_flags.h and tx_flags.h). They also serve as the default when --headers is omitted. Headers are keyed by basename as before, so #include "foo.h" finds headers/sub/foo.h.
  • scripts/update-headers.mjs re-syncs those headers (yarn headers:update); yarn headers:check exits 1 on drift and runs in CI as the headers-up-to-date job.
  • init now rejects an invalid type before creating the project directory.
  • Move tests from jest to node:test run via tsx --test: hooks-compiler is ESM-only and ts-jest rewrites import() to require(), so jest cannot load it. tsconfig uses module/moduleResolution node16 so tsc keeps the dynamic import.
  • Require Node >= 20.12 (hooks-compiler's requirement).
  • debug and HOOKS_DEBUG_HOST are unchanged.

Behaviour changes

  • Optimization: the server compiled with -O3; hooks-compiler uses -O2 followed by wasm-opt -Oz. Output for contracts-c/base.c is 197 bytes (server: 231 bytes) with identical imports and exports.
  • Gas-type hooks (HookApiVersion 1, no _g import) are still rejected by hook-cleaner, the same as with the compile server.

Release note

src/init/c/package.json still pins @xahau/hooks-cli: ^2.1.0 and the package version is still 2.1.0. Because the published 2.x CLI requires HOOKS_COMPILE_HOST and the new template .env no longer sets it, this should ship as 3.0.0 with the template devDependency bumped to ^3.0.0 in the release commit.

Verification

  • yarn build, yarn lint, yarn test:integration (14 tests, including real npm/yarn/pnpm installs of a generated project built against this branch's CLI).
  • Built contracts-c/base.c, chooks-template index.c, and iou-reward-hook reward.c with both the previous buildbox header set and the release-branch set (byte-identical output): all pass guard_checker, export only hook, import only env.*, and have import/export sets identical to the compile server's output for the same sources.
  • Deployed base.wasm and index.wasm to a standalone xahaud via the generated project's deploy script: base: Finished. and accept (return code 14 = __LINE__) with the expected HookState entry written.
  • Invalid C produces exit 1 and <name>.log containing the clang diagnostics.

- Remove compile-js, js2qjsc-cli, init js, and the js2qjsc/2bytes modules
- Replace the remote compile server with hooks-compiler@0.2.0 (in-process);
  HOOKS_COMPILE_HOST and the --xrpl flag are gone
- Vendor the C header files into the init template; they also serve as the
  default when --headers is omitted
- Move tests from jest to node:test via tsx (jest cannot load the ESM-only
  compiler); tsconfig uses node16 module resolution
- Require Node >= 20.12
- scripts/update-headers.mjs syncs src/init/c/contracts/include with
  hook/*.h on Xahau/xahaud@release; --check reports drift and exits 1
- yarn headers:update / yarn headers:check; CI runs the check
- Bundled headers now match the release branch (adds ls_flags.h, tx_flags.h)
@tequdev
tequdev enabled auto-merge (squash) October 19, 2026 11:52
@tequdev
tequdev disabled auto-merge October 19, 2026 12:05
@tequdev
tequdev merged commit 06ba4be into Xahau:main Oct 19, 2026
9 checks passed
@tequdev tequdev mentioned this pull request Oct 20, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant