Files
reverse-engineering-anything/scripts/lib/cargo-build-artifacts.mjs
T
Matt Van Hornandgensokyo-dev 237b1ea5b3 feat(evidence): project Go and Rust dependencies as CycloneDX
Project retained Go and Rust dependency metadata as deterministic, bounded CycloneDX documents with parent provenance and explicit unknowns. Share current Evidence identity admission and canonical document-ceiling recovery.

Assisted-by: Suika (gensokyo-skills:suika-scatter-gather-planning)
Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
2026-11-17 10:47:29 +00:00

37 lines
1.2 KiB
JavaScript

/**
* Select the one executable Cargo reported for a binary target.
*
* Cargo owns the output layout: CARGO_BUILD_TARGET, build.target and profile
* settings all move the executable, so read its `compiler-artifact` messages
* instead of reconstructing the path.
*/
export function cargoExecutableArtifact(messages, targetName) {
const executables = [];
for (const line of messages.split("\n")) {
const text = line.trim();
if (!text.startsWith("{")) continue;
let message;
try {
message = JSON.parse(text);
} catch {
continue;
}
if (
message?.reason === "compiler-artifact" &&
message.target?.name === targetName &&
Array.isArray(message.target.kind) &&
message.target.kind.includes("bin") &&
typeof message.executable === "string"
)
executables.push(message.executable);
}
const unique = [...new Set(executables)];
if (unique.length !== 1)
throw new Error(
unique.length === 0
? `Cargo reported no executable for binary target ${targetName}.`
: `Cargo reported multiple executables for binary target ${targetName}: ${unique.join(", ")}`,
);
return unique[0];
}