Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion crates/wasm-tools-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ use wasm_metadata::Producers;
use wit_component::{ComponentEncoder, DecodedWasm, WitPrinter};
use wit_parser::{Resolve, UnresolvedPackage};

use exports::local::wasm_tools::tools::{
EmbedOpts, Guest, ModuleMetaType, ModuleMetadata, ProducersFields, StringEncoding,
};

wit_bindgen::generate!({
world: "wasm-tools",
exports: {
world: WasmToolsJs
"local:wasm-tools/tools": WasmToolsJs
}
});

Expand Down
20 changes: 12 additions & 8 deletions crates/wasm-tools-component/wit/wasm-tools.wit
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package local:wasm-tools

world wasm-tools {
interface tools {
/// Translate the WebAssembly text format to binary
export parse: func(wat: string) -> result<list<u8>, string>
parse: func(wat: string) -> result<list<u8>, string>

/// Translate the WebAssembly binary format to text
export print: func(binary: list<u8>) -> result<string, string>
print: func(binary: list<u8>) -> result<string, string>

enum string-encoding {
utf8,
Expand All @@ -14,10 +14,10 @@ world wasm-tools {
}

/// Create a component from a core wasm binary that implements and embeds a component type
export component-new: func(binary: list<u8>, adapters: option<list<tuple<string, list<u8>>>>) -> result<list<u8>, string>
component-new: func(binary: list<u8>, adapters: option<list<tuple<string, list<u8>>>>) -> result<list<u8>, string>

/// Extract a *.wit interface from a component, optionally providing a document name to extract
export component-wit: func(binary: list<u8>) -> result<string, string>
component-wit: func(binary: list<u8>) -> result<string, string>

type producers-fields = list<tuple<string, list<tuple<string, string>>>>

Expand All @@ -35,7 +35,7 @@ world wasm-tools {
metadata: option<producers-fields>
}

export component-embed: func(embed-opts: embed-opts) -> result<list<u8>, string>
component-embed: func(embed-opts: embed-opts) -> result<list<u8>, string>

variant module-meta-type {
module,
Expand All @@ -51,8 +51,12 @@ world wasm-tools {
}

/// Extract the metadata for a component
export metadata-show: func(binary: list<u8>) -> result<list<module-metadata>, string>
metadata-show: func(binary: list<u8>) -> result<list<module-metadata>, string>

/// Append producer metadata to a component
export metadata-add: func(binary: list<u8>, metadata: producers-fields) -> result<list<u8>, string>
metadata-add: func(binary: list<u8>, metadata: producers-fields) -> result<list<u8>, string>
}

world wasm-tools {
export tools
}
17 changes: 9 additions & 8 deletions packages/preview2-shim/lib/browser/cli.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
let _env, _args = [], _cwd = null;
import { _setCwd as fsSetCwd } from './filesystem.js';

let _env = [], _args = [], _cwd = null;
export function _setEnv (envObj) {
_env = Object.entries(envObj);
}

export function _setArgs (args) {
_args = args;
}

export function _setCwd (cwd) {
_cwd = cwd;
fsSetCwd(_cwd = cwd);
}

export const environment = {
getEnvironment () {
if (!_env) _setEnv(process.env);
return _env;
},
getArguments () {
Expand All @@ -25,15 +25,16 @@ export const environment = {
};

class ComponentExit extends Error {
constructor(code) {
super(`Component exited ${code === 0 ? 'successfully' : 'with error'}`);
this.code = code;
constructor(ok) {
super(`Component exited ${ok ? 'successfully' : 'with error'}`);
this.exitError = true;
this.ok = ok;
}
}

export const exit = {
exit (status) {
throw new ComponentExit(status.tag === 'err' ? 1 : 0);
throw new ComponentExit(status.tag === 'err' ? true : false);
}
};

Expand Down
Loading