Skip to content
This repository was archived by the owner on Sep 12, 2023. It is now read-only.
This repository was archived by the owner on Sep 12, 2023. It is now read-only.

Deno Build output is broken #14

@alexl0gan

Description

@alexl0gan

I'm trying to compile the following lib file

use wasm_bindgen::prelude::*;
use serde::{Serialize, Deserialize};
use std::collections::HashMap;
use std::iter::FromIterator;


#[derive(Serialize, Deserialize)]
pub struct QueryResult {
  pub data: Vec<String>
}

#[derive(Serialize, Deserialize)]
pub struct VehicleCounts {
  pub data: Vec<(String, u64)>
}

#[wasm_bindgen]
pub fn get_counts(val: &JsValue) -> JsValue {
  println!("here!");
  let query_result: QueryResult = val.into_serde().unwrap();
  let counts = get_counts_imp(query_result.data);
  let vehicle_count = VehicleCounts {
    data: counts
  };

  JsValue::from_serde(&vehicle_count).unwrap()
}

fn get_counts_imp(arr: Vec<String>) -> Vec<(String, u64)>{
  let mut make_counts: HashMap<String, u64> = HashMap::new();

  for vehicle in arr {
      let v = make_counts.entry(vehicle).or_insert(0);
      *v += 1
  }

  let mut hash_vec: Vec<(String, u64)> = Vec::from_iter(make_counts);
  hash_vec.sort_by(|a, b| b.1.cmp(&a.1));
  println!("Sorted: {:?}", hash_vec);

  return hash_vec
}

Using the command

rustwasmc build --target deno

However this causes the following error in Deno

error: Uncaught TypeError: WebAssembly.Instance(): Import #0 module="__wbindgen_placeholder__" error: module is not an object or function
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);

It looks like the offending line is

const wasi = new WASI({
  args: Deno.args,
  env: Deno.env.toObject(),
  preopens: {
    "/": __dirname,
  },
});
---> imports = { wasi_snapshot_preview1: wasi.exports }; <---

const p = path.join(__dirname, "functions_lib_bg.wasm");
const bytes = Deno.readFileSync(p);

Which is clearing the other imports added earlier in the file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions