Skip to content

Commit

Permalink
Merge pull request #1511 from o1-labs/fix/bench-win-support
Browse files Browse the repository at this point in the history
Fix build and run on Windows (+ additional benchmarks CI target platform).
  • Loading branch information
shimkiv committed Mar 22, 2024
2 parents 02f2ffb + 4325090 commit 95e5d41
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,6 +37,7 @@ jobs:
git submodule update --init --recursive
npm ci
npm run build
bash run-ci-benchmarks.sh
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
2 changes: 1 addition & 1 deletion benchmark/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions src/build/build-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs/promises';
import path from 'path';
import ts from 'typescript';
import esbuild from 'esbuild';
import { platform } from 'node:process';

export { buildAndImport, build, buildOne };

Expand All @@ -11,7 +12,7 @@ async function buildAndImport(srcPath, { keepFile = false }) {
try {
importedModule = await import(absPath);
} finally {
if (!keepFile) await fs.unlink(absPath);
if (!keepFile) await fs.unlink(absPath.replace(/^file:\/\/\/*/, ''));
}
return importedModule;
}
Expand Down Expand Up @@ -44,6 +45,9 @@ async function build(srcPath, isWeb = false) {
});

let absPath = path.resolve('.', outfile);
if (platform === 'win32') {
absPath = 'file:///' + absPath;
}
return absPath;
}

Expand All @@ -70,6 +74,9 @@ async function buildOne(srcPath) {
});

let absPath = path.resolve('.', outfile);
if (platform === 'win32') {
absPath = 'file:///' + absPath;
}
return absPath;
}

Expand Down Expand Up @@ -104,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')),
}));
},
};
Expand Down
5 changes: 3 additions & 2 deletions src/build/build-node.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -46,13 +47,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: !(platform === 'win32' && path.endsWith('index.js')),
}));
},
};
Expand Down

0 comments on commit 95e5d41

Please sign in to comment.