Files
Chris Tate c4105d23a7 Stop building and shipping runtime import bitcode
Program builds have not imported runtime bitcode since fc38e6279, but
every runtime pack still built and listed it: release units through the
helper's prune-import, speed units as runtime-unit's second output. That
is 24 MB of the linux-x64-gnu pack.

Building that bitcode also cost scr_glibc_math its runtime profile: the
pruned import module keeps the floor, ceil and trunc ifuncs without their
resolvers and fails verification, and runtime-unit built it before the
object, so the whole speed unit fell back to a direct compile. The build
printed only the first line of the helper's stderr, a CPU feature
warning.

- runtime-unit's --bitcode is optional (feature
  "runtime-unit-optional-bitcode"), and pack builds no longer pass it or
  run prune-import. Speed objects come out as before, scr_glibc_math's now
  with the runtime profile.
- Pack manifests list no bitcode, and the compiler no longer validates the
  field. verify and share-artifacts check objects only.
- A unit the helper can't emit reports the helper's JSON diagnostic.
- The zero-cost gate names changed runtime functions from the objects'
  disassembly instead of the bitcode.
2026-10-29 17:58:37 -05:00

59 lines
2.0 KiB
JavaScript

#!/usr/bin/env node
import { createHash } from "node:crypto";
import { access, readFile } from "node:fs/promises";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
const root = dirname(dirname(fileURLToPath(import.meta.url)));
const manifest = JSON.parse(await readFile(join(root, "runtime-pack.json"), "utf8"));
const packageManifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
if (
manifest.schema !== "scriptc.runtime-pack.v1" ||
manifest.format !== 1 ||
manifest.package !== packageManifest.name ||
manifest.version !== packageManifest.version
)
throw new Error("runtime pack identity does not match package.json");
const artifacts = [
...Object.values(manifest.flavors).flatMap((flavor) =>
flavor.runtime_units.flatMap((unit) => unit.variants),
),
...manifest.archives,
];
function printableStrings(bytes) {
const strings = [];
let start = -1;
for (let i = 0; i <= bytes.length; i++) {
const byte = bytes[i];
if (byte !== undefined && byte >= 0x20 && byte <= 0x7e) {
if (start === -1) start = i;
continue;
}
if (start !== -1 && i - start >= 4) strings.push(bytes.subarray(start, i).toString("ascii"));
start = -1;
}
return strings;
}
for (const artifact of artifacts) {
const path = join(root, artifact.path);
const bytes = await readFile(path);
const digest = createHash("sha256").update(bytes).digest("hex");
if (bytes.length !== artifact.size || digest !== artifact.sha256) {
throw new Error(`runtime pack hash mismatch: ${artifact.path}`);
}
const checkoutPath = printableStrings(bytes).find(
(value) => value.startsWith("/") && value.includes("/packages/runtime/"),
);
if (checkoutPath !== undefined) {
throw new Error(
`runtime pack contains an absolute source path in ${artifact.path}: ${checkoutPath}`,
);
}
}
for (const license of manifest.licenses) await access(join(root, license.path));
process.stdout.write(
`verified ${manifest.package}@${manifest.version}: ${artifacts.length} artifacts\n`,
);