我的目标是编写一个Kotlin库,将它编译成WebAssembly,然后从JS调用它的函数。由于几个小时,我试着得到一个简单的你好世界的工作。有关此主题的文档要么不存在,要么隐藏得很好。
这是我的kotlin档案:
@Used
public fun hello() {
println("Hello world!")
}
fun main(args: Array<String>) {
println("main() function executed!")
}
当我将它编译到WebAssembly时,我会得到一个hello.wasm和
我才刚开始研究基板,已经把我搞糊涂了:
需要注意的是,衬底运行时同时编译为本机Rust std二进制文件和WebAssembly (Wasm)二进制文件。有关编译std和no_std特性的详细信息,请参阅XXX。
这很好,我熟悉std和no_std。我的印象是,您要么已启用std并将其编译为本机Rust二进制文件,要么没有将其编译为WASM二进制文件。
但是,当我查看运行时的lib.rs时,我会发现以下内容:
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of rec
我正在尝试将一个WebAssembly文件加载到浏览器中。我正在尝试加载this库,但当我尝试执行所描述的操作时,我得到一个错误 const worker = new Worker('http://localhost:3000/webworker-wasm')
VM114:1 Refused to create a worker from 'http://localhost:3000/webworker-wasm' because it violates the following Content Security Policy directive: "
我得到代码的错误"RuntimeError:在rustwasm中无法到达“
错误信息:
Uncaught (in promise) RuntimeError: unreachable
at __rust_start_panic (http://127.0.0.1:8080/wasm_bg.wasm:wasm-function[346]:0x274ec)
at rust_panic (http://127.0.0.1:8080/wasm_bg.wasm:wasm-function[254]:0x26d0b)
at std::panicking::rust_pani