Skip to content

Allow extending hyperlight-js-runtime with custom native modules #48

Description

@simongdavies

Summary

I'd like to add custom native Rust modules to the JS runtime without forking hyperlight-js-runtime. Currently the native module registry is internal and not extensible.

Use Case

Some operations are too slow in pure JavaScript. For example, DEFLATE compression is ~50-100x slower than native Rust, which can cause CPU timeouts on large inputs. I want to add native modules that run inside the same Hyperlight guest VM without maintaining a full fork of the runtime.

Desired Outcome

  1. Build a custom runtime binary that includes all default native modules (io, crypto, console, require) plus my own
  2. Use the same mechanism that upstream uses to declare native modules
  3. Automatically inherit new native modules when upstream adds them

Proposed Approach

  1. Expose hyperlight-js-runtime as a library — add [lib] to Cargo.toml so custom runtimes can link against it

  2. Provide a native_modules! macro that generates a NativeModuleLoader. The macro always chains to the upstream loader first, then checks additional modules:

    // Upstream uses:
    native_modules! {
        "io" => io::js_io,
        "crypto" => crypto::js_crypto,
        "console" => console::js_console,
        "require" => require::js_require,
    }
    
    // Extender uses (upstream modules are inherited automatically):
    native_modules! {
        "compression" => my_compression_module,
    }

    The macro-generated loader delegates to hyperlight_js_runtime::NativeModuleLoader for any module it doesn't recognize, so extenders automatically get all upstream modules without listing them.

  3. Build-time binary override — add an env var check in hyperlight-js/build.rs so custom runtime binaries can be embedded instead of the default:

    HYPERLIGHT_JS_RUNTIME_PATH=/path/to/custom-runtime cargo build

Benefits

  • Same macro used by upstream and extenders
  • Extenders automatically inherit upstream modules via delegation
  • Compile-time only — no runtime registration or mutation

Activity

  1. added 11 commits that reference this issue on Mar 12, 2026
    886149d
    373aade
    41d9932
    2d152be
    e46b03e
    1c4360c
    0fce14f
    80dd30b
    acaa72b
    d721317
    3e43831
  2. added a commit that references this issue on Mar 26, 2026
    53858a0
  3. added 2 commits that reference this issue on Jun 4, 2026
    0049b1a
    ce5bc5f
  4. added 2 commits that reference this issue on Jun 30, 2026
    2ce5694
    a7fb67d
  5. added a commit that references this issue on Jul 2, 2026
    9261899
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions