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 1 commit
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
Prev Previous commit
Next Next commit
use yarn pack
  • Loading branch information
cometkim committed Apr 30, 2025
commit 4762a8c5a42af2935a4be6f19b19cc33ee0748ab
5 changes: 0 additions & 5 deletions lib/.npmignore

This file was deleted.

9 changes: 9 additions & 0 deletions lib_dev/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ export const compilerVersionFile = path.resolve(
"bs_version.ml",
);

/**
* path: `<projectDir>/packages/artifacts.txt`
*/
export const artifactListFile = path.resolve(
projectDir,
"packages",
"artifacts.txt",
);

/**
* path: `<projectDir>/_build/install/default/bin/`
*/
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@
},
"files": [
"CHANGELOG.md",
"COPYING",
"COPYING.LESSER",
"CREDITS.md",
"ninja.COPYING",
"docs/docson/build-schema.json",
"lib/js/*.js",
"lib/es6/*.js",
"lib",
"cli"
],
"exports": {
Expand Down
37 changes: 1 addition & 36 deletions packages/artifacts.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ cli/rescript.js
cli/rescript/dump.js
cli/rescript/format.js
cli/rewatch.js
darwin/bsb_helper.exe
darwin/bsc.exe
darwin/ninja.exe
darwin/rescript-editor-analysis.exe
darwin/rescript-tools.exe
darwin/rescript.exe
darwin/rewatch.exe
darwinarm64/bsb_helper.exe
darwinarm64/bsc.exe
darwinarm64/ninja.exe
darwinarm64/rescript-editor-analysis.exe
darwinarm64/rescript-tools.exe
darwinarm64/rescript.exe
darwinarm64/rewatch.exe
docs/docson/build-schema.json
lib/es6/Belt.js
lib/es6/Belt_Array.js
Expand Down Expand Up @@ -1227,26 +1213,5 @@ lib/ocaml/Stdlib_WeakSet.cmi
lib/ocaml/Stdlib_WeakSet.cmj
lib/ocaml/Stdlib_WeakSet.cmt
lib/ocaml/Stdlib_WeakSet.res
linux/bsb_helper.exe
linux/bsc.exe
linux/ninja.exe
linux/rescript-editor-analysis.exe
linux/rescript-tools.exe
linux/rescript.exe
linux/rewatch.exe
linuxarm64/bsb_helper.exe
linuxarm64/bsc.exe
linuxarm64/ninja.exe
linuxarm64/rescript-editor-analysis.exe
linuxarm64/rescript-tools.exe
linuxarm64/rescript.exe
linuxarm64/rewatch.exe
ninja.COPYING
ninja/COPYING
package.json
win32/bsb_helper.exe
win32/bsc.exe
win32/ninja.exe
win32/rescript-editor-analysis.exe
win32/rescript-tools.exe
win32/rescript.exe
win32/rewatch.exe
131 changes: 61 additions & 70 deletions scripts/npmPack.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,80 @@

// @ts-check

// NOTE:
// We cannot use `yarn pack` since we need to set our OCaml binaries executable.
// Yarn (Berry) only allow `bin` to be executable, wouldn't preserve permission bits.

// This performs `npm pack` and retrieves the list of artifact files from the output.
// This performs `yarn pack` and retrieves the list of artifact files from the output.
//
// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `npm pack`
// In local dev, invoke it with `-updateArtifactList` to perform a dry run of `yarn pack`
// and recreate `packages/artifacts.txt`.
// The exes for all platforms will then be included in the list, even if not present locally.
//
// In CI, the scripts is invoked without options. It then performs `npm pack` for real,
// In CI, the scripts is invoked without options. It then performs `yarn pack` for real,
// recreates the artifact list and verifies that it has no changes compared to the committed state.

/**
* @typedef {{
* path: string,
* size: number,
* mode: number,
* }} PackOutputFile
*
* @typedef {{
* files: PackOutputFile[],
* entryCount: number,
* bundled: unknown[],
* }} PackOutputEntry
*
* @typedef {[PackOutputEntry]} PackOutput
import { spawn, execSync } from "node:child_process";
import fs from "node:fs";
import { parseArgs } from "node:util";
import { artifactListFile } from "#dev/paths";

/**
* @typedef {(
* | { "base": string }
* | { "location": string }
* | { "output": string }
* )} YarnPackOutputLine
*/

import { execSync, spawnSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import { projectDir } from "#dev/paths";
const { values } = parseArgs({
args: process.argv.slice(2),
options: {
updateArtifactList: {
type: "boolean",
short: "u",
},
},
});

const mode = process.argv.includes("-updateArtifactList")
const mode = values.updateArtifactList
? "updateArtifactList"
: "package";

const fileListPath = path.join(projectDir, "packages", "artifacts.txt");

const output = spawnSync(
`npm pack --json${mode === "updateArtifactList" ? " --dry-run" : ""}`,
{
cwd: projectDir,
encoding: "utf8",
shell: true,
},
).stdout;

/** @type {PackOutput} */
const parsedOutput = JSON.parse(output);
let filePaths = parsedOutput[0].files.map(file => file.path);

if (mode === "updateArtifactList") {
filePaths = Array.from(new Set(filePaths.concat(getFilesAddedByCI())));
const child = spawn(
"yarn",
[
"workspace",
"rescript",
"pack",
"--json",
mode === "updateArtifactList" ? "--dry-run" : "",
].filter(Boolean),
);
const exitCode = new Promise((resolve, reject) => {
child.once("error", reject);
child.once("close", code => resolve(code));
});

fs.unlinkSync(artifactListFile);

for await (const chunk of child.stdout.setEncoding("utf8")) {
const lines = /** @type {string} */ (chunk).trim().split(/\s/);
for (const line of lines) {
/** @type {YarnPackOutputLine} */
const json = JSON.parse(line);
if ("location" in json) {
// Workaround for false positive reports
// See https://github.com/yarnpkg/berry/issues/6766
if (json.location.startsWith("_build")) {
continue;
}
fs.appendFileSync(
artifactListFile,
json.location + "\n",
"utf8",
);
}
}
}

filePaths.sort();
fs.writeFileSync(fileListPath, filePaths.join("\n"));
await exitCode;

if (mode === "package") {
execSync(`git diff --exit-code ${fileListPath}`, { stdio: "inherit" });
}

function getFilesAddedByCI() {
const platforms = ["darwin", "darwinarm64", "linux", "linuxarm64", "win32"];
const exes = [
"bsb_helper.exe",
"bsc.exe",
"ninja.exe",
"rescript.exe",
"rescript-editor-analysis.exe",
"rescript-tools.exe",
"rewatch.exe",
];

const files = ["ninja.COPYING"];

for (const platform of platforms) {
for (const exe of exes) {
files.push(`${platform}/${exe}`);
}
}

return files;
execSync(`git diff --exit-code ${artifactListFile}`, { stdio: "inherit" });
}
86 changes: 0 additions & 86 deletions tools/CHANGELOG.md

This file was deleted.