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

Open
wants to merge 26 commits into
base: master
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
60 changes: 34 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ jobs:
- build-compiler
- build-rewatch

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

steps:
- name: Checkout
Expand All @@ -447,29 +447,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 +475,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 +489,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
target: darwin-x64
- os: macos-14
target: darwin-arm64
- os: ubuntu-24.04
target: linux-x64
- os: ubuntu-24.04-arm
target: linux-arm64
- os: windows-latest
target: win32-x64

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

steps:
- name: Checkout
Expand Down Expand Up @@ -532,7 +534,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.target }}-${{ needs.package.outputs.rescript_version }}.tgz
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}

Expand All @@ -546,7 +549,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 +571,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
2 changes: 1 addition & 1 deletion .github/workflows/get_artifact_dir_name.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from "node:fs";
import * as os from "node:os";

import { platformName } from "#cli/bins";
import { platformName } from "#dev/paths";

// Pass artifactDirName to subsequent GitHub actions
fs.appendFileSync(
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/moveArtifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

set -e

check_statically_linked() {
local dir=$1
local all_statically_linked=true

for file in "$dir"/*; do
if [ -f "$file" ]; then
if file "$file" | grep -Eq "statically linked|static-pie linked"; then
echo "$file is statically linked."
else
echo "$file is NOT statically linked."
all_statically_linked=false
fi
fi
done

if $all_statically_linked; then
echo "All files in $dir are statically linked executables."
else
echo "Error: Not all files in $dir are statically linked executables."
exit 1
fi
}

clean_dir() {
local dir="$1"
rm -rf "$dir" && mkdir -p "$dir"
echo -n "$dir"
}

# rescript
mv lib-ocaml lib/ocaml

# @rescript/{target}
chmod +x binaries-*/*.exe rewatch-*/*.exe
mv -f binaries-darwin/* rewatch-darwin/* "$(clean_dir "packages/@rescript/darwin-x64/bin")"
mv -f binaries-darwinarm64/* rewatch-darwinarm64/* "$(clean_dir "packages/@rescript/darwin-arm64/bin")"
mv -f binaries-linux/* rewatch-linux/* "$(clean_dir "packages/@rescript/linux-x64/bin")"
mv -f binaries-linuxarm64/* rewatch-linuxarm64/* "$(clean_dir "packages/@rescript/linux-arm64/bin")"
mv -f binaries-win32/* rewatch-win32/* "$(clean_dir "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
10 changes: 9 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

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

*.tsbuildinfo

# package tarballs
package.tgz
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ lib:
./scripts/prebuilt.js

artifacts: lib
./scripts/npmPack.js -updateArtifactList
./scripts/npmPack.js --updateArtifactList

# Builds the core playground bundle (without the relevant cmijs files for the runtime)
playground:
Expand Down
3 changes: 2 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@
"lib/es6/**",
"lib/js/**",
"ninja/**",
"packages/**",
"playground/**",
"*.bs.js",
"*.res.js",
"*.res.mjs",
"*.gen.ts*",
"*.d.ts",
"*.exe",
"package.json"
]
}
Expand Down
18 changes: 9 additions & 9 deletions cli/bstracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// @ts-check

import * as fs from "node:fs";
import * as readline from "node:readline";
import * as path from "node:path";
import * as readline from "node:readline";

/**
*
Expand All @@ -14,10 +14,10 @@ import * as path from "node:path";
*/
function processEntry(file, lineCb, finish) {
const input = fs.createReadStream(file);
input.on("error", (error) => {
input.on("error", error => {
console.error(error.message);
console.error(
"make sure you are running after bsb building and in the top directory"
"make sure you are running after bsb building and in the top directory",
);
process.exit(2);
});
Expand Down Expand Up @@ -156,7 +156,7 @@ function category(target, obj) {
} else {
getColorName(obj, "cmj");
}
obj.name = target.targets.map((x) => path.parse(x).base).join(",");
obj.name = target.targets.map(x => path.parse(x).base).join(",");
return obj;
}
/**
Expand All @@ -173,7 +173,7 @@ function readIntervals(file, showAll, outputFile) {
let offset = 0;
processEntry(
file,
(line) => {
line => {
const lineTrim = line.trim();
if (lineTrim.startsWith("#")) {
return;
Expand All @@ -195,7 +195,7 @@ function readIntervals(file, showAll, outputFile) {
setDefault(
targets,
cmdHash,
new Interval(Number(start) + offset, Number(end) + offset)
new Interval(Number(start) + offset, Number(end) + offset),
).targets.push(name);
},
() => {
Expand All @@ -213,12 +213,12 @@ function readIntervals(file, showAll, outputFile) {
ts: target.start * 1000,
tid: threads.alloc(target),
args: {},
})
}),
);
}
console.log(` ${outputFile} is produced, loade it via chrome://tracing/`);
fs.writeFileSync(outputFile, JSON.stringify(jsonArray), "utf8");
}
},
);
}
const logName = ".ninja_log";
Expand All @@ -240,7 +240,7 @@ function tryLocation(ps) {
}
}
console.error(
"no .ninja_log found in specified paths, make sure you set bstracing to the proper directory"
"no .ninja_log found in specified paths, make sure you set bstracing to the proper directory",
);
process.exit(2);
}
Expand Down
Loading