Skip to content

Commit

Permalink
Merge branch 'main' into chore/wasi-sockets-udp-worker-thread
Browse files Browse the repository at this point in the history
  • Loading branch information
manekinekko authored Dec 12, 2023
2 parents 779ecaf + 50760d6 commit 594eefc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<p>
<a href="https://github.com/bytecodealliance/jco/actions?query=workflow%3ACI"><img src="https://github.com/bytecodealliance/jco/workflows/CI/badge.svg" alt="build status" /></a>
</p>

<h3>
<a href="https://bytecodealliance.github.io/jco/">Contributing</a>
<span> | </span>
<a href="https://bytecodealliance.zulipchat.com/#narrow/stream/409526-jco">Chat on Zulip</a>
</h3>
</div>

## Overview
Expand Down
19 changes: 11 additions & 8 deletions packages/preview2-shim/lib/browser/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ function getChildEntry (parentEntry, subpath, openFlags) {
let segmentIdx;
do {
if (!entry || !entry.dir) throw 'not-directory';
segmentIdx = subpath.indexOf('/');
segmentIdx = subpath.indexOf('/', segmentIdx);
const segment = segmentIdx === -1 ? subpath : subpath.slice(0, segmentIdx);
if (segment === '.' || segment === '') return entry;
if (segment === '..') throw 'no-entry';
if (!entry.dir[segment] && openFlags.create)
if (segment === '.' || segment === '')
/* continue traversing */;
else if (segment === '..')
throw 'no-entry';
else if (!entry.dir[segment] && openFlags.create)
entry = entry.dir[segment] = openFlags.directory ? { dir: {} } : { source: new Uint8Array([]) };
else
entry = entry.dir[segment];
} while (segmentIdx !== -1)
subpath = subpath.substring(segmentIdx + 1);
} while (segmentIdx !== -1);
if (!entry) throw 'no-entry';
return entry;
}
Expand Down Expand Up @@ -179,13 +182,13 @@ class Descriptor {
stat() {
let type = 'unknown', size = BigInt(0);
if (this.#entry.source) {
type = 'directory';
}
else if (this.#entry.dir) {
type = 'regular-file';
const source = getSource(this.#entry);
size = BigInt(source.byteLength);
}
else if (this.#entry.dir) {
type = 'directory';
}
return {
type,
linkCount: BigInt(0),
Expand Down
2 changes: 1 addition & 1 deletion packages/preview2-shim/lib/browser/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const random = {
for (var generated = 0; generated < len; generated += MAX_BYTES) {
// buffer.slice automatically checks if the end is past the end of
// the buffer so we don't have to here
crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
crypto.getRandomValues(bytes.subarray(generated, generated + MAX_BYTES));
}
} else {
crypto.getRandomValues(bytes);
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ async function wasm2Js (source) {
*/
export async function transpileComponent (component, opts = {}) {
await $init;
if (opts.noWasiShim || opts.instantiation) opts.wasiShim = false;
if (opts.instantiation) opts.wasiShim = false;

let spinner;
const showSpinner = getShowSpinner();
Expand Down Expand Up @@ -119,8 +119,8 @@ export async function transpileComponent (component, opts = {}) {
instantiation,
validLiftingOptimization: opts.validLiftingOptimization ?? false,
tracing: opts.tracing ?? false,
noNodejsCompat: !(opts.nodejsCompat ?? true),
noTypescript: opts.noTypescript || false,
noNodejsCompat: opts.nodejsCompat === false,
noTypescript: opts.typescript === false,
tlaCompat: opts.tlaCompat ?? false,
base64Cutoff: opts.js ? 0 : opts.base64Cutoff ?? 5000,
noNamespacedExports: opts.namespacedExports === false,
Expand Down
15 changes: 13 additions & 2 deletions src/jco.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { program, Option } from 'commander';
import { opt } from './cmd/opt.js';
import { transpile } from './cmd/transpile.js';
import { run } from './cmd/run.js';
import { run as runCmd } from './cmd/run.js';
import { parse, print, componentNew, componentEmbed, metadataAdd, metadataShow, componentWit } from './cmd/wasm-tools.js';
import { componentize } from './cmd/componentize.js';
import c from 'chalk-template';
Expand Down Expand Up @@ -55,12 +55,21 @@ program.command('run')
.description('Run a WebAssembly Command component')
.usage('<command.wasm> <args...>')
.helpOption(false)
.allowUnknownOption(true)
.allowExcessArguments(true)
.argument('<command>', 'Wasm command binary to run')
.option('--jco-dir <dir>', 'Instead of using a temporary dir, set the output directory for the run command')
.option('--jco-trace', 'Enable call tracing')
.option('--jco-import <module>', 'Custom module to import before the run executes to support custom environment setup')
.argument('[args...]', 'Any CLI arguments to provide to the command')
.action(asyncAction(run));
.action(asyncAction(async function run (cmd, args, opts, command) {
// specially only allow help option in first position
if (cmd === '--help' || cmd === '-h') {
command.help();
} else {
return runCmd(cmd, args, opts);
}
}));

program.command('opt')
.description('optimizes a Wasm component, including running wasm-opt Binaryen optimizations')
Expand Down Expand Up @@ -124,6 +133,8 @@ program.command('embed')
.option('-m, --metadata <metadata...>', 'field=name[@version] producer metadata to add with the embedding')
.action(asyncAction(componentEmbed));

program.showHelpAfterError();

program.parse();

function asyncAction (cmd) {
Expand Down

0 comments on commit 594eefc

Please sign in to comment.