Skip to content

Make rewatch the default build system / cli #7593

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 17 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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,12 @@ jobs:

- name: Build runtime/stdlib with rewatch
if: ${{ runner.os != 'Windows' }}
run: ./scripts/buildRuntimeRewatch.sh
run: ./scripts/buildRuntime.sh
shell: bash

- name: Build runtime/stdlib with bsb (Windows)
if: ${{ runner.os == 'Windows' }}
run: ./scripts/buildRuntime.sh
run: ./scripts/buildRuntimeLegacy.sh
shell: bash

- name: Check for changes in lib folder
Expand Down Expand Up @@ -510,7 +510,7 @@ jobs:
- name: Build website
if: steps.diffcheck.outputs.clean == 'false'
run: |
npm ci
npm ci
npm run build
- name: Commit and push
Expand Down Expand Up @@ -569,7 +569,7 @@ jobs:
working-directory: ${{ steps.tmp-dir.outputs.path }}

- name: Test installation
run: npx rescript -h && npx rescript build && cat src/Test.res.js
run: npx rescript -h && npx rescript legacy build && cat src/Test.res.js
shell: bash
working-directory: ${{ steps.tmp-dir.outputs.path }}

Expand All @@ -581,7 +581,7 @@ jobs:
working-directory: rewatch/testrepo

- name: Run rewatch integration tests
run: ./rewatch/tests/suite-ci.sh node_modules/.bin/rewatch
run: ./rewatch/tests/suite-ci.sh node_modules/.bin/rescript
shell: bash

publish:
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

#### :boom: Breaking Change

- The legacy rescript cli can be called through rewatch via `rewatch legacy`. Arguments to rewatch need to be passed after the subcommand. Argument `--compiler-args` is now a subcommand `compiler-args`. https://github.com/rescript-lang/rescript/pull/7551
- New `rewatch` based build system. https://github.com/rescript-lang/rescript/pull/7551 https://github.com/rescript-lang/rescript/pull/7593
- The new `rewatch` based build system is now the default and is exposed through the `rescript` command. The `rewatch` command has been removed.
- The previous Ninja-based build system is now available via the `rescript legacy` subcommand.
- Argument `--compiler-args` is now a subcommand `compiler-args`.
- Remove `String.getSymbol` from standard library. https://github.com/rescript-lang/rescript/pull/7571
- Remove `String.getSymbolUnsafe` from standard library. https://github.com/rescript-lang/rescript/pull/7571
- Remove `String.setSymbol` from standard library. https://github.com/rescript-lang/rescript/pull/7571
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dce:

rewatch:
cargo build --manifest-path rewatch/Cargo.toml --release
cp rewatch/target/release/rewatch rewatch
./scripts/copyExes.js --rewatch

ninja/ninja:
Expand Down Expand Up @@ -53,10 +52,10 @@ reanalyze:
reanalyze.exe -set-exit-code -all-cmt _build/default/compiler _build/default/tests -exclude-paths compiler/outcome_printer,compiler/ml,compiler/frontend,compiler/ext,compiler/depends,compiler/core,compiler/common,compiler/cmij,compiler/bsb_helper,compiler/bsb

lib-bsb:
./scripts/buildRuntime.sh
./scripts/buildRuntimeLegacy.sh

lib:
./scripts/buildRuntimeRewatch.sh
./scripts/buildRuntime.sh

artifacts: lib
./scripts/npmPack.js --updateArtifactList
Expand Down
2 changes: 1 addition & 1 deletion analysis/examples/example-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"scripts": {
"build": "rescript",
"start": "rescript build -w",
"clean": "rescript clean -with-deps"
"clean": "rescript clean"
}
}
2 changes: 1 addition & 1 deletion analysis/examples/larger-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "rescript build -w",
"build": "rescript build",
"clean": "rescript clean -with-deps"
"clean": "rescript clean"
},
"devDependencies": {
"react": "^16.13.1",
Expand Down
2 changes: 1 addition & 1 deletion cli/common/bins.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const {
ninja_exe,
rescript_editor_analysis_exe,
rescript_tools_exe,
rescript_legacy_exe,
rescript_exe,
rewatch_exe,
},
} = mod;
4 changes: 2 additions & 2 deletions cli/common/bsb.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as os from "node:os";
import * as path from "node:path";
import { WebSocket } from "#lib/minisocket";

import { rescript_exe } from "./bins.js";
import { rescript_legacy_exe } from "./bins.js";

const cwd = process.cwd();
const lockFileName = path.join(cwd, ".bsb.lock");
Expand Down Expand Up @@ -50,7 +50,7 @@ function acquireBuild(args, options) {
return null;
}
try {
ownerProcess = child_process.spawn(rescript_exe, args, {
ownerProcess = child_process.spawn(rescript_legacy_exe, args, {
stdio: "inherit",
...options,
});
Expand Down
135 changes: 135 additions & 0 deletions cli/rescript-legacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/usr/bin/env node

// @ts-check

// This script is supposed to be running in project root directory
// It matters since we need read .sourcedirs(location)
// and its content are file/directories with regard to project root

import * as fs from "node:fs";
import * as tty from "node:tty";

import { bsc_exe, rescript_legacy_exe } from "./common/bins.js";
import * as bsb from "./common/bsb.js";

const cwd = process.cwd();
process.env.BSB_PROJECT_ROOT = cwd;

if (process.env.FORCE_COLOR === undefined) {
if (tty.isatty(1)) {
process.env.FORCE_COLOR = "1";
process.env.NINJA_ANSI_FORCED = "1";
}
} else {
if (
process.env.FORCE_COLOR === "1" &&
process.env.NINJA_ANSI_FORCED === undefined
) {
process.env.NINJA_ANSI_FORCED = "1";
}
if (process.argv.includes("-verbose")) {
console.log(`FORCE_COLOR: "${process.env.FORCE_COLOR}"`);
}
}

const helpMessage = `Usage: rescript <options> <subcommand>
\`rescript\` is equivalent to \`rescript build\`
Options:
-v, -version display version number
-h, -help display help
Subcommands:
build
clean
format
dump
help
Run \`rescript <subcommand> -h\` for subcommand help. Examples:
rescript build -h
rescript format -h`;

function onUncaughtException(err) {
console.error("Uncaught Exception", err);
bsb.releaseBuild();
process.exit(1);
}

function exitProcess() {
bsb.releaseBuild();
process.exit(0);
}

process.on("uncaughtException", onUncaughtException);

// OS signal handlers
// Ctrl+C
process.on("SIGINT", exitProcess);
// kill pid
try {
process.on("SIGUSR1", exitProcess);
process.on("SIGUSR2", exitProcess);
process.on("SIGTERM", exitProcess);
process.on("SIGHUP", exitProcess);
} catch (_e) {
// Deno might throw an error here, see https://github.com/denoland/deno/issues/9995
// TypeError: Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK).
}

const args = process.argv.slice(2);
const argPatterns = {
help: ["help", "-h", "-help", "--help"],
version: ["version", "-v", "-version", "--version"],
};

const helpArgIndex = args.findIndex(arg => argPatterns.help.includes(arg));
const firstPositionalArgIndex = args.findIndex(arg => !arg.startsWith("-"));

if (
helpArgIndex !== -1 &&
(firstPositionalArgIndex === -1 || helpArgIndex <= firstPositionalArgIndex)
) {
console.log(helpMessage);
} else if (argPatterns.version.includes(args[0])) {
const packageSpec = JSON.parse(
fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8"),
);

console.log(packageSpec.version);
} else if (firstPositionalArgIndex !== -1) {
const subcmd = args[firstPositionalArgIndex];
const subcmdArgs = args.slice(firstPositionalArgIndex + 1);

switch (subcmd) {
case "info": {
bsb.info(subcmdArgs);
break;
}
case "clean": {
bsb.clean(subcmdArgs);
break;
}
case "build": {
bsb.build(subcmdArgs);
break;
}
case "format": {
const mod = await import("./rescript-legacy/format.js");
await mod.main(subcmdArgs, rescript_legacy_exe, bsc_exe);
break;
}
case "dump": {
const mod = await import("./rescript-legacy/dump.js");
mod.main(subcmdArgs, rescript_legacy_exe, bsc_exe);
break;
}
default: {
console.error(`Error: Unknown command "${subcmd}".\n${helpMessage}`);
process.exit(2);
}
}
} else {
bsb.build(args);
}
14 changes: 9 additions & 5 deletions cli/rescript/dump.js → cli/rescript-legacy/dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const specs = [];

/**
* @param {string[]} argv
* @param {string} rescript_exe
* @param {string} rescript_legacy_exe
* @param {string} bsc_exe
*/
export function main(argv, rescript_exe, bsc_exe) {
export function main(argv, rescript_legacy_exe, bsc_exe) {
let target;
arg.parse_exn(dump_usage, argv, specs, xs => {
if (xs.length !== 1) {
Expand All @@ -34,9 +34,13 @@ export function main(argv, rescript_exe, bsc_exe) {
process.exit(2);
}

let output = child_process.spawnSync(rescript_exe, ["build", "--", target], {
encoding: "utf-8",
});
let output = child_process.spawnSync(
rescript_legacy_exe,
["build", "--", target],
{
encoding: "utf-8",
},
);
if (output.status !== 0) {
console.log(output.stdout);
console.error(output.stderr);
Expand Down
6 changes: 3 additions & 3 deletions cli/rescript/format.js → cli/rescript-legacy/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) {

/**
* @param {string[]} argv
* @param {string} rescript_exe
* @param {string} rescript_legacy_exe
* @param {string} bsc_exe
*/
export async function main(argv, rescript_exe, bsc_exe) {
export async function main(argv, rescript_legacy_exe, bsc_exe) {
const isSupportedFile = hasExtension(formattedFileExtensions);
const isSupportedStd = hasExtension(formattedStdExtensions);

Expand Down Expand Up @@ -179,7 +179,7 @@ export async function main(argv, rescript_exe, bsc_exe) {
// -all
// TODO: check the rest arguments
const output = child_process.spawnSync(
rescript_exe,
rescript_legacy_exe,
["info", "-list-files"],
{
encoding: "utf-8",
Expand Down
Loading