Skip to content

Implement bytecode-only runtime build mode#10

Draft
yumin-chen wants to merge 1 commit intomainfrom
bytecode-only-runtime-final-7784769475260091224
Draft

Implement bytecode-only runtime build mode#10
yumin-chen wants to merge 1 commit intomainfrom
bytecode-only-runtime-final-7784769475260091224

Conversation

@yumin-chen
Copy link
Copy Markdown
Owner

Implement a bytecode-only runtime build mode that allows dead-stripping the parser and compiler from the generated binary when parser-dependent features are disabled. This involves guarding core entry points in quickjs.c and quickjs-libc.c, implementing automatic library selection in qjsc, and adding the necessary build system support and tests.


PR created automatically by Jules for task 7784769475260091224 started by @yumin-chen

This feature introduces a "bytecode-only" build mode for QuickJS. When `qjsc`
is invoked with `-fno-eval -fno-regexp -fno-json -fno-module-loader`, it
automatically links against a minified runtime library (`libquickjs-bytecode.a`)
where the JS parser and compiler are dead-stripped by LTO.

Key changes:
- `quickjs.c`: Guarded parser/compiler entry points and their assignments
  with `#ifndef CONFIG_BYTECODE_ONLY_RUNTIME`.
- `quickjs-libc.c`: Guarded source-loading functions (`loadScript`,
  `evalScript`, `parseExtJSON`), `os.Worker`, and their module registrations
  to prevent indirect parser invocation.
- `qjsc.c`: Added logic to detect the "Bytecode-Only Trigger" and select
  the appropriate library suffix. Added a compile-time guard to ensure `qjsc`
  always includes the full engine.
- `Makefile`: Added targets for `libquickjs-bytecode.a` and its LTO variant,
  using a dedicated `.obj-rt` directory for minified objects.
- Added `tests/test_bytecode_runtime.js` and a `test-bytecode-runtime`
  Makefile target for CI validation.

Requirements covered: 1-7.
Acceptance criteria met: all.
@google-labs-jules
Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@yumin-chen
Copy link
Copy Markdown
Owner Author

Add comprehensive tests that:

  1. ensure BigInt, closures with mutation, generators, async/await, Map/Set iteration still work
  2. test std.evalScript, std.loadScript, std.parseExtJSON are absent from the std module at runtime
  3. test os.Worker is absent from the os module at runtime
  4. test Function.prototype.toString() on a bytecode function
  5. test of import.meta.url on a pre-compiled module
  6. test that the bytecode-only binary rejects a partial/corrupted bytecode buffer gracefully

@yumin-chen
Copy link
Copy Markdown
Owner Author

And the following must not be guarded (as they are required for bytecode execution):

JS_ReadObject
JS_EvalFunction
JS_EvalFunctionInternal
free_function_bytecode
js_closure

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