-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[wasm] fix #5021: wechat webassembly support #5056
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution, a couple of comments.
Reviewable status: 0 of 1 approvals obtained (waiting on @deepkolos)
tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 16 at r1 (raw file):
file.endsWith('tfjs-backend-wasm-threaded-simd.js') ) { code = code.replace(`require("worker_threads")`, 'null')
we prefer to have ';' at the end of the statement.
tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 22 at r1 (raw file):
// it is not a nice way, but WebAssembly.validate not working and SIMD is not support in WXWebAssembly if (file.endsWith('backend_wasm.ts')) { code = code.replace(`env().getAsync('WASM_HAS_SIMD_SUPPORT')`, 'false')
this can be done in the wechat plugin, where we can do tf.env().set('WASM_HAS_SIMD_SUPPORT', false), similar with WASM_HAS_MULTITHREAD_SUPPORT
tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 25 at r1 (raw file):
code = code.replace(`env().getAsync('WASM_HAS_MULTITHREAD_SUPPORT')`, 'false') code = code.replace( `function createInstantiateWasmFunc(path) {`,
This is bit of hacky to relies on treeshaking to remove the rest of the method, can you use regex to match the whole method?
}); | ||
return {}; | ||
}`) | ||
const ast = this.parse(code); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pyu10055 a better way to replace createInstantiateWasmFunc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and test case updated
tf.env().set('WASM_HAS_SIMD_SUPPORT', false);
tf.env().set('WASM_HAS_MULTITHREAD_SUPPORT', false);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 1 of 1 approvals obtained (waiting on @deepkolos)
tfjs-backend-wasm/scripts/patch-wechat-webassembly.js, line 35 at r2 (raw file):
Previously, deepkolos (DeepKolos) wrote…
and test case updated
tf.env().set('WASM_HAS_SIMD_SUPPORT', false); tf.env().set('WASM_HAS_MULTITHREAD_SUPPORT', false);
This is very nice, thanks you!
tfjs-backend-wasm/src/backend_wasm.ts, line 213 at r3 (raw file):
function createInstantiateWasmFunc(path: string) { // this will be replace by rollup plugin patchWechatWebAssembly in minprogram's output
is this comment still needed, or should it be updated to reflect your new solution?
To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.
test demo in repo tfjs-wxmp-wasm-test
related issue: #5021
This change is