Skip to content

Commit

Permalink
feat: add musl target support in generate-packages and postinstall sc…
Browse files Browse the repository at this point in the history
…ripts
  • Loading branch information
matteosacchetto committed Dec 5, 2023
1 parent 1e999b5 commit 873b8c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
18 changes: 12 additions & 6 deletions packages/@biomejs/biome/scripts/generate-packages.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "node:fs";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { format } from "node:util";

const CLI_ROOT = resolve(fileURLToPath(import.meta.url), "../..");
const PACKAGES_ROOT = resolve(CLI_ROOT, "..");
Expand All @@ -11,10 +12,15 @@ const rootManifest = JSON.parse(
fs.readFileSync(MANIFEST_PATH).toString("utf-8"),
);

function generateNativePackage(platform, arch) {
const packageName = `@biomejs/cli-${platform}-${arch}`;
const packageRoot = resolve(PACKAGES_ROOT, `cli-${platform}-${arch}`);
function getName(platform, arch, prefix = 'cli') {
return format(`${prefix}-${platform}`, arch);
}

function generateNativePackage(platform, arch) {
const buildName = getName(platform, arch)
const packageName = `@biomejs/${buildName}`
const packageRoot = resolve(PACKAGES_ROOT, buildName);

// Remove the directory just in case it already exists (it's autogenerated
// so there shouldn't be anything important there anyway)
fs.rmSync(packageRoot, { recursive: true, force: true });
Expand Down Expand Up @@ -43,7 +49,7 @@ function generateNativePackage(platform, arch) {

// Copy the CLI binary
const ext = platform === "win32" ? ".exe" : "";
const binarySource = resolve(REPO_ROOT, `biome-${platform}-${arch}${ext}`);
const binarySource = resolve(REPO_ROOT, `${getName(platform, arch, 'biome')}${ext}`);
const binaryTarget = resolve(packageRoot, `biome${ext}`);

console.log(`Copy binary ${binaryTarget}`);
Expand Down Expand Up @@ -75,7 +81,7 @@ function writeManifest(packagePath) {

const nativePackages = PLATFORMS.flatMap((platform) =>
ARCHITECTURES.map((arch) => [
`@biomejs/cli-${platform}-${arch}`,
`@biomejs/${getName(platform, arch)}`,
rootManifest.version,
]),
);
Expand All @@ -88,7 +94,7 @@ function writeManifest(packagePath) {
fs.writeFileSync(manifestPath, content);
}

const PLATFORMS = ["win32", "darwin", "linux"];
const PLATFORMS = ["win32-%s", "darwin-%s", "linux-%s", "linux-%s-musl"];
const ARCHITECTURES = ["x64", "arm64"];
const WASM_TARGETS = ["bundler", "nodejs", "web"];

Expand Down
26 changes: 25 additions & 1 deletion packages/@biomejs/biome/scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
const { platform, arch } = process;
const { execSync } = require("child_process");

function isMusl() {
let stderr;
try {
stderr = execSync("ldd --version", {
stdio: ['pipe', 'pipe', 'pipe']
});
} catch (err) {
stderr = err.stderr;
}
if (stderr.indexOf("musl") > -1) {
return true;
}
return false;
}

const PLATFORMS = {
win32: {
Expand All @@ -13,9 +29,17 @@ const PLATFORMS = {
x64: "@biomejs/cli-linux-x64/biome",
arm64: "@biomejs/cli-linux-arm64/biome",
},
"linux-musl": {
x64: "@biomejs/cli-linux-x64-musl/biome",
arm64: "@biomejs/cli-linux-arm64-musl/biome",
},
};

const binName = PLATFORMS?.[platform]?.[arch];
const binName =
platform === "linux" && isMusl()
? PLATFORMS?.["linux-musl"]?.[arch]
: PLATFORMS?.[platform]?.[arch];

if (binName) {
let binPath;
try {
Expand Down

0 comments on commit 873b8c3

Please sign in to comment.