Skip to content

Commit

Permalink
deps: upgrade to [email protected] toolchain (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
macovedj authored Feb 20, 2024
1 parent fabbe7c commit 2b546b7
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 131 deletions.
222 changes: 115 additions & 107 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ indexmap = "2.1"
js-component-bindgen = { path = "./crates/js-component-bindgen" }
structopt = "0.3.26"
tempdir = "0.3.7"
wasm-encoder = "0.40.0"
wasm-metadata = "0.10.16"
wasmparser = "0.120.0"
wasmprinter = "0.2.77"
wasmtime-environ = { version = "17.0.0", features = ["component-model"] }
wat = "1.0.84"
wit-bindgen = "0.16.0"
wit-bindgen-core = "0.16.0"
wit-component = { version = "0.20.0", features = ["dummy-module"] }
wit-parser = "0.13.1"
wasm-encoder = "0.200.0"
wasm-metadata = "0.10.20"
wasmparser = "0.200.0"
wasmprinter = "0.200.0"
wasmtime-environ = { version = "18.0.0", features = ["component-model"] }
wat = "1.200.0"
wit-bindgen = "0.18.0"
wit-bindgen-core = "0.18.0"
wit-component = { version = "0.21.0", features = ["dummy-module"] }
wit-parser = "0.14.0"
xshell = "0.2.5"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/js-component-bindgen-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Guest for JsComponentBindgenComponent {
wasmtime_environ::component::Export::LiftedFunction { .. } => {
ExportType::Function
}
wasmtime_environ::component::Export::Instance(_) => {
wasmtime_environ::component::Export::Instance { .. } => {
ExportType::Instance
}
_ => panic!("Unexpected export type"),
Expand Down
34 changes: 34 additions & 0 deletions crates/js-component-bindgen/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ use wasmtime_environ::component::CoreDef;
use wasmtime_environ::wasmparser;
use wasmtime_environ::{EntityIndex, MemoryIndex, ModuleTranslation, PrimaryMap};

fn unimplemented_try_table() -> wasm_encoder::Instruction<'static> {
unimplemented!()
}
pub enum Translation<'a> {
Normal(ModuleTranslation<'a>),
Augmented {
Expand Down Expand Up @@ -711,6 +714,7 @@ macro_rules! define_translate {
(mk F32Const $v:ident) => (F32Const(f32::from_bits($v.bits())));
(mk F64Const $v:ident) => (F64Const(f64::from_bits($v.bits())));
(mk V128Const $v:ident) => (V128Const($v.i128()));
(mk TryTable $v:ident) => (unimplemented_try_table());
(mk MemoryGrow $($x:tt)*) => ({
if true { unimplemented!() } Nop
});
Expand Down Expand Up @@ -753,6 +757,17 @@ macro_rules! define_translate {
$arg.targets().map(|i| i.unwrap()).collect::<Vec<_>>().into(),
$arg.default(),
));
(map $self:ident $arg:ident try_table) => {$arg};
(map $self:ident $arg:ident struct_type_index) => {$self.remap(Item::Type, $arg).unwrap()};
(map $self:ident $arg:ident field_index) => {$arg};
(map $self:ident $arg:ident array_type_index) => {$self.remap(Item::Type, $arg).unwrap()};
(map $self:ident $arg:ident array_size) => {$arg};
(map $self:ident $arg:ident array_data_index) => ($self.remap(Item::Data, $arg).unwrap());
(map $self:ident $arg:ident array_elem_index) => ($self.remap(Item::Element, $arg).unwrap());
(map $self:ident $arg:ident array_type_index_dst) => ($self.remap(Item::Type, $arg).unwrap());
(map $self:ident $arg:ident array_type_index_src) => ($self.remap(Item::Type, $arg).unwrap());
(map $self:ident $arg:ident from_ref_type) => ($self.refty(&$arg).unwrap());
(map $self:ident $arg:ident to_ref_type) => ($self.refty(&$arg).unwrap());
}

impl<'a> VisitOperator<'a> for Translator<'_, 'a> {
Expand All @@ -761,7 +776,26 @@ impl<'a> VisitOperator<'a> for Translator<'_, 'a> {
wasmparser::for_each_operator!(define_translate);
}

#[derive(Debug, Hash, Eq, PartialEq, Copy, Clone)]
pub enum Item {
// Function,
// Table,
// Memory,
// Tag,
// Global,
Type,
Data,
Element,
}

impl Translator<'_, '_> {
fn remap(&mut self, item: Item, idx: u32) -> Result<u32> {
let _ = item;
Ok(idx)
}
fn refty(&mut self, _ty: &wasmparser::RefType) -> Result<wasm_encoder::RefType> {
unimplemented!()
}
fn blockty(&self, ty: wasmparser::BlockType) -> wasm_encoder::BlockType {
match ty {
wasmparser::BlockType::Empty => wasm_encoder::BlockType::Empty,
Expand Down
6 changes: 3 additions & 3 deletions crates/js-component-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn transpile(component: &[u8], opts: TranspileOpts) -> Result<Transpiled, an
// internal to a component to a straight linear list of initializers
// that need to be executed to instantiate a component.
let scope = ScopeVec::new();
let tunables = Tunables::default();
let tunables = Tunables::default_u32();
let mut types = ComponentTypesBuilder::default();
let mut validator = Validator::new_with_features(WasmFeatures {
component_model: true,
Expand All @@ -129,7 +129,7 @@ pub fn transpile(component: &[u8], opts: TranspileOpts) -> Result<Transpiled, an
.map(|(_i, module)| core::Translation::new(module, opts.multi_memory))
.collect::<Result<_>>()?;

let types = types.finish();
let types = types.finish(&PrimaryMap::new(), Vec::new(), Vec::new());

// Insert all core wasm modules into the generated `Files` which will
// end up getting used in the `generate_instantiate` method.
Expand All @@ -142,7 +142,7 @@ pub fn transpile(component: &[u8], opts: TranspileOpts) -> Result<Transpiled, an
}

let (imports, exports) = transpile_bindgen(
&name, &component, &modules, &types, &resolve, world_id, opts, &mut files,
&name, &component, &modules, &types.0, &resolve, world_id, opts, &mut files,
);

let mut files_out: Vec<(String, Vec<u8>)> = Vec::new();
Expand Down
14 changes: 7 additions & 7 deletions crates/js-component-bindgen/src/transpile_bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,11 @@ impl<'a> Instantiator<'a, '_> {
match item {
WorldItem::Interface(iface) => {
let iface = &self.resolve.interfaces[*iface];
let Export::Instance(instance) = &export else {
let Export::Instance { exports, .. } = &export else {
unreachable!()
};
for (ty_name, ty) in &iface.types {
match instance.get(ty_name).unwrap() {
match exports.get(ty_name).unwrap() {
Export::Type(TypeDef::Resource(resource)) => {
self.connect_resources(*ty, *resource, true);
}
Expand All @@ -466,7 +466,7 @@ impl<'a> Instantiator<'a, '_> {
}
}
for (func_name, func) in &iface.functions {
let Export::LiftedFunction { ty, .. } = instance.get(func_name).unwrap()
let Export::LiftedFunction { ty, .. } = exports.get(func_name).unwrap()
else {
unreachable!()
};
Expand Down Expand Up @@ -1539,12 +1539,12 @@ impl<'a> Instantiator<'a, '_> {
);
}
}
Export::Instance(iface) => {
Export::Instance { exports, .. } => {
let id = match item {
WorldItem::Interface(id) => *id,
WorldItem::Function(_) | WorldItem::Type(_) => unreachable!(),
};
for (func_name, export) in iface {
for (func_name, export) in exports {
let (def, options, _) = match export {
Export::LiftedFunction { func, options, ty } => (func, options, ty),
Export::Type(_) => continue, // ignored
Expand All @@ -1566,7 +1566,7 @@ impl<'a> Instantiator<'a, '_> {
}
.to_string();

self.export_bindgen(&local_name, def, options, func, export_name, true);
self.export_bindgen(&local_name, &def, &options, func, export_name, true);

if let FunctionKind::Constructor(ty)
| FunctionKind::Method(ty)
Expand Down Expand Up @@ -1594,7 +1594,7 @@ impl<'a> Instantiator<'a, '_> {

// This can't be tested at this time so leave it unimplemented
Export::ModuleStatic(_) => unimplemented!(),
Export::ModuleImport(_) => unimplemented!(),
Export::ModuleImport { .. } => unimplemented!(),
}
}
self.gen.esm_bindgen.populate_export_aliases();
Expand Down
4 changes: 2 additions & 2 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export async function apiTest(fixtures) {
[
"processed-by",
[
["wit-component", "0.20.0"],
["wit-component", "0.21.0"],
["dummy-gen", "test"],
],
],
Expand Down Expand Up @@ -186,7 +186,7 @@ export async function apiTest(fixtures) {
[
"processed-by",
[
["wit-component", "0.20.0"],
["wit-component", "0.21.0"],
["dummy-gen", "test"],
],
],
Expand Down
2 changes: 1 addition & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ export async function cliTest(fixtures) {
[
"processed-by",
[
["wit-component", "0.20.0"],
["wit-component", "0.21.0"],
["dummy-gen", "test"],
],
],
Expand Down

0 comments on commit 2b546b7

Please sign in to comment.