Skip to content

Per-platform binary packages #7395

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

Merged
merged 34 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6451c4b
wip
cometkim Apr 14, 2025
22e361d
per-platform packages
cometkim Apr 14, 2025
dda6eae
fix gentype makefile
cometkim Apr 15, 2025
3458e98
change binary package exports
cometkim Apr 16, 2025
4762a8c
use yarn pack
cometkim Apr 16, 2025
25571d7
upload platform artifacts
cometkim Apr 16, 2025
dc2288b
fix format
cometkim Apr 16, 2025
5f1886d
fix flag
cometkim Apr 16, 2025
7f6526d
suppress warnings from biome
cometkim Apr 16, 2025
8c4d743
expose bsb_helper path
cometkim Apr 16, 2025
821d418
compute realpath of binaries as needed
cometkim Apr 16, 2025
38bfc2d
reduce lstats in tests
cometkim Apr 16, 2025
f2028c0
exclude unintended path from packages
cometkim Apr 16, 2025
73435ef
fix package script
cometkim Apr 16, 2025
51d815a
fix installation test
cometkim Apr 16, 2025
27c6e67
add typescript declarations
cometkim Apr 16, 2025
44f132a
tmp: search stdlib
cometkim Apr 17, 2025
8b1468d
sync versions
cometkim Apr 17, 2025
1dd4706
gotcha
cometkim Apr 17, 2025
e76f956
a bit safer
cometkim Apr 17, 2025
3e628f2
it shound't be symlinks
cometkim Apr 17, 2025
934fe83
Overlapped bin entries is not compatibile with the mult-arch config
cometkim Apr 17, 2025
cdae7dc
workaround for executable permission
cometkim Apr 17, 2025
fc41236
actually not needed
cometkim Apr 17, 2025
367d899
update lockfile
cometkim Apr 17, 2025
d9e5259
handle path correctly
cometkim Apr 17, 2025
e915fa0
remove symlinks
cometkim Apr 24, 2025
ddd18af
fix
cometkim Apr 24, 2025
a6fdc01
use workspace protocol, less burden
cometkim Apr 24, 2025
fd92bc5
make ninja task recoverable without rebuild
cometkim Apr 24, 2025
496611a
refactor using readline
cometkim Apr 25, 2025
d566a6f
add changelog
cometkim Apr 30, 2025
0be8f48
add note about resolutions override for testing
cometkim Apr 30, 2025
b93bdaf
Update CHANGELOG.md
cometkim Apr 30, 2025
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
102 changes: 58 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ jobs:
include:
- os: macos-13 # x64
rust-target: x86_64-apple-darwin
node-target: darwin-x64
- os: macos-14 # ARM
rust-target: aarch64-apple-darwin
node-target: darwin-arm64
- os: ubuntu-24.04 # x64
rust-target: x86_64-unknown-linux-musl
node-target: linux-x64
- os: ubuntu-24.04-arm # ARM
rust-target: aarch64-unknown-linux-musl
node-target: linux-arm64
- os: windows-latest
rust-target: x86_64-pc-windows-gnu
node-target: win32-x64

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

Expand Down Expand Up @@ -66,25 +71,24 @@ jobs:
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{matrix.rust-target}}
targets: ${{ matrix.rust-target }}

- name: Build rewatch
if: steps.build-cache.outputs.cache-hit != 'true'
run: cargo build --manifest-path rewatch/Cargo.toml --target ${{matrix.rust-target}} --release

- name: Copy rewatch exe to platform bin dir
run: |
cp rewatch/target/${{matrix.rust-target}}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch
node ./scripts/copyExes.js -rewatch
cargo build --manifest-path rewatch/Cargo.toml --target ${{ matrix.rust-target }} --release

- name: Get artifact dir name
run: node .github/workflows/get_artifact_dir_name.js
- name: Copy rewatch binary
run: |
cp rewatch/target/${{ matrix.rust-target }}/release/rewatch${{ runner.os == 'Windows' && '.exe' || '' }} rewatch.exe
shell: bash

- name: "Upload artifact: rewatch binary"
uses: actions/upload-artifact@v4
with:
name: rewatch-${{env.artifact_dir_name}}
path: ${{ env.artifact_dir_name }}
name: rewatch-${{ matrix.node-target }}
path: rewatch.exe
if-no-files-found: error

build-compiler:
strategy:
Expand All @@ -95,21 +99,26 @@ jobs:
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
upload_binaries: true
upload_libs: true
node-target: linux-x64
- os: ubuntu-24.04-arm # ARM
ocaml_compiler: ocaml-variants.5.3.0+options,ocaml-option-static
upload_binaries: true
# Build the playground compiler and run the benchmarks on the fastest runner
build_playground: true
benchmarks: true
node-target: linux-arm64
- os: macos-13 # x64
ocaml_compiler: 5.3.0
upload_binaries: true
node-target: darwin-x64
- os: macos-14 # ARM
ocaml_compiler: 5.3.0
upload_binaries: true
node-target: darwin-arm64
- os: windows-latest
ocaml_compiler: 5.3.0
upload_binaries: true
node-target: win32-x64

# Verify that the compiler still builds with older OCaml versions
- os: ubuntu-24.04
Expand Down Expand Up @@ -144,9 +153,6 @@ jobs:
cache: yarn
node-version-file: .nvmrc

- name: Get artifact dir name
run: node .github/workflows/get_artifact_dir_name.js

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
uses: awalsh128/[email protected]
Expand Down Expand Up @@ -303,13 +309,13 @@ jobs:
run: yarn install

- name: Copy compiler exes to platform bin dir
run: node ./scripts/copyExes.js -compiler
run: node scripts/copyExes.js --compiler

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

- name: Setup Python for ninja build
Expand All @@ -336,7 +342,7 @@ jobs:

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

- name: "Syntax: Run roundtrip tests"
if: ${{ runner.os != 'Windows' }}
Expand Down Expand Up @@ -423,8 +429,8 @@ jobs:
if: matrix.upload_binaries
uses: actions/upload-artifact@v4
with:
name: binaries-${{ env.artifact_dir_name }}
path: ${{ env.artifact_dir_name }}
name: binaries-${{ matrix.node-target }}
path: packages/@rescript/${{ matrix.node-target }}/bin

- name: "Upload artifacts: lib/ocaml"
if: matrix.upload_libs
Expand All @@ -438,7 +444,7 @@ jobs:
- build-compiler
- build-rewatch

runs-on: ubuntu-24.04
runs-on: ubuntu-24.04-arm

steps:
- name: Checkout
Expand All @@ -447,29 +453,22 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
cache: yarn
node-version-file: .nvmrc

- name: NPM install
run: yarn install

- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: "@(binaries-*|rewatch-*|lib-ocaml)"

- name: Move artifacts
run: ./scripts/moveArtifacts.sh
- name: Move artifacts into packages
run: .github/workflows/moveArtifacts.sh
shell: bash

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

- name: Copy JS files to stdlib package
run: mkdir -p packages/std/lib && cp -R lib/es6 lib/js packages/std/lib

- name: npm pack (@rescript/std)
run: npm pack
working-directory: packages/std
- name: yarn pack @rescript/* subpackages
run: yarn workspaces foreach -W --no-private --exclude rescript pack

- name: Prepare package upload
# For pull requests, pass the correct commit SHA explicitly as GITHUB_SHA points to the wrong commit.
Expand All @@ -482,6 +481,11 @@ jobs:
path: |
rescript-${{ env.rescript_version }}.tgz
rescript-std-${{ env.rescript_version }}.tgz
rescript-linux-x64-${{ env.rescript_version }}.tgz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use GitHub's package registry for nightly builds

rescript-linux-arm64-${{ env.rescript_version }}.tgz
rescript-darwin-x64-${{ env.rescript_version }}.tgz
rescript-darwin-arm64-${{ env.rescript_version }}.tgz
rescript-win32-x64-${{ env.rescript_version }}.tgz

outputs:
rescript_version: ${{ env.rescript_version }}
Expand All @@ -491,15 +495,19 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [
macos-13, # x64
macos-14, # ARM
ubuntu-24.04,
ubuntu-24.04-arm,
windows-latest,
]
include:
- os: macos-13
node-target: darwin-x64
- os: macos-14
node-target: darwin-arm64
- os: ubuntu-24.04
node-target: linux-x64
- os: ubuntu-24.04-arm
node-target: linux-arm64
- os: windows-latest
node-target: win32-x64

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

steps:
- name: Checkout
Expand Down Expand Up @@ -532,7 +540,8 @@ jobs:
- name: Install ReScript package
run: |
npm i --ignore-scripts --no-audit \
rescript-${{ needs.package.outputs.rescript_version }}.tgz
rescript-${{ needs.package.outputs.rescript_version }}.tgz \
rescript-${{ matrix.node-target }}-${{ needs.package.outputs.rescript_version }}.tgz
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}

Expand All @@ -546,7 +555,7 @@ jobs:

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

runs-on: ubuntu-24.04
runs-on: ubuntu-24.04-arm

steps:
- name: Checkout
Expand All @@ -568,8 +577,13 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
run: |
npm publish rescript-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
npm publish rescript-std-${{ needs.package.outputs.rescript_version }}.tgz --tag ci
npm publish --tag ci rescript-${{ needs.package.outputs.rescript_version }}.tgz
npm publish --tag ci rescript-std-${{ needs.package.outputs.rescript_version }}.tgz
npm publish --tag ci rescript-linux-x64-${{ needs.package.outputs.rescript_version }}.tgz
npm publish --tag ci rescript-linux-arm64-${{ needs.package.outputs.rescript_version }}.tgz
npm publish --tag ci rescript-darwin-x64-${{ needs.package.outputs.rescript_version }}.tgz
npm publish --tag ci rescript-darwin-arm64-{{ needs.package.outputs.rescript_version }}.tgz
npm publish --tag ci rescript-win32-x64-${{ needs.package.outputs.rescript_version }}.tgz

- name: Update Website Playground
env:
Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/get_artifact_dir_name.js

This file was deleted.

30 changes: 16 additions & 14 deletions scripts/moveArtifacts.sh → .github/workflows/moveArtifacts.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env bash

set -e

check_statically_linked() {
Expand All @@ -24,18 +25,19 @@ check_statically_linked() {
fi
}

chmod +x binaries-*/*.exe rewatch-*/*.exe

mkdir darwin darwinarm64 linux linuxarm64 win32

mv binaries-darwin/* rewatch-darwin/* darwin
mv binaries-darwinarm64/* rewatch-darwinarm64/* darwinarm64
mv binaries-linux/* rewatch-linux/* linux
mv binaries-linuxarm64/* rewatch-linuxarm64/* linuxarm64
mv binaries-win32/* rewatch-win32/* win32

# rescript
mv lib-ocaml lib/ocaml
mv ninja/COPYING ninja.COPYING

check_statically_linked "linux"
check_statically_linked "linuxarm64"
# @rescript/{target}
chmod +x binaries-*/*.exe rewatch-*/*.exe
mv -f binaries-darwin-x64/* rewatch-darwin-x64/* "packages/@rescript/darwin-x64/bin"
mv -f binaries-darwin-arm64/* rewatch-darwin-arm64/* "packages/@rescript/darwin-arm64/bin"
mv -f binaries-linux-x64/* rewatch-linux-x64/* "packages/@rescript/linux-x64/bin"
mv -f binaries-linux-arm64/* rewatch-linux-arm64/* "packages/@rescript/linux-arm64/bin"
mv -f binaries-win32-x64/* rewatch-win32-x64/* "packages/@rescript/win32-x64/bin"
check_statically_linked "packages/@rescript/linux-x64/bin"
check_statically_linked "packages/@rescript/linux-arm64/bin"

# @rescript/std
mkdir -p packages/std/lib
cp -R lib/es6 lib/js packages/std/lib
32 changes: 27 additions & 5 deletions .github/workflows/prepare_package_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,43 @@ import * as fs from "node:fs";
import * as os from "node:os";

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

const { version } = packageSpec;

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

// rescript
fs.renameSync("package.tgz", `rescript-${version}-${commitHashShort}.tgz`);

// @rescript/std
fs.renameSync(
"packages/std/package.tgz",
`rescript-std-${version}-${commitHashShort}.tgz`,
);

// @rescript/{target}
fs.renameSync(
`rescript-${version}.tgz`,
`rescript-${version}-${commitHashShort}.tgz`,
"packages/@rescript/linux-x64/package.tgz",
`rescript-linux-x64-${version}-${commitHashShort}.tgz`,
);
fs.renameSync(
`packages/std/rescript-std-${version}.tgz`,
`rescript-std-${version}-${commitHashShort}.tgz`,
"packages/@rescript/linux-arm64/package.tgz",
`rescript-linux-arm64-${version}-${commitHashShort}.tgz`,
);
fs.renameSync(
"packages/@rescript/darwin-x64/package.tgz",
`rescript-darwin-x64-${version}-${commitHashShort}.tgz`,
);
fs.renameSync(
"packages/@rescript/darwin-arm64/package.tgz",
`rescript-darwin-arm64-${version}-${commitHashShort}.tgz`,
);
fs.renameSync(
"packages/@rescript/win32-x64/package.tgz",
`rescript-win32-x64-${version}-${commitHashShort}.tgz`,
);

// Pass information to subsequent GitHub actions
Expand Down
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ _build
node_modules
*.dump
coverage
*.exe

.ninja_log
.bsdeps
Expand Down Expand Up @@ -82,6 +81,12 @@ tests/tools_tests/lib
tests/analysis_tests*/lib
tests/analysis_tests/**/*.bs.js

/linux/*.exe
/linuxarm64/*.exe
/darwin/*.exe
/darwinarm64/*.exe
/win32/*.exe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to add these if we ignore all *.exe (further below)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused lines, I will remove


.yarn/*
!.yarn/patches
!.yarn/plugins
Expand All @@ -90,3 +95,7 @@ tests/analysis_tests/**/*.bs.js
!.yarn/versions

*.tsbuildinfo

# package tarballs
package.tgz
*.exe
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :rocket: New Feature

- Add shift (`<<`, `>>`, `>>>`) operators for `int` and `bigint`. https://github.com/rescript-lang/rescript/pull/7183
- 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

#### :bug: Bug fix

Expand Down
Loading