Skip to content

Commit b9bff84

Browse files
cometkimcknitt
andauthored
Per-platform binary packages (#7395)
Co-authored-by: Christoph Knittel <[email protected]>
1 parent 6728d57 commit b9bff84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+717
-364
lines changed

.github/workflows/ci.yml

+58-44
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ jobs:
2727
include:
2828
- os: macos-13 # x64
2929
rust-target: x86_64-apple-darwin
30+
node-target: darwin-x64
3031
- os: macos-14 # ARM
3132
rust-target: aarch64-apple-darwin
33+
node-target: darwin-arm64
3234
- os: ubuntu-24.04 # x64
3335
rust-target: x86_64-unknown-linux-musl
36+
node-target: linux-x64
3437
- os: ubuntu-24.04-arm # ARM
3538
rust-target: aarch64-unknown-linux-musl
39+
node-target: linux-arm64
3640
- os: windows-latest
3741
rust-target: x86_64-pc-windows-gnu
42+
node-target: win32-x64
3843

3944
runs-on: ${{matrix.os}}
4045

@@ -66,25 +71,24 @@ jobs:
6671
uses: dtolnay/rust-toolchain@master
6772
with:
6873
toolchain: stable
69-
targets: ${{matrix.rust-target}}
74+
targets: ${{ matrix.rust-target }}
7075

7176
- name: Build rewatch
7277
if: steps.build-cache.outputs.cache-hit != 'true'
73-
run: cargo build --manifest-path rewatch/Cargo.toml --target ${{matrix.rust-target}} --release
74-
75-
- name: Copy rewatch exe to platform bin dir
7678
run: |
77-
cp rewatch/target/${{matrix.rust-target}}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch
78-
node ./scripts/copyExes.js -rewatch
79+
cargo build --manifest-path rewatch/Cargo.toml --target ${{ matrix.rust-target }} --release
7980
80-
- name: Get artifact dir name
81-
run: node .github/workflows/get_artifact_dir_name.js
81+
- name: Copy rewatch binary
82+
run: |
83+
cp rewatch/target/${{ matrix.rust-target }}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch.exe
84+
shell: bash
8285

8386
- name: "Upload artifact: rewatch binary"
8487
uses: actions/upload-artifact@v4
8588
with:
86-
name: rewatch-${{env.artifact_dir_name}}
87-
path: ${{ env.artifact_dir_name }}
89+
name: rewatch-${{ matrix.node-target }}
90+
path: rewatch.exe
91+
if-no-files-found: error
8892

8993
build-compiler:
9094
strategy:
@@ -95,21 +99,26 @@ jobs:
9599
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
96100
upload_binaries: true
97101
upload_libs: true
102+
node-target: linux-x64
98103
- os: ubuntu-24.04-arm # ARM
99104
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
100105
upload_binaries: true
101106
# Build the playground compiler and run the benchmarks on the fastest runner
102107
build_playground: true
103108
benchmarks: true
109+
node-target: linux-arm64
104110
- os: macos-13 # x64
105111
ocaml_compiler: 5.3.0
106112
upload_binaries: true
113+
node-target: darwin-x64
107114
- os: macos-14 # ARM
108115
ocaml_compiler: 5.3.0
109116
upload_binaries: true
117+
node-target: darwin-arm64
110118
- os: windows-latest
111119
ocaml_compiler: 5.3.0
112120
upload_binaries: true
121+
node-target: win32-x64
113122

114123
# Verify that the compiler still builds with older OCaml versions
115124
- os: ubuntu-24.04
@@ -144,9 +153,6 @@ jobs:
144153
cache: yarn
145154
node-version-file: .nvmrc
146155

147-
- name: Get artifact dir name
148-
run: node .github/workflows/get_artifact_dir_name.js
149-
150156
- name: Install dependencies (Linux)
151157
if: runner.os == 'Linux'
152158
uses: awalsh128/[email protected]
@@ -303,13 +309,13 @@ jobs:
303309
run: yarn install
304310

305311
- name: Copy compiler exes to platform bin dir
306-
run: node ./scripts/copyExes.js -compiler
312+
run: node scripts/copyExes.js --compiler
307313

308314
- name: Restore ninja build cache
309315
id: ninja-build-cache
310316
uses: actions/cache@v4
311317
with:
312-
path: ${{ env.artifact_dir_name }}/ninja.exe
318+
path: packages/@rescript/${{ matrix.node-target }}/bin/ninja.exe
313319
key: ninja-build-v1-${{ matrix.os }}-${{ hashFiles('ninja/src/**') }}
314320

315321
- name: Setup Python for ninja build
@@ -336,7 +342,7 @@ jobs:
336342

337343
- name: Copy ninja exe to platform bin dir
338344
if: steps.ninja-build-cache.outputs.cache-hit != 'true'
339-
run: node ./scripts/copyExes.js -ninja
345+
run: node scripts/copyExes.js --ninja
340346

341347
- name: "Syntax: Run roundtrip tests"
342348
if: ${{ runner.os != 'Windows' }}
@@ -423,8 +429,8 @@ jobs:
423429
if: matrix.upload_binaries
424430
uses: actions/upload-artifact@v4
425431
with:
426-
name: binaries-${{ env.artifact_dir_name }}
427-
path: ${{ env.artifact_dir_name }}
432+
name: binaries-${{ matrix.node-target }}
433+
path: packages/@rescript/${{ matrix.node-target }}/bin
428434

429435
- name: "Upload artifacts: lib/ocaml"
430436
if: matrix.upload_libs
@@ -438,7 +444,7 @@ jobs:
438444
- build-compiler
439445
- build-rewatch
440446

441-
runs-on: ubuntu-24.04
447+
runs-on: ubuntu-24.04-arm
442448

443449
steps:
444450
- name: Checkout
@@ -447,29 +453,22 @@ jobs:
447453
- name: Use Node.js
448454
uses: actions/setup-node@v4
449455
with:
450-
cache: yarn
451456
node-version-file: .nvmrc
452457

453-
- name: NPM install
454-
run: yarn install
455-
456458
- name: Download artifacts
457459
uses: actions/download-artifact@v4
458460
with:
459461
pattern: "@(binaries-*|rewatch-*|lib-ocaml)"
460462

461-
- name: Move artifacts
462-
run: ./scripts/moveArtifacts.sh
463+
- name: Move artifacts into packages
464+
run: .github/workflows/moveArtifacts.sh
465+
shell: bash
463466

464-
- name: npm pack (rescript) + check artifact list
467+
- name: Check artifact list
465468
run: node ./scripts/npmPack.js
466469

467-
- name: Copy JS files to stdlib package
468-
run: mkdir -p packages/std/lib && cp -R lib/es6 lib/js packages/std/lib
469-
470-
- name: npm pack (@rescript/std)
471-
run: npm pack
472-
working-directory: packages/std
470+
- name: yarn pack @rescript/* subpackages
471+
run: yarn workspaces foreach -W --no-private --exclude rescript pack
473472

474473
- name: Prepare package upload
475474
# For pull requests, pass the correct commit SHA explicitly as GITHUB_SHA points to the wrong commit.
@@ -482,6 +481,11 @@ jobs:
482481
path: |
483482
rescript-${{ env.rescript_version }}.tgz
484483
rescript-std-${{ env.rescript_version }}.tgz
484+
rescript-linux-x64-${{ env.rescript_version }}.tgz
485+
rescript-linux-arm64-${{ env.rescript_version }}.tgz
486+
rescript-darwin-x64-${{ env.rescript_version }}.tgz
487+
rescript-darwin-arm64-${{ env.rescript_version }}.tgz
488+
rescript-win32-x64-${{ env.rescript_version }}.tgz
485489
486490
outputs:
487491
rescript_version: ${{ env.rescript_version }}
@@ -491,15 +495,19 @@ jobs:
491495
strategy:
492496
fail-fast: false
493497
matrix:
494-
os: [
495-
macos-13, # x64
496-
macos-14, # ARM
497-
ubuntu-24.04,
498-
ubuntu-24.04-arm,
499-
windows-latest,
500-
]
498+
include:
499+
- os: macos-13
500+
node-target: darwin-x64
501+
- os: macos-14
502+
node-target: darwin-arm64
503+
- os: ubuntu-24.04
504+
node-target: linux-x64
505+
- os: ubuntu-24.04-arm
506+
node-target: linux-arm64
507+
- os: windows-latest
508+
node-target: win32-x64
501509

502-
runs-on: ${{matrix.os}}
510+
runs-on: ${{ matrix.os }}
503511

504512
steps:
505513
- name: Checkout
@@ -532,7 +540,8 @@ jobs:
532540
- name: Install ReScript package
533541
run: |
534542
npm i --ignore-scripts --no-audit \
535-
rescript-${{ needs.package.outputs.rescript_version }}.tgz
543+
rescript-${{ needs.package.outputs.rescript_version }}.tgz \
544+
rescript-${{ matrix.node-target }}-${{ needs.package.outputs.rescript_version }}.tgz
536545
shell: bash
537546
working-directory: ${{ steps.tmp-dir.outputs.path }}
538547

@@ -546,7 +555,7 @@ jobs:
546555

547556
if: startsWith(github.ref, 'refs/tags/v')
548557

549-
runs-on: ubuntu-24.04
558+
runs-on: ubuntu-24.04-arm
550559

551560
steps:
552561
- name: Checkout
@@ -568,8 +577,13 @@ jobs:
568577
env:
569578
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
570579
run: |
571-
npm publish rescript-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
572-
npm publish rescript-std-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
580+
npm publish --tag ci rescript-${{ needs.package.outputs.rescript_version }}.tgz
581+
npm publish --tag ci rescript-std-${{ needs.package.outputs.rescript_version }}.tgz
582+
npm publish --tag ci rescript-linux-x64-${{ needs.package.outputs.rescript_version }}.tgz
583+
npm publish --tag ci rescript-linux-arm64-${{ needs.package.outputs.rescript_version }}.tgz
584+
npm publish --tag ci rescript-darwin-x64-${{ needs.package.outputs.rescript_version }}.tgz
585+
npm publish --tag ci rescript-darwin-arm64-{{ needs.package.outputs.rescript_version }}.tgz
586+
npm publish --tag ci rescript-win32-x64-${{ needs.package.outputs.rescript_version }}.tgz
573587
574588
- name: Update Website Playground
575589
env:

.github/workflows/get_artifact_dir_name.js

-10
This file was deleted.

scripts/moveArtifacts.sh renamed to .github/workflows/moveArtifacts.sh

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
23
set -e
34

45
check_statically_linked() {
@@ -24,18 +25,19 @@ check_statically_linked() {
2425
fi
2526
}
2627

27-
chmod +x binaries-*/*.exe rewatch-*/*.exe
28-
29-
mkdir darwin darwinarm64 linux linuxarm64 win32
30-
31-
mv binaries-darwin/* rewatch-darwin/* darwin
32-
mv binaries-darwinarm64/* rewatch-darwinarm64/* darwinarm64
33-
mv binaries-linux/* rewatch-linux/* linux
34-
mv binaries-linuxarm64/* rewatch-linuxarm64/* linuxarm64
35-
mv binaries-win32/* rewatch-win32/* win32
36-
28+
# rescript
3729
mv lib-ocaml lib/ocaml
38-
mv ninja/COPYING ninja.COPYING
3930

40-
check_statically_linked "linux"
41-
check_statically_linked "linuxarm64"
31+
# @rescript/{target}
32+
chmod +x binaries-*/*.exe rewatch-*/*.exe
33+
mv -f binaries-darwin-x64/* rewatch-darwin-x64/* "packages/@rescript/darwin-x64/bin"
34+
mv -f binaries-darwin-arm64/* rewatch-darwin-arm64/* "packages/@rescript/darwin-arm64/bin"
35+
mv -f binaries-linux-x64/* rewatch-linux-x64/* "packages/@rescript/linux-x64/bin"
36+
mv -f binaries-linux-arm64/* rewatch-linux-arm64/* "packages/@rescript/linux-arm64/bin"
37+
mv -f binaries-win32-x64/* rewatch-win32-x64/* "packages/@rescript/win32-x64/bin"
38+
check_statically_linked "packages/@rescript/linux-x64/bin"
39+
check_statically_linked "packages/@rescript/linux-arm64/bin"
40+
41+
# @rescript/std
42+
mkdir -p packages/std/lib
43+
cp -R lib/es6 lib/js packages/std/lib

.github/workflows/prepare_package_upload.js

+27-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,43 @@ import * as fs from "node:fs";
22
import * as os from "node:os";
33

44
const packageSpec = JSON.parse(
5-
fs.readFileSync(new URL("../../package.json", import.meta.url), "utf-8")
5+
fs.readFileSync(new URL("../../package.json", import.meta.url), "utf-8"),
66
);
77

88
const { version } = packageSpec;
99

1010
const commitHash = process.argv[2] || process.env.GITHUB_SHA;
1111
const commitHashShort = commitHash.substring(0, 7);
1212

13+
// rescript
14+
fs.renameSync("package.tgz", `rescript-${version}-${commitHashShort}.tgz`);
15+
16+
// @rescript/std
17+
fs.renameSync(
18+
"packages/std/package.tgz",
19+
`rescript-std-${version}-${commitHashShort}.tgz`,
20+
);
21+
22+
// @rescript/{target}
1323
fs.renameSync(
14-
`rescript-${version}.tgz`,
15-
`rescript-${version}-${commitHashShort}.tgz`,
24+
"packages/@rescript/linux-x64/package.tgz",
25+
`rescript-linux-x64-${version}-${commitHashShort}.tgz`,
1626
);
1727
fs.renameSync(
18-
`packages/std/rescript-std-${version}.tgz`,
19-
`rescript-std-${version}-${commitHashShort}.tgz`,
28+
"packages/@rescript/linux-arm64/package.tgz",
29+
`rescript-linux-arm64-${version}-${commitHashShort}.tgz`,
30+
);
31+
fs.renameSync(
32+
"packages/@rescript/darwin-x64/package.tgz",
33+
`rescript-darwin-x64-${version}-${commitHashShort}.tgz`,
34+
);
35+
fs.renameSync(
36+
"packages/@rescript/darwin-arm64/package.tgz",
37+
`rescript-darwin-arm64-${version}-${commitHashShort}.tgz`,
38+
);
39+
fs.renameSync(
40+
"packages/@rescript/win32-x64/package.tgz",
41+
`rescript-win32-x64-${version}-${commitHashShort}.tgz`,
2042
);
2143

2244
// Pass information to subsequent GitHub actions

.gitignore

+10-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ _build
4646
node_modules
4747
*.dump
4848
coverage
49-
*.exe
5049

5150
.ninja_log
5251
.bsdeps
@@ -82,6 +81,12 @@ tests/tools_tests/lib
8281
tests/analysis_tests*/lib
8382
tests/analysis_tests/**/*.bs.js
8483

84+
/linux/*.exe
85+
/linuxarm64/*.exe
86+
/darwin/*.exe
87+
/darwinarm64/*.exe
88+
/win32/*.exe
89+
8590
.yarn/*
8691
!.yarn/patches
8792
!.yarn/plugins
@@ -90,3 +95,7 @@ tests/analysis_tests/**/*.bs.js
9095
!.yarn/versions
9196

9297
*.tsbuildinfo
98+
99+
# package tarballs
100+
package.tgz
101+
*.exe

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#### :rocket: New Feature
2020

2121
- Add shift (`<<`, `>>`, `>>>`) operators for `int` and `bigint`. https://github.com/rescript-lang/rescript/pull/7183
22+
- Significantly reduced the download size by splitting binaries into optional platform-specific dependencies (e.g, `@rescript/linux-x64`). https://github.com/rescript-lang/rescript/pull/7395
2223

2324
#### :bug: Bug fix
2425

0 commit comments

Comments
 (0)