Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add musl binaries to the Standalone CLI #15567

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `@reference "…"` API as a replacement for the previous `@import "…" reference` option ([#15565](https://github.com/tailwindlabs/tailwindcss/pull/15565))
- Add functional utility syntax ([#15455](https://github.com/tailwindlabs/tailwindcss/pull/15455))
- Add new `--spacing(…)`, `--alpha(…)`, and `--theme(…)` CSS functions ([#15572](https://github.com/tailwindlabs/tailwindcss/pull/15572))
- Add Linux musl builds of the Standalone CLI ([#15567](https://github.com/tailwindlabs/tailwindcss/pull/15567))

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion packages/@tailwindcss-standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@parcel/watcher-linux-x64-musl": "^2.5.0",
"@parcel/watcher-win32-x64": "^2.5.0",
"@types/bun": "^1.1.14",
"bun": "1.1.42",
"bun": "1.1.43",
"lightningcss-darwin-arm64": "^1.25.1",
"lightningcss-darwin-x64": "^1.25.1",
"lightningcss-linux-arm64-gnu": "^1.25.1",
Expand Down
12 changes: 11 additions & 1 deletion packages/@tailwindcss-standalone/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ async function buildForPlatform(triple: string, outfile: string) {
// We wrap this in a retry because occasionally the atomic rename fails for some reason
for (let i = 0; i < 5; ++i) {
try {
return await $`bun build --compile --target=${triple} ./src/index.ts --outfile=${outfile}`
let cmd = $`bun build --compile --target=${triple} ./src/index.ts --outfile=${outfile} --env inline`

// This env var is used by our patched versions of Lightning CSS and Parcel Watcher
// to statically bundle the proper binaries for musl vs glibc
cmd = cmd.env({
PLATFORM_LIBC: triple.includes('-musl') ? 'musl' : 'glibc',
})

return await cmd
} catch (err) {
if (i < 5) continue

Expand Down Expand Up @@ -46,7 +54,9 @@ await mkdir(path.resolve(__dirname, '../dist'), { recursive: true })
// Build platform binaries and checksum them
let results = await Promise.all([
build('bun-linux-arm64', './tailwindcss-linux-arm64'),
build('bun-linux-arm64-musl', './tailwindcss-linux-arm64-musl'),
build('bun-linux-x64', './tailwindcss-linux-x64'),
build('bun-linux-x64-musl', './tailwindcss-linux-x64-musl'),
// build('linux-armv7', 'tailwindcss-linux-armv7'),
build('bun-darwin-arm64', './tailwindcss-macos-arm64'),
build('bun-darwin-x64', './tailwindcss-macos-x64'),
Expand Down
47 changes: 27 additions & 20 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/index.js b/index.js
index 8afb2b1126dcc687b7ff9b631589da252c1f9c22..f3b1158eb5612235388ff5f5347f6edcbf323090 100644
index 8afb2b1126dcc687b7ff9b631589da252c1f9c22..398af238a439912d150b3573367873d2a9a311e3 100644
--- a/index.js
+++ b/index.js
@@ -1,41 +1,27 @@
@@ -1,41 +1,34 @@
-const {createWrapper} = require('./wrapper');
+const { createWrapper } = require('./wrapper')

Expand All @@ -17,11 +17,12 @@ index 8afb2b1126dcc687b7ff9b631589da252c1f9c22..f3b1158eb5612235388ff5f5347f6edc
-}
+function loadPackage() {
+ if (process.platform === 'linux') {
+ let { MUSL, GLIBC, family, familySync } = require('detect-libc')
+ // Bun polyfills `detect-libc` in compiled binaries. We rely on
+ // [email protected] but the polyfilled version is 2.x. In detect-libc@2x
+ // there is a `familySync` function that we can use instead.
+ if (typeof familySync === 'function') family = familySync()
+ if (process.env.PLATFORM_LIBC === "musl") {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-musl`)
+ } else if (process.env.PLATFORM_LIBC === "glibc") {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-glibc`)
+ } else {
+ let { MUSL, GLIBC, family, familySync } = require('detect-libc')

-let binding;
-try {
Expand All @@ -37,24 +38,30 @@ index 8afb2b1126dcc687b7ff9b631589da252c1f9c22..f3b1158eb5612235388ff5f5347f6edc
- } catch (err) {
- handleError(err);
- throw new Error(`No prebuild or local build of @parcel/watcher found. Tried ${name}. Please ensure it is installed (don't use --no-optional when installing with npm). Otherwise it is possible we don't support your platform yet. If this is the case, please report an issue to https://github.com/parcel-bundler/watcher.`);
+ if (family === MUSL) {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-musl`)
+ } else if (family === GLIBC) {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-glibc`)
+ } else {
+ throw new Error(`Unsupported libc on: ${process.platform}-${process.arch}`)
}
- }
- }
-}
+ // Bun polyfills `detect-libc` in compiled binaries. We rely on
+ // [email protected] but the polyfilled version is 2.x. In detect-libc@2x
+ // there is a `familySync` function that we can use instead.
+ if (typeof familySync === 'function') family = familySync()

-function handleError(err) {
- if (err?.code !== 'MODULE_NOT_FOUND') {
- throw err;
+ if (family === MUSL) {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-musl`)
+ } else if (family === GLIBC) {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}-glibc`)
+ } else {
+ throw new Error(`Unsupported libc on: ${process.platform}-${process.arch}`)
+ }
+ }
+ } else {
+ return require(`@parcel/watcher-${process.platform}-${process.arch}`)
}
}

-function handleError(err) {
- if (err?.code !== 'MODULE_NOT_FOUND') {
- throw err;
- }
-}
-
-const wrapper = createWrapper(binding);
-exports.writeSnapshot = wrapper.writeSnapshot;
-exports.getEventsSince = wrapper.getEventsSince;
Expand Down
45 changes: 28 additions & 17 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/node/index.js b/node/index.js
index a9f2f6d5f3394329fcf8bc06af549030c01167a5..b92cc804adb694dbb17ee48368f13a03dd729267 100644
index a9f2f6d5f3394329fcf8bc06af549030c01167a5..db3b1c6cab5e4bac140d2f7a2b2e041d9a0a8a36 100644
--- a/node/index.js
+++ b/node/index.js
@@ -1,27 +1,32 @@
@@ -1,27 +1,43 @@
-let parts = [process.platform, process.arch];
-if (process.platform === 'linux') {
- const { MUSL, family } = require('detect-libc');
Expand All @@ -18,11 +18,16 @@ index a9f2f6d5f3394329fcf8bc06af549030c01167a5..b92cc804adb694dbb17ee48368f13a03
-}
+function loadPackage() {
+ if (process.platform === "linux") {
+ let { MUSL, GLIBC, family, familySync } = require("detect-libc");
+ // Bun polyfills `detect-libc` in compiled binaries. We rely on
+ // [email protected] but the polyfilled version is 2.x. In detect-libc@2x
+ // there is a `familySync` function that we can use instead.
+ if (typeof familySync === 'function') family = familySync()
+ if (process.env.PLATFORM_LIBC === 'musl') {
+ return require(`lightningcss-${process.platform}-${process.arch}-musl`);
+ } else if (process.env.PLATFORM_LIBC === 'glibc') {
+ if (process.arch === "arm") {
+ return require(`lightningcss-${process.platform}-${process.arch}-gnueabihf`);
+ } else {
+ return require(`lightningcss-${process.platform}-${process.arch}-gnu`);
+ }
+ } else {
+ let { MUSL, GLIBC, family, familySync } = require('detect-libc')

-if (process.env.CSS_TRANSFORMER_WASM) {
- module.exports = require(`../pkg`);
Expand All @@ -31,18 +36,24 @@ index a9f2f6d5f3394329fcf8bc06af549030c01167a5..b92cc804adb694dbb17ee48368f13a03
- module.exports = require(`lightningcss-${parts.join('-')}`);
- } catch (err) {
- module.exports = require(`../lightningcss.${parts.join('-')}.node`);
+ if (family === MUSL) {
+ return require(`lightningcss-${process.platform}-${process.arch}-musl`);
+ } else if (family === GLIBC) {
+ if (process.arch === "arm") {
+ return require(`lightningcss-${process.platform}-${process.arch}-gnueabihf`);
+ // Bun polyfills `detect-libc` in compiled binaries. We rely on
+ // [email protected] but the polyfilled version is 2.x. In detect-libc@2x
+ // there is a `familySync` function that we can use instead.
+ if (typeof familySync === 'function') family = familySync()
+
+ if (family === MUSL) {
+ return require(`lightningcss-${process.platform}-${process.arch}-musl`);
+ } else if (family === GLIBC) {
+ if (process.arch === "arm") {
+ return require(`lightningcss-${process.platform}-${process.arch}-gnueabihf`);
+ } else {
+ return require(`lightningcss-${process.platform}-${process.arch}-gnu`);
+ }
+ } else {
+ return require(`lightningcss-${process.platform}-${process.arch}-gnu`);
+ throw new Error(
+ `Unsupported libc on: ${process.platform}-${process.arch}`
+ );
+ }
+ } else {
+ throw new Error(
+ `Unsupported libc on: ${process.platform}-${process.arch}`
+ );
+ }
+ } else if (process.platform === "win32") {
+ return require(`lightningcss-${process.platform}-${process.arch}-msvc`);
Expand Down
Loading