如何在通过Cross运行Rust时发送RUST_BACKTRACE=1

myzjeezk  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(271)

我正在尝试使用Cross交叉编译Rust项目
我收到一个错误,我想通过设置环境变量RUST_BACKTRACE=1来跟踪进程
但我不知道如何在使用Cross时这样做。

编辑

我使用的是命令cross build --target aarch64-unknown-linux-gnu
这是我的“cross.toml”目录

[target.aarch64-unknown-linux-gnu]
openssl-sys = "0.9.76"

[build.env]
passthrough = [
    "RUST_BACKTRACE",
    "RUST_LOG",
    "TRAVIS",
]

[target.aarch64-unknown-linux-gnu.env]
passthrough = [
    "RUST_DEBUG",
]

我在尝试编译时收到以下错误

thread 'main' panicked at '

  Could not find directory of OpenSSL installation, and this `-sys` crate cannot
  proceed without this knowledge. If OpenSSL is installed and this crate had
  trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
  compilation process.

  Make sure you also have the development packages of openssl installed.
  For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

  If you're in a situation where you think the directory *should* be found
  automatically, please open a bug at https://github.com/sfackler/rust-openssl
  and include information about your system as well as this message.

  $HOST = x86_64-unknown-linux-gnu
  $TARGET = aarch64-unknown-linux-gnu
  openssl-sys = 0.9.76

  ', /cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.76/build/find_normal.rs:191:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
9bfwbjaz

9bfwbjaz1#

在Cross.toml中使用passthrough只是 * 传递 * 你的本地环境变量。所以在你的例子中,它是按预期工作的,但它没有按你希望的那样工作的原因是因为RUST_BACKTRACE变量没有设置。
在Linux/Unix(mac)中,您可以通过例如写入echo $RUST_BACKTRACE来检查环境变量的值,并通过写入RUST_BACKTRACE=1来临时设置它。
因此,为了设置cross中的变量,您可以在运行如下命令时设置RUST_BACKTRACE

RUST_BACKTRACE=1 cross build --target aarch64-unknown-linux-gnu

或者,您可以直接在Cross.toml配置中设置该值,如下所示:

[target.aarch64-unknown-linux-gnu]
openssl-sys = "0.9.76"

[build.env]
passthrough = [
    "RUST_BACKTRACE=1",
    "RUST_LOG",
    "TRAVIS",
]

[target.aarch64-unknown-linux-gnu.env]
passthrough = [
    "RUST_DEBUG",
]

相关问题