Skip to content

Commit e10d612

Browse files
ospencerphated
andauthored
feat!: Remove js-runner (#1585)
* feat!: Remove js-runner * Implement wasi runner via execSync, call it grainrun * Also move the v8 flag * passthrough exit code * Update workflow step names * provide wasm file as first argv * gracefully show errors during grainrun * Remove remaining js-runner references * Update issue number * Fix missed preopens in merge * Passthrough argv after -- and add to test harness * Remove MTracepoint * Fix test arg * Regenerate lockfile * add hack for fdPrestatGet * Remove argv pass-through stuff from this PR * update timing tests * Update cli/bin/grain.js * move comment because formatter is BROKE --------- Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
1 parent 686de7e commit e10d612

40 files changed

+225
-6915
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ setup.data
3636
setup.ml
3737
myocamlbuild.ml
3838
.merlin
39-
js-runner/dist
4039
/*.gr
4140
_esy/
4241
**/_esy/

.github/CODEOWNERS

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@
5050
/compiler/esy.json @ospencer @phated
5151
/compiler/package.json @ospencer @phated
5252

53-
/js-runner/.prettierignore @ospencer @phated
54-
/js-runner/.prettierrc.json @ospencer @phated
55-
/js-runner/README.md @ospencer @phated
56-
/js-runner/src/ @ospencer @phated @peblair
57-
/js-runner/package.json @ospencer @phated
58-
/js-runner/webpack.*.js @ospencer @phated
59-
/js-runner/LICENSE @ospencer @peblair
60-
6153
/stdlib/ @ospencer @phated @peblair @marcusroberts @jozanza
6254
/stdlib/runtime/ @ospencer @peblair @jozanza @phated
6355
/stdlib/package.json @phated @ospencer

.github/workflows/build-native.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ jobs:
9696
run: |
9797
npm run compiler check-format
9898
99-
- name: (js-runner) Check formatting
100-
if: inputs.os != 'windows-latest'
101-
run: |
102-
npm run js-runner check-format
103-
10499
- name: (cli) Check formatting
105100
if: inputs.os != 'windows-latest'
106101
run: |

.github/workflows/release.yml

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
releases-created: ${{ steps.release.outputs.releases_created }}
1818
tag-name: ${{ steps.release.outputs.tag_name }}
1919
stdlib-tag-name: ${{ steps.release.outputs.stdlib--tag_name }}
20-
js-runner-tag-name: ${{ steps.release.outputs.js-runner--tag_name }}
2120
steps:
2221
- uses: GoogleCloudPlatform/release-please-action@v3.7.5
2322
id: release
@@ -87,7 +86,6 @@ jobs:
8786
runs-on: ubuntu-latest
8887
outputs:
8988
stdlib-download-url: ${{ steps.stdlib-upload.outputs.browser_download_url }}
90-
js-runner-download-url: ${{ steps.js-runner-upload.outputs.browser_download_url }}
9189
steps:
9290
- name: Checkout project
9391
uses: actions/checkout@v3
@@ -118,22 +116,6 @@ jobs:
118116
asset_name: stdlib.tgz
119117
tag: ${{ needs.release-please.outputs.stdlib-tag-name }}
120118

121-
- name: Pack js-runner
122-
working-directory: ./js-runner
123-
# Runs `npm pack` and assigns the filename to an env var we can use later
124-
# `sed` is used to workaround https://github.com/npm/cli/issues/3405
125-
run: |
126-
echo "RUNNER_TAR=$(npm pack --json | jq -r '.[0].filename' | sed -r 's/@//g' | sed -r 's/\//-/g')" >> $GITHUB_ENV
127-
128-
- name: Upload js-runner
129-
id: js-runner-upload
130-
uses: grain-lang/upload-release-action@v3.0.2
131-
with:
132-
token: ${{ secrets.GITHUB_TOKEN }}
133-
file: ./js-runner/${{ env.RUNNER_TAR }}
134-
asset_name: js-runner.tgz
135-
tag: ${{ needs.release-please.outputs.js-runner-tag-name }}
136-
137119
dispatch-website:
138120
needs: [release-please, upload-release]
139121
if: ${{ needs.release-please.outputs.releases-created }}
@@ -194,22 +176,3 @@ jobs:
194176
npm publish ${{ needs.upload-npm-artifacts.outputs.stdlib-download-url }}
195177
env:
196178
NODE_AUTH_TOKEN: ${{ secrets.NPM_RELEASE }}
197-
198-
npm-release-js-runner:
199-
needs: [release-please, upload-npm-artifacts]
200-
if: ${{ needs.release-please.outputs.releases-created }}
201-
name: Publish js-runner to npm registry
202-
runs-on: ubuntu-latest
203-
steps:
204-
- name: Setup NodeJS
205-
uses: actions/setup-node@v3.6.0
206-
with:
207-
node-version: ">=18.15"
208-
check-latest: true
209-
registry-url: "https://registry.npmjs.org"
210-
211-
- name: Publish to npm
212-
run: |
213-
npm publish ${{ needs.upload-npm-artifacts.outputs.js-runner-download-url }}
214-
env:
215-
NODE_AUTH_TOKEN: ${{ secrets.NPM_RELEASE }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ setup.data
2626
setup.ml
2727
myocamlbuild.ml
2828
.merlin
29-
js-runner/dist
3029
/*.gr
3130
_esy/
3231
pkg/

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{".":"0.5.13","cli":"0.5.13","compiler":"0.5.13","js-runner":"0.5.13","stdlib":"0.5.13"}
1+
{".":"0.5.13","cli":"0.5.13","compiler":"0.5.13","stdlib":"0.5.13"}

CONTRIBUTING.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,6 @@ npm run compiler test
3333

3434
It can sometimes be helpful to run small Grain programs directly to test some functionality without running the full test suite.
3535

36-
### JS runner
37-
38-
After making changes in the `js-runner` directory, run:
39-
40-
```bash
41-
npm run js-runner build
42-
npm run js-runner test
43-
```
44-
45-
Once the JS runner has been built, it's the only one active. Grain programs that you run from the command line or the tests will use that version.
46-
4736
### Standard library
4837

4938
It's usually easiest to create a small Grain program that imports your library to try it out, like so:

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ For instructions on how to build Grain from source, please consult the [official
3232

3333
### Other Commands
3434

35-
To build the JS runner:
36-
37-
```bash
38-
npm run js-runner build
39-
```
40-
4135
To link the CLI:
4236

4337
```bash

cli/bin/exec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,37 @@ function execGrainlsp(options, program, execOpts = { stdio: "inherit" }) {
114114
return execSync(`${grainlsp} ${flags.join(" ")}`, execOpts);
115115
}
116116

117+
function getGrainrun() {
118+
const node = process.execPath;
119+
const grainlsp_js = path.join(__dirname, "grainrun.js");
120+
return `"${node}" ${grainlsp_js}`;
121+
}
122+
123+
const grainrun = getGrainrun();
124+
125+
function execGrainrun(file, options, program, execOpts = { stdio: "inherit" }) {
126+
const preopens = {};
127+
options.dir?.forEach((preopen) => {
128+
const [guestDir, hostDir = guestDir] = preopen.split("=");
129+
preopens[guestDir] = hostDir;
130+
});
131+
132+
const env = {
133+
PREOPENS: JSON.stringify(preopens),
134+
NODE_OPTIONS: `--experimental-wasi-unstable-preview1 --no-warnings`,
135+
};
136+
137+
try {
138+
execSync(`${grainrun} ${file}`, { ...execOpts, env });
139+
} catch (e) {
140+
process.exit(e.status);
141+
}
142+
}
143+
117144
module.exports = {
118145
grainc: execGrainc,
119146
graindoc: execGraindoc,
120147
grainformat: execGrainformat,
121148
grainlsp: execGrainlsp,
149+
grainrun: execGrainrun,
122150
};

cli/bin/grain.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
#!/usr/bin/env node
22

3-
// https://github.com/grain-lang/grain/issues/114
4-
const v8 = require("v8");
5-
/* From the Node.js docs:
6-
*
7-
* The v8.setFlagsFromString() method can be used to programmatically set V8 command-line flags.
8-
* This method should be used with care. Changing settings after the VM has started may result
9-
* in unpredictable behavior, including crashes and data loss; or it may simply do nothing.
10-
*
11-
* This seems to work for our needs with Node 18, but we should be cautious when updating.
12-
*/
13-
v8.setFlagsFromString("--experimental-wasm-return-call");
14-
153
const commander = require("commander");
164
const exec = require("./exec.js");
17-
const run = require("./run.js");
185
const pkgJson = require("../package.json");
196

207
const stdlibPath = require("@grain/stdlib");
@@ -159,7 +146,6 @@ class GrainCommand extends commander.Command {
159146
"--use-start-section",
160147
"replaces the _start export with a start section during linking"
161148
);
162-
cmd.forwardOption("--no-link", "disable static linking");
163149
cmd.forwardOption(
164150
"--no-pervasives",
165151
"don't automatically import the Grain Pervasives module"
@@ -189,28 +175,27 @@ program
189175
.command("compile-and-run <file>", { isDefault: true, hidden: true })
190176
// `--version` should only be available on the default command
191177
.version(pkgJson.version, "-v, --version", "output the current version")
192-
.addOption(new commander.Option("-p, --print-output").hideHelp())
193178
.forwardOption("-o <filename>", "output filename")
194179
.action(function (file, options, program) {
195180
exec.grainc(file, options, program);
196181
if (options.o) {
197-
run(options.o, options);
182+
exec.grainrun(options.o, options, program);
198183
} else {
199-
run(file.replace(/\.gr$/, ".gr.wasm"), options);
184+
exec.grainrun(file.replace(/\.gr$/, ".gr.wasm"), options, program);
200185
}
201186
});
202187

203188
program
204189
.command("compile <file>")
205190
.description("compile a grain program into wasm")
206191
.forwardOption("-o <filename>", "output filename")
192+
.forwardOption("--no-link", "disable static linking")
207193
.action(exec.grainc);
208194

209195
program
210196
.command("run <file>")
211-
.description("run a wasm file with grain's javascript runner")
212-
.addOption(new commander.Option("-p, --print-output").hideHelp())
213-
.action(run);
197+
.description("run a wasm file via grain's WASI runner")
198+
.action(exec.grainrun);
214199

215200
program
216201
.command("lsp")

0 commit comments

Comments
 (0)