Skip to content

Commit db4ea84

Browse files
authored
Build CLI packages in CI (parcel-bundler#80)
1 parent 18adb3b commit db4ea84

File tree

5 files changed

+144
-12
lines changed

5 files changed

+144
-12
lines changed

.github/workflows/release.yml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ jobs:
1111
# Windows
1212
- os: windows-latest
1313
target: x86_64-pc-windows-msvc
14+
binary: parcel_css.exe
1415
# Mac OS
1516
- os: macos-latest
1617
target: x86_64-apple-darwin
1718
strip: strip -x # Must use -x on macOS. This produces larger results on linux.
19+
binary: parcel_css
1820

1921
name: build-${{ matrix.target }}
2022
runs-on: ${{ matrix.os }}
@@ -39,14 +41,20 @@ jobs:
3941
run: yarn build-release
4042
env:
4143
RUST_TARGET: ${{ matrix.target }}
44+
- name: Build CLI
45+
run: |
46+
cargo build --release --features cli --target ${{ matrix.target }}
47+
node -e "require('fs').renameSync('target/${{ matrix.target }}/release/${{ matrix.binary }}', '${{ matrix.binary }}')"
4248
- name: Strip debug symbols # https://github.com/rust-lang/rust/issues/46034
4349
if: ${{ matrix.strip }}
44-
run: ${{ matrix.strip }} *.node
50+
run: ${{ matrix.strip }} *.node ${{ matrix.binary }}
4551
- name: Upload artifacts
4652
uses: actions/upload-artifact@v2
4753
with:
4854
name: bindings-${{ matrix.target }}
49-
path: '*.node'
55+
path: |
56+
*.node
57+
${{ matrix.binary }}
5058
5159
build-apple-silicon:
5260
name: build-apple-silicon
@@ -73,13 +81,26 @@ jobs:
7381
env:
7482
RUST_TARGET: aarch64-apple-darwin
7583
JEMALLOC_SYS_WITH_LG_PAGE: 14
84+
- name: Build CLI
85+
run: |
86+
export CC=$(xcrun -f clang);
87+
export CXX=$(xcrun -f clang++);
88+
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
89+
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
90+
export MACOSX_DEPLOYMENT_TARGET="10.9";
91+
cargo build --release --features cli --target aarch64-apple-darwin
92+
mv target/aarch64-apple-darwin/release/parcel_css parcel_css
93+
env:
94+
JEMALLOC_SYS_WITH_LG_PAGE: 14
7695
- name: Strip debug symbols # https://github.com/rust-lang/rust/issues/46034
77-
run: strip -x *.node
96+
run: strip -x *.node parcel_css
7897
- name: Upload artifacts
7998
uses: actions/upload-artifact@v2
8099
with:
81100
name: bindings-aarch64-apple-darwin
82-
path: '*.node'
101+
path: |
102+
*.node
103+
parcel_css
83104
84105
build-linux:
85106
strategy:
@@ -134,14 +155,20 @@ jobs:
134155
run: yarn build-release
135156
env:
136157
RUST_TARGET: ${{ matrix.target }}
158+
- name: Build CLI
159+
run: |
160+
cargo build --release --features cli --target ${{ matrix.target }}
161+
mv target/${{ matrix.target }}/release/parcel_css parcel_css
137162
- name: Strip debug symbols # https://github.com/rust-lang/rust/issues/46034
138163
if: ${{ matrix.strip }}
139-
run: ${{ matrix.strip }} *.node
164+
run: ${{ matrix.strip }} *.node parcel_css
140165
- name: Upload artifacts
141166
uses: actions/upload-artifact@v2
142167
with:
143168
name: bindings-${{ matrix.target }}
144-
path: '*.node'
169+
path: |
170+
*.node
171+
parcel_css
145172
146173
build-wasm:
147174
runs-on: ubuntu-latest
@@ -191,6 +218,10 @@ jobs:
191218
npm publish;
192219
cd ../..;
193220
done
221+
cd cli
222+
echo "Publishing @parcel/css-cli...";
223+
npm publish
224+
cd ..
194225
echo "Publishing @parcel/css...";
195226
npm publish
196227

cli/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package.json
2+
README.md
3+
.DS_Store
4+
parcel_css.exe

cli/parcel_css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file is required so that npm creates the parcel-css binary on Windows.

cli/postinstall.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
let fs = require('fs');
2+
let path = require('path');
3+
4+
let parts = [process.platform, process.arch];
5+
if (process.platform === 'linux') {
6+
const {MUSL, family} = require('detect-libc');
7+
if (family === MUSL) {
8+
parts.push('musl');
9+
} else if (process.arch === 'arm') {
10+
parts.push('gnueabihf');
11+
} else {
12+
parts.push('gnu');
13+
}
14+
} else if (process.platform === 'win32') {
15+
parts.push('msvc');
16+
}
17+
18+
let binary = process.platform === 'win32' ? 'parcel_css.exe' : 'parcel_css';
19+
20+
let pkgPath;
21+
try {
22+
pkgPath = path.dirname(require.resolve(`@parcel/css-cli-${parts.join('-')}/package.json`));
23+
} catch (err) {
24+
pkgPath = path.join(__dirname, '..', 'target', 'release');
25+
if (!fs.existsSync(path.join(pkgPath, binary))) {
26+
pkgPath = path.join(__dirname, '..', 'target', 'debug');
27+
}
28+
}
29+
30+
try {
31+
fs.linkSync(path.join(pkgPath, binary), path.join(__dirname, binary));
32+
} catch (err) {
33+
try {
34+
fs.copyFileSync(path.join(pkgPath, binary), path.join(__dirname, binary));
35+
} catch (err) {
36+
console.error('Failed to move @parcel/css-cli binary into place.');
37+
process.exit(1);
38+
}
39+
}
40+
41+
if (process.platform === 'win32') {
42+
try {
43+
fs.unlinkSync(path.join(__dirname, 'parcel_css'));
44+
} catch (err) {}
45+
}

scripts/build-npm.js

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const sysToNodePlatform = {
2626
};
2727

2828
let optionalDependencies = {};
29+
let cliOptionalDependencies = {};
2930

3031
try {
3132
fs.mkdirSync(dir + '/npm');
@@ -41,6 +42,33 @@ for (let triple of triples) {
4142
t += '-' + abi;
4243
}
4344

45+
buildNode(triple, cpu, os, t);
46+
buildCLI(triple, cpu, os, t);
47+
}
48+
49+
pkg.optionalDependencies = optionalDependencies;
50+
fs.writeFileSync(`${dir}/package.json`, JSON.stringify(pkg, false, 2) + '\n');
51+
52+
let cliPkg = {...pkg};
53+
cliPkg.name += '-cli';
54+
cliPkg.bin = {
55+
'parcel-css': 'parcel_css'
56+
};
57+
delete cliPkg.main;
58+
delete cliPkg.napi;
59+
delete cliPkg.devDependencies;
60+
delete cliPkg.targets;
61+
delete cliPkg.types;
62+
cliPkg.files = ['parcel_css', 'postinstall.js'];
63+
cliPkg.optionalDependencies = cliOptionalDependencies;
64+
cliPkg.scripts = {
65+
postinstall: 'node postinstall.js'
66+
};
67+
68+
fs.writeFileSync(`${dir}/cli/package.json`, JSON.stringify(cliPkg, false, 2) + '\n');
69+
fs.copyFileSync(`${dir}/README.md`, `${dir}/cli/README.md`);
70+
71+
function buildNode(triple, cpu, os, t) {
4472
let name = `parcel-css.${t}.node`;
4573

4674
let pkg2 = {...pkg};
@@ -60,12 +88,35 @@ for (let triple of triples) {
6088
optionalDependencies[pkg2.name] = pkg.version;
6189

6290
try {
63-
fs.mkdirSync(dir + '/npm/' + t);
91+
fs.mkdirSync(dir + '/npm/node-' + t);
6492
} catch (err) {}
65-
fs.writeFileSync(`${dir}/npm/${t}/package.json`, JSON.stringify(pkg2, false, 2) + '\n');
66-
fs.copyFileSync(`${dir}/artifacts/bindings-${triple}/${name}`, `${dir}/npm/${t}/${name}`);
67-
fs.writeFileSync(`${dir}/npm/${t}/README.md`, `This is the ${triple} build of @parcel/css. See https://github.com/parcel-bundler/parcel-css for details.`);
93+
fs.writeFileSync(`${dir}/npm/node-${t}/package.json`, JSON.stringify(pkg2, false, 2) + '\n');
94+
fs.copyFileSync(`${dir}/artifacts/bindings-${triple}/${name}`, `${dir}/npm/node-${t}/${name}`);
95+
fs.writeFileSync(`${dir}/npm/node-${t}/README.md`, `This is the ${triple} build of @parcel/css. See https://github.com/parcel-bundler/parcel-css for details.`);
6896
}
6997

70-
pkg.optionalDependencies = optionalDependencies;
71-
fs.writeFileSync(`${dir}/package.json`, JSON.stringify(pkg, false, 2) + '\n');
98+
function buildCLI(triple, cpu, os, t) {
99+
let binary = os === 'win32' ? 'parcel_css.exe' : 'parcel_css';
100+
let pkg2 = {...pkg};
101+
pkg2.name += '-cli-' + t;
102+
pkg2.os = [os];
103+
pkg2.cpu = [cpu];
104+
pkg2.files = [binary];
105+
delete pkg2.main;
106+
delete pkg2.napi;
107+
delete pkg2.devDependencies;
108+
delete pkg2.dependencies;
109+
delete pkg2.optionalDependencies;
110+
delete pkg2.targets;
111+
delete pkg2.scripts;
112+
delete pkg2.types;
113+
114+
cliOptionalDependencies[pkg2.name] = pkg.version;
115+
116+
try {
117+
fs.mkdirSync(dir + '/npm/cli-' + t);
118+
} catch (err) {}
119+
fs.writeFileSync(`${dir}/npm/cli-${t}/package.json`, JSON.stringify(pkg2, false, 2) + '\n');
120+
fs.copyFileSync(`${dir}/artifacts/bindings-${triple}/${binary}`, `${dir}/npm/cli-${t}/${binary}`);
121+
fs.writeFileSync(`${dir}/npm/cli-${t}/README.md`, `This is the ${triple} build of @parcel/css-cli. See https://github.com/parcel-bundler/parcel-css for details.`);
122+
}

0 commit comments

Comments
 (0)