Skip to content
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

Fix build and run on Windows (+ additional benchmarks CI target platform). #1511

Merged
merged 7 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
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
7 changes: 6 additions & 1 deletion src/build/build-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ 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 };

async function buildAndImport(srcPath, { keepFile = false }) {
let absPath = await build(srcPath);
let importedModule;
try {
importedModule = await import(absPath);
let absPathForImport = absPath
if (platform === 'win32') {
absPathForImport = 'file:///' + absPathForImport;
shimkiv marked this conversation as resolved.
Show resolved Hide resolved
}
importedModule = await import(absPathForImport);
} finally {
if (!keepFile) await fs.unlink(absPath);
}
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
4 changes: 4 additions & 0 deletions src/build/run.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import minimist from 'minimist';
import { platform } from 'node:process';
import { buildAndImport, buildOne } from './build-example.js';

let {
Expand All @@ -18,6 +19,9 @@ npx snarky-run [file]`);
if (!bundle) {
let absPath = await buildOne(filePath);
console.log(`running ${absPath}`);
if (platform === 'win32') {
absPath = 'file:///' + absPath;
shimkiv marked this conversation as resolved.
Show resolved Hide resolved
}
let module = await import(absPath);
if (main) await module.main();
if (runDefault) await module.default();
Expand Down
Loading