如何通过 wasm-pack 将 Rust Wasm 应用程序与 libpq 链接? [英] How can I link a Rust Wasm application with libpq via wasm-pack?

查看:41
本文介绍了如何通过 wasm-pack 将 Rust Wasm 应用程序与 libpq 链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Wasm 数据库层创建 NodeJS 应用程序.我使用 Rust、Diesel 作为数据库驱动程序,使用 wasm-pack 作为 WebAssembly 编译器.

I'm trying to create a NodeJS application with a Wasm database layer. I use Rust, Diesel as a database driver and wasm-pack as a WebAssembly compiler.

当我尝试使用 wasm-pack 构建我的服务时,它尝试链接 libpq 库失败.PQ_LIB_DIR 环境变量已设置,diesel-cli 工作没有任何问题,但是当我尝试编译我的服务时,它失败并出现以下错误:

When I try to build my service with wasm-pack, it fails trying to link the libpq library. The PQ_LIB_DIR environment variable is set, and the diesel-cli works without any issue, but when I try to compile my service it fails with the following error:

error: linking with `rust-lld` failed: exit code: 1
  = note: rust-lld: error: unable to find library -llibpq

我该如何解决?

我的系统:

  • 操作系统:Windows 10
  • :1.38.0
  • wasm-pack:0.8.1
  • 柴油:1.4.0
  • PostgreSQL:12
  • OS: Windows 10
  • Rust: 1.38.0
  • wasm-pack: 0.8.1
  • diesel: 1.4.0
  • PostgreSQL: 12

推荐答案

无法从 WebAssembly 链接到系统库.您必须使用以纯 Rust 代码编写的实现才能使其工作.您也可以使用 JavaScript 库.但它始终必须在 JavaScript 运行时环境内.

It's not possible to link to a system library from WebAssembly. You have to use an implementation written in pure Rust code to make it work. You also could use a JavaScript library. But it always has to be inside of the JavaScript runtime environment.

这篇关于如何通过 wasm-pack 将 Rust Wasm 应用程序与 libpq 链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆