Files
bun.sh/scripts/create-link-metadata.mjs
Dylan Conway 698b004ea4 Add step in CI to upload link metadata (#25448)
### What does this PR do?

### How did you verify your code works?

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-12-16 14:30:10 -08:00

50 lines
1.6 KiB
JavaScript

#!/usr/bin/env bun
/**
* Creates link-metadata.json with link command and build metadata
*
* Usage: bun scripts/create-link-metadata.mjs <build-path> <bun-target>
*/
import { $ } from "bun";
import { dirname, join } from "path";
const [buildPath, bunTarget] = process.argv.slice(2);
if (!buildPath || !bunTarget) {
console.error("Usage: bun scripts/create-link-metadata.mjs <build-path> <bun-target>");
process.exit(1);
}
// Get the repo root (parent of scripts directory)
const repoRoot = dirname(import.meta.dir);
// Extract link command using ninja
console.log("Extracting link command...");
const linkCommandResult = await $`ninja -C ${buildPath} -t commands ${bunTarget}`.quiet();
const linkCommand = linkCommandResult.stdout.toString().trim();
// Read linker-related files from src/
console.log("Reading linker files...");
const linkerLds = await Bun.file(join(repoRoot, "src", "linker.lds")).text();
const symbolsDyn = await Bun.file(join(repoRoot, "src", "symbols.dyn")).text();
const symbolsTxt = await Bun.file(join(repoRoot, "src", "symbols.txt")).text();
// Create metadata JSON with link command included
const metadata = {
webkit_url: process.env.WEBKIT_DOWNLOAD_URL || "",
webkit_version: process.env.WEBKIT_VERSION || "",
zig_commit: process.env.ZIG_COMMIT || "",
target: bunTarget,
timestamp: new Date().toISOString(),
link_command: linkCommand,
linker_lds: linkerLds,
symbols_dyn: symbolsDyn,
symbols_txt: symbolsTxt,
};
const metadataPath = join(buildPath, "link-metadata.json");
await Bun.write(metadataPath, JSON.stringify(metadata, null, 2));
console.log(`Written to ${metadataPath}`);
console.log("Done");