Skip to content

Commit a2ae0ac

Browse files
committed
docs: add resolve-cflags script and update extending-runtime docs
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent bb1d0dd commit a2ae0ac

2 files changed

Lines changed: 64 additions & 5 deletions

File tree

docs/extending-runtime.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,24 @@ libc stubs) — no copying files or build scripts needed.
7474

7575
### 3. Build and embed in hyperlight-js
7676

77-
Build your custom runtime for the Hyperlight target and embed it:
77+
Build your custom runtime for the Hyperlight target.
78+
79+
The hyperlight target has no libc, so QuickJS needs Hyperlight target stub headers
80+
and `-D__wasi__=1` to disable pthreads. Set `HYPERLIGHT_CFLAGS` before
81+
building — the helper script resolves the include path automatically
82+
from your Cargo dependency tree:
7883

7984
```bash
80-
# Build for the hyperlight target
85+
# Resolve CFLAGS (finds hyperlight-js-runtime's include/ directory)
86+
export HYPERLIGHT_CFLAGS=$(node scripts/resolve-cflags.js \
87+
--manifest-path=my-custom-runtime/Cargo.toml)
88+
89+
# Build the custom runtime for the hyperlight target
8190
cargo hyperlight build --manifest-path my-custom-runtime/Cargo.toml
8291

83-
# Build hyperlight-js with your custom runtime embedded
84-
HYPERLIGHT_JS_RUNTIME_PATH=/path/to/my-custom-runtime \
85-
cargo build -p hyperlight-js
92+
# Build hyperlight-js with the custom runtime embedded
93+
export HYPERLIGHT_JS_RUNTIME_PATH=my-custom-runtime/target/x86_64-hyperlight-none/release/my-custom-runtime
94+
cargo build -p hyperlight-js
8695
```
8796

8897
### 4. Use from the host
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
/**
3+
* Resolves HYPERLIGHT_CFLAGS for crates that extend hyperlight-js-runtime.
4+
*
5+
* The hyperlight target (x86_64-hyperlight-none) has no libc. QuickJS
6+
* (compiled by rquickjs-sys) needs Hyperlight target stub headers for stdio.h,
7+
* time.h, and unistd.h, plus -D__wasi__=1 to disable pthreads.
8+
* These stubs live in hyperlight-js-runtime/include/.
9+
*
10+
* This script uses cargo metadata to find that include directory
11+
* regardless of whether the crate is a path, git, or registry dep.
12+
*
13+
* Usage:
14+
* export HYPERLIGHT_CFLAGS=$(node resolve-cflags.js --manifest-path=path/to/Cargo.toml)
15+
* cargo hyperlight build --manifest-path path/to/Cargo.toml
16+
*
17+
* Requires: Node.js, cargo
18+
* Output: -I/absolute/path/to/include -D__wasi__=1
19+
*/
20+
21+
const { execSync } = require("child_process");
22+
const path = require("path");
23+
24+
const args = process.argv.slice(2);
25+
const manifestArg = args.find((a) => a.startsWith("--manifest-path="));
26+
const manifestPath = manifestArg ? manifestArg.split("=")[1] : "Cargo.toml";
27+
28+
try {
29+
const meta = JSON.parse(
30+
execSync(
31+
`cargo metadata --format-version 1 --manifest-path ${manifestPath}`,
32+
{ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }
33+
)
34+
);
35+
36+
const pkg = meta.packages.find((p) => p.name === "hyperlight-js-runtime");
37+
if (!pkg) {
38+
process.stderr.write(
39+
"Error: hyperlight-js-runtime not found in the dependency tree.\n" +
40+
"Make sure your Cargo.toml depends on hyperlight-js-runtime.\n"
41+
);
42+
process.exit(1);
43+
}
44+
45+
const includeDir = path.join(path.dirname(pkg.manifest_path), "include");
46+
console.log(`-I${includeDir} -D__wasi__=1`);
47+
} catch (err) {
48+
process.stderr.write(`Failed to resolve CFLAGS: ${err.message}\n`);
49+
process.exit(1);
50+
}

0 commit comments

Comments
 (0)