From 7e7cc1ac28f8b250c5aa352e804f3763182ee0c5 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Tue, 19 Mar 2024 15:46:46 +0200 Subject: [PATCH 1/7] Fix benchmarks run on Windows. --- .github/workflows/benchmarks.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index 94a4cf24b..f1b0aaa45 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -15,7 +15,7 @@ jobs: fail-fast: true matrix: node: [20] - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: - name: Checkout repository @@ -37,6 +37,5 @@ jobs: git submodule update --init --recursive npm ci npm run build - bash run-ci-benchmarks.sh + node --enable-source-maps --stack-trace-limit=1000 src/build/run.js benchmark/runners/with-cloud-history.ts --bundle >>benchmarks.log 2>&1 cat benchmarks.log >> $GITHUB_STEP_SUMMARY - shell: bash From f5632ff3bc34678cb7cae482bbff9f63ea39bfa3 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Tue, 19 Mar 2024 18:50:19 +0200 Subject: [PATCH 2/7] Windows build fix. --- src/build/build-node.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/build/build-node.js b/src/build/build-node.js index 4708bf5a8..5f1af370f 100644 --- a/src/build/build-node.js +++ b/src/build/build-node.js @@ -46,13 +46,13 @@ async function buildNode({ production }) { } function makeNodeModulesExternal() { - let isNodeModule = /^[^./]|^\.[^./]|^\.\.[^/]/; + let isNodeModule = /^[^./\\]|^\.[^./\\]|^\.\.[^/\\]/; return { name: 'plugin-external', setup(build) { build.onResolve({ filter: isNodeModule }, ({ path }) => ({ path, - external: true, + external: !path.endsWith('index.js'), })); }, }; From c2b978432ec9baacfa58ed966d7ff2feaf019d17 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Tue, 19 Mar 2024 21:09:31 +0200 Subject: [PATCH 3/7] Windows build fix. --- src/build/build-example.js | 7 ++++++- src/build/run.js | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/build/build-example.js b/src/build/build-example.js index 2f3a37e37..f5af4a3d5 100644 --- a/src/build/build-example.js +++ b/src/build/build-example.js @@ -2,6 +2,7 @@ import fs from 'fs/promises'; import path from 'path'; import ts from 'typescript'; import esbuild from 'esbuild'; +import os from 'node:os'; export { buildAndImport, build, buildOne }; @@ -9,7 +10,11 @@ async function buildAndImport(srcPath, { keepFile = false }) { let absPath = await build(srcPath); let importedModule; try { - importedModule = await import(absPath); + let absPathForImport = absPath + if (os.platform() === 'win32') { + absPathForImport = 'file:///' + absPathForImport; + } + importedModule = await import(absPathForImport); } finally { if (!keepFile) await fs.unlink(absPath); } diff --git a/src/build/run.js b/src/build/run.js index 7902f1ccd..6b5d8c94f 100755 --- a/src/build/run.js +++ b/src/build/run.js @@ -1,4 +1,5 @@ #!/usr/bin/env node +import os from 'node:os'; import minimist from 'minimist'; import { buildAndImport, buildOne } from './build-example.js'; @@ -18,6 +19,9 @@ npx snarky-run [file]`); if (!bundle) { let absPath = await buildOne(filePath); console.log(`running ${absPath}`); + if (os.platform() === 'win32') { + absPath = 'file:///' + absPath; + } let module = await import(absPath); if (main) await module.main(); if (runDefault) await module.default(); From e0c959f6837758cc6ec076a02cee26744f59b2db Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Tue, 19 Mar 2024 21:25:08 +0200 Subject: [PATCH 4/7] Output improvements. --- .github/workflows/benchmarks.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/benchmarks.yml b/.github/workflows/benchmarks.yml index f1b0aaa45..db25ed78c 100644 --- a/.github/workflows/benchmarks.yml +++ b/.github/workflows/benchmarks.yml @@ -37,5 +37,7 @@ jobs: git submodule update --init --recursive npm ci npm run build + echo 'Running o1js benchmarks.' node --enable-source-maps --stack-trace-limit=1000 src/build/run.js benchmark/runners/with-cloud-history.ts --bundle >>benchmarks.log 2>&1 cat benchmarks.log >> $GITHUB_STEP_SUMMARY + shell: bash From 771047b4a97b9be296e16aa0e8f70c7cca61a469 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Wed, 20 Mar 2024 09:06:03 +0200 Subject: [PATCH 5/7] Refactoring. --- src/build/build-example.js | 4 ++-- src/build/build-node.js | 3 ++- src/build/run.js | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/build/build-example.js b/src/build/build-example.js index f5af4a3d5..f555e4cff 100644 --- a/src/build/build-example.js +++ b/src/build/build-example.js @@ -2,7 +2,7 @@ import fs from 'fs/promises'; import path from 'path'; import ts from 'typescript'; import esbuild from 'esbuild'; -import os from 'node:os'; +import { platform } from 'node:process'; export { buildAndImport, build, buildOne }; @@ -11,7 +11,7 @@ async function buildAndImport(srcPath, { keepFile = false }) { let importedModule; try { let absPathForImport = absPath - if (os.platform() === 'win32') { + if (platform === 'win32') { absPathForImport = 'file:///' + absPathForImport; } importedModule = await import(absPathForImport); diff --git a/src/build/build-node.js b/src/build/build-node.js index 5f1af370f..4ba289033 100644 --- a/src/build/build-node.js +++ b/src/build/build-node.js @@ -1,4 +1,5 @@ import path from 'node:path'; +import { platform } from 'node:process'; import { fileURLToPath } from 'node:url'; import esbuild from 'esbuild'; import minimist from 'minimist'; @@ -52,7 +53,7 @@ function makeNodeModulesExternal() { setup(build) { build.onResolve({ filter: isNodeModule }, ({ path }) => ({ path, - external: !path.endsWith('index.js'), + external: !(platform === 'win32' && path.endsWith('index.js')), })); }, }; diff --git a/src/build/run.js b/src/build/run.js index 6b5d8c94f..40f4600f0 100755 --- a/src/build/run.js +++ b/src/build/run.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -import os from 'node:os'; import minimist from 'minimist'; +import { platform } from 'node:process'; import { buildAndImport, buildOne } from './build-example.js'; let { @@ -19,7 +19,7 @@ npx snarky-run [file]`); if (!bundle) { let absPath = await buildOne(filePath); console.log(`running ${absPath}`); - if (os.platform() === 'win32') { + if (platform === 'win32') { absPath = 'file:///' + absPath; } let module = await import(absPath); From 6c7744de76356ac06fa2d83fb448fd7d277a9bf5 Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Wed, 20 Mar 2024 09:13:10 +0200 Subject: [PATCH 6/7] Don't print new line after the benchmark name. --- benchmark/benchmark.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/benchmark.ts b/benchmark/benchmark.ts index 17ae0d981..c091fd64c 100644 --- a/benchmark/benchmark.ts +++ b/benchmark/benchmark.ts @@ -112,7 +112,7 @@ function logResult( result: BenchmarkResult, previousResult?: BenchmarkResult ): void { - console.log(result.label + `\n`); + console.log(result.label); console.log(`time: ${resultToString(result)}`); if (previousResult === undefined) return; From 4325090a856395b1dae4e6124e9f81a5d184754b Mon Sep 17 00:00:00 2001 From: Serhii Shymkiv Date: Wed, 20 Mar 2024 14:08:24 +0200 Subject: [PATCH 7/7] Addressing review comments. --- src/build/build-example.js | 18 ++++++++++-------- src/build/run.js | 4 ---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/build/build-example.js b/src/build/build-example.js index f555e4cff..966bf6088 100644 --- a/src/build/build-example.js +++ b/src/build/build-example.js @@ -10,13 +10,9 @@ async function buildAndImport(srcPath, { keepFile = false }) { let absPath = await build(srcPath); let importedModule; try { - let absPathForImport = absPath - if (platform === 'win32') { - absPathForImport = 'file:///' + absPathForImport; - } - importedModule = await import(absPathForImport); + importedModule = await import(absPath); } finally { - if (!keepFile) await fs.unlink(absPath); + if (!keepFile) await fs.unlink(absPath.replace(/^file:\/\/\/*/, '')); } return importedModule; } @@ -49,6 +45,9 @@ async function build(srcPath, isWeb = false) { }); let absPath = path.resolve('.', outfile); + if (platform === 'win32') { + absPath = 'file:///' + absPath; + } return absPath; } @@ -75,6 +74,9 @@ async function buildOne(srcPath) { }); let absPath = path.resolve('.', outfile); + if (platform === 'win32') { + absPath = 'file:///' + absPath; + } return absPath; } @@ -109,13 +111,13 @@ function typescriptPlugin(tsConfig) { } function makeNodeModulesExternal() { - let isNodeModule = /^[^./]|^\.[^./]|^\.\.[^/]/; + let isNodeModule = /^[^./\\]|^\.[^./\\]|^\.\.[^/\\]/; return { name: 'plugin-external', setup(build) { build.onResolve({ filter: isNodeModule }, ({ path }) => ({ path, - external: true, + external: !(platform === 'win32' && path.endsWith('index.js')), })); }, }; diff --git a/src/build/run.js b/src/build/run.js index 40f4600f0..7902f1ccd 100755 --- a/src/build/run.js +++ b/src/build/run.js @@ -1,6 +1,5 @@ #!/usr/bin/env node import minimist from 'minimist'; -import { platform } from 'node:process'; import { buildAndImport, buildOne } from './build-example.js'; let { @@ -19,9 +18,6 @@ npx snarky-run [file]`); if (!bundle) { let absPath = await buildOne(filePath); console.log(`running ${absPath}`); - if (platform === 'win32') { - absPath = 'file:///' + absPath; - } let module = await import(absPath); if (main) await module.main(); if (runDefault) await module.default();