Skip to content

Commit

Permalink
Configure wasm-pack & wasm-opt
Browse files Browse the repository at this point in the history
  • Loading branch information
expede committed Feb 4, 2024
1 parent d24f8f4 commit e5fdd53
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 41 deletions.
5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
cargo = "${pkgs.cargo}/bin/cargo";
node = "${unstable.nodejs_20}/bin/node";
wasm-pack = "${pkgs.wasm-pack}/bin/wasm-pack";
wasm-opt = "${pkgs.binaryen}/bin/wasm-opt";
in rec {
devShells.default = pkgs.devshell.mkShell {
name = "ucan";
Expand Down Expand Up @@ -134,13 +135,13 @@
name = "release:wasm:web";
help = "Release for current host target";
category = "release";
command = "${wasm-pack} build --release --target=web";
command = "${wasm-pack} build --release --target=web && ${wasm-opt} -Os ./pkg/ucan_bg.wasm -o ./pkg/ucan_bg.opt.wasm && ls -lh pkg/*.wasm | cut -d ' ' -f 8,13";
}
{
name = "release:wasm:nodejs";
help = "Release for current host target";
category = "release";
command = "${wasm-pack} build --release --target=nodejs";
command = "${wasm-pack} build --release --target=nodejs && ${wasm-opt} -Os ./pkg/ucan_bg.wasm -o ./pkg/ucan_bg.opt.wasm && ls -lah pkg/*.wasm | cut -d ' ' -f 8,13";
}
# Build
{
Expand Down
30 changes: 10 additions & 20 deletions src/ability/js/parentful.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct Config {
}

#[wasm_bindgen(typescript_custom_section)]
const CONSTRUCTOR_WITH_MAP: &str = r#"
const CONFIG_ARGS: &str = r#"
interface ConfigArgs {
command: string,
is_nonce_meaningful: boolean,
Expand All @@ -48,38 +48,28 @@ extern "C" {
pub type ConfigArgs;

pub fn command(this: &ConfigArgs) -> String;

pub fn is_nonce_meaningful(this: &ConfigArgs) -> bool;

pub fn validate_shape(this: &ConfigArgs) -> Function;

pub fn check_same(this: &ConfigArgs) -> Function;

pub fn check_parents(this: &ConfigArgs) -> Map;
}

#[wasm_bindgen]
impl Config {
// FIXME object args as an option
#[wasm_bindgen(constructor, typescript_type = "ConfigArgs")]
pub fn new(
js: ConfigArgs,
// command: String,
// is_nonce_meaningful: bool,
// validate_shape: Function,
// check_same: Function,
// check_parents: Map, // FIXME swap for an object?
) -> Result<Config, JsValue> {
#[wasm_bindgen(constructor)]
pub fn new(js_obj: ConfigArgs) -> Result<Config, JsValue> {
Ok(Config {
command: command(&js),
is_nonce_meaningful: is_nonce_meaningful(&js),
validate_shape: validate_shape(&js),
check_same: check_same(&js),
command: command(&js_obj),
is_nonce_meaningful: is_nonce_meaningful(&js_obj),
validate_shape: validate_shape(&js_obj),
check_same: check_same(&js_obj),
check_parents: {
let mut btree = BTreeMap::new();
let mut acc = Ok(());
// Correct order
check_parents(&js).for_each(&mut |value, key| {

check_parents(&js_obj).for_each(&mut |value, key| {
// |value, key| is correct ------^^^^^^^^^^^^
if let Ok(_) = &acc {
match key.as_string() {
None => acc = Err(JsString::from("Key is not a string")), // FIXME better err
Expand Down
35 changes: 16 additions & 19 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"module": "es2015",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2015"
]
}
}

0 comments on commit e5fdd53

Please sign in to comment.