Skip to content

Add ability to run on Apple silicon #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 14, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ package-lock.json
yarn-error.log
/typescript
/example-multi
.DS_Store
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ rust({

// Allows you to customize the behavior for loading the .wasm file, this is for advanced users only!
importHook: function (path) { return JSON.stringify(path); },

// Allows you to define a custom path to wasm-pack.
// If the path starts with '~' it will be converted to `os.homedir()`
// eg. "~/.cargo/bin/wasm-pack -> "/Users/user_name/.cargo/bin/wasm-pack"
wasmPackPath: "node_modules/.bin/wasm-pack"
})
```

Expand Down
4 changes: 2 additions & 2 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ console_error_panic_hook = "0.1.6"
[dependencies.web-sys]
version = "0.3.35"
features = [
"console",
]
"console"
]
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"rimraf": "^3.0.2",
"rollup": "^1.31.0"
}
}
}
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const $path = require("path");
const $child = require("child_process");
const $toml = require("toml");
const $rimraf = require("rimraf");
const $os = require("os");
const { createFilter } = require("rollup-pluginutils");


Expand Down Expand Up @@ -128,6 +129,21 @@ async function get_target_dir(dir) {
//return JSON.parse(metadata).target_directory;
}

function wasm_pack_path(options) {
if (options.wasmPackPath !== undefined) {
if (typeof (options.wasmPackPath) === "string") {
// Quick hack to allow use of "~" for home directory?
return (options.wasmPackPath.startsWith("~") ? options.wasmPackPath.replace("~", $os.homedir()) : options.wasmPackPath);
} else {
throw new Error("'wasmPackPath' must be a string")
}
} else if (process.platform === "win32") {
// TODO pretty hacky, but needed to make it work on Windows
return "wasm-pack.cmd"
} else {
return "wasm-pack"
}
}

async function wasm_pack(cx, state, dir, source, id, options) {
const target_dir = await get_target_dir(dir);
Expand All @@ -150,8 +166,7 @@ async function wasm_pack(cx, state, dir, source, id, options) {
"--",
].concat(options.cargoArgs);

// TODO pretty hacky, but needed to make it work on Windows
const command = (process.platform === "win32" ? "wasm-pack.cmd" : "wasm-pack");
const command = wasm_pack_path(options);

try {
// TODO what if it tries to build the same crate multiple times ?
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
"glob": "^7.1.6",
"rimraf": "^3.0.0",
"rollup-pluginutils": "^2.8.2",
"toml": "^3.0.0",
"toml": "^3.0.0"
},
"optionalDependencies": {
"wasm-pack": "^0.10.0"
}
}
}