Files
kucherenko__jscpd/rust/basta/platform-map.js
apk b718753839 chore(basta): ship basta on its own trigger, separate from the jscpd release
basta is a separate product from jscpd — a different question about the
same tree — so it gets its own version, its own prebuilt packages and its
own trigger. jscpd goes out on every push to master that leaves a version
unpublished; basta goes out only when a `basta-v*` tag is pushed, or by
hand through workflow_dispatch. Neither release can drag the other along
or hold it up.

`basta-release.yml` owns the whole thing: it checks that the crate, the npm
manifest and the tag all name the same version and that the working tree is
already synced, publishes the crate, builds the eight targets and publishes
`basta-<platform>` plus the `basta` wrapper. It ends by asserting that npm's
`latest` really points at this release — the package carries 1.x versions
from an unrelated tool of the same name, and a dist-tag that quietly stayed
on those would hand every `npm i basta` the wrong program.

The one place the two cannot be separated is crates.io: `jscpd` depends on
`basta`, so cargo refuses to publish jscpd until a matching basta exists.
The jscpd crates job therefore still publishes basta when it is missing, and
that is now commented as the dependency requirement it is. Both paths skip a
version already on the registry, so whichever runs first wins.

npm needed the wrapper pattern `jscpd` and `cpd` already use: `rust/basta/`
holds the manifest, a platform map naming `basta-<platform>`, and a launcher
that falls back to a local `cargo build` when no platform package is
installed. `npm-prebuilt-package.mjs` grew a `--product` flag; its output for
jscpd is byte-identical to before. `prebuilt-targets.json` now carries a
platform label rather than a jscpd-specific blurb, so one table serves both
products. `sync-version.mjs` syncs and verifies the basta wrapper against the
basta crate version — the same independent version/pin update the jscpd block
does, for the same reason it does it.

Nothing is published by this commit.

Claude-Session: https://claude.ai/code/session_01WztdFKZAwW9b51iJe9zhtV
2026-09-16 11:01:06 +02:00

119 lines
2.6 KiB
JavaScript

"use strict";
const { platform, arch } = process;
const PLATFORM_MAP = {
"linux-x64-gnu": {
packageName: "basta-linux-x64-gnu",
os: "linux",
cpu: "x64",
libc: "glibc",
rustTarget: "x86_64-unknown-linux-gnu",
runner: "ubuntu-latest",
},
"linux-arm64-gnu": {
packageName: "basta-linux-arm64-gnu",
os: "linux",
cpu: "arm64",
libc: "glibc",
rustTarget: "aarch64-unknown-linux-gnu",
runner: "ubuntu-latest",
},
"linux-x64-musl": {
packageName: "basta-linux-x64-musl",
os: "linux",
cpu: "x64",
libc: "musl",
rustTarget: "x86_64-unknown-linux-musl",
runner: "ubuntu-latest",
},
"linux-arm64-musl": {
packageName: "basta-linux-arm64-musl",
os: "linux",
cpu: "arm64",
libc: "musl",
rustTarget: "aarch64-unknown-linux-musl",
runner: "ubuntu-22.04-arm",
},
"darwin-arm64": {
packageName: "basta-darwin-arm64",
os: "darwin",
cpu: "arm64",
rustTarget: "aarch64-apple-darwin",
runner: "macos-latest",
},
"darwin-x64": {
packageName: "basta-darwin-x64",
os: "darwin",
cpu: "x64",
rustTarget: "x86_64-apple-darwin",
runner: "macos-13",
},
"windows-x64-msvc": {
packageName: "basta-windows-x64-msvc",
os: "win32",
cpu: "x64",
rustTarget: "x86_64-pc-windows-msvc",
runner: "windows-latest",
},
"windows-arm64-msvc": {
packageName: "basta-windows-arm64-msvc",
os: "win32",
cpu: "arm64",
rustTarget: "aarch64-pc-windows-msvc",
runner: "windows-11-arm",
},
};
function detectLinuxLibc() {
if (platform !== "linux") {
return undefined;
}
const report =
process.report && typeof process.report.getReport === "function"
? process.report.getReport()
: undefined;
if (report && report.header && report.header.glibcVersionRuntime) {
return "glibc";
}
return "musl";
}
function getPlatformKey() {
const libc = detectLinuxLibc();
for (const [key, target] of Object.entries(PLATFORM_MAP)) {
if (target.os !== platform || target.cpu !== arch) {
continue;
}
if (target.os === "linux" && target.libc !== libc) {
continue;
}
return key;
}
return undefined;
}
/**
* Human-readable description of the host, e.g. "linux/arm64 (musl)", for
* error messages.
*/
function describeHost() {
const libc = detectLinuxLibc();
return `${platform}/${arch}${libc ? ` (${libc})` : ""}`;
}
/** Supported platform keys, e.g. ["linux-x64-gnu", ...]. */
function supportedPlatforms() {
return Object.keys(PLATFORM_MAP);
}
module.exports = {
PLATFORM_MAP,
getPlatformKey,
detectLinuxLibc,
describeHost,
supportedPlatforms,
};