rust - 如何为 x86_64-unknown-linux-musl 构建依赖于 curl 的可执行文件

标签 rust musl

我在 amd64 Debian 机器上,正在尝试构建 x86_64-unknown-linux-musl 可执行文件。我的 Cargo.toml 中有这个:

[dependencies]
curl = "0.4"

当我运行 cargo build --target=x86_64-unknown-linux-musl 我得到 这个:

error: failed to run custom build command for `libz-sys v1.0.10`
process didn't exit successfully: `/tmp/foo/target/debug/build/libz-sys-c20da5f29c41e515/build-script-build` (exit code: 101)
--- stdout
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("x86_64-unknown-linux-musl")
debug=true opt-level=0
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-unknown-linux-musl")
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-musl = None
CC_x86_64_unknown_linux_musl = None
TARGET_CC = None
CC = None
HOST = Some("x86_64-unknown-linux-gnu")
CROSS_COMPILE = None
TARGET = Some("x86_64-unknown-linux-musl")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_x86_64-unknown-linux-musl = None
CFLAGS_x86_64_unknown_linux_musl = None
TARGET_CFLAGS = None
CFLAGS = None
running: "./configure" "--prefix=/tmp/foo/target/x86_64-unknown-linux-musl/debug/build/libz-sys-e109627694e9981e/out"
Compiler error reporting is too harsh for ./configure (perhaps remove -Werror).
** ./configure aborting.

--- stderr
thread 'main' panicked at 'failed to run successfully: exit code: 1', /home/tshepang/.cargo/registry/src/github.com-1ecc6299db9ec823/libz-sys-1.0.10/build.rs:189

当我重新运行它时:

error: failed to run custom build command for `openssl-sys v0.9.6`
process didn't exit successfully: `/tmp/foo/target/debug/build/openssl-sys-ac9c042b062dad1d/build-script-build` (exit code: 101)
--- stderr
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.

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 = x86_64-unknown-linux-musl
    openssl-sys = 0.9.6

当我在本地构建时一切正常,即 cargo build --target=x86_64-unknown-linux-gnu

四处搜索,我了解到一个环境变量,PKG_CONFIG_ALLOW_CROSS:

PKG_CONFIG_ALLOW_CROSS=true cargo build --target=x86_64-unknown-linux-musl

在这样做的过程中,我还发现我缺少 Debian 软件包 名为 libcurl4-openssl-dev

运行 ldd target/target/x86_64-unknown-linux-musl/debug/foo 指示可执行文件是动态链接的,然后搜索 此外,我了解了另一个环境变量, PKG_CONFIG_ALL_STATIC:

PKG_CONFIG_ALL_STATIC=true PKG_CONFIG_ALLOW_CROSS=true cargo build --target=x86_64-unknown-linux-musl

这揭示了一大堆缺失的部门,所有这些(幸运的是) 有 Debian 依赖项。但是安装所有这些都没有帮助,因为, 最后,我仍然坐在一个不是的可执行文件上 静态链接。

最佳答案

我放弃了,最终使用了 cross :

cargo install cross
cross build --target=x86_64-unknown-linux-musl

这太简单了,您会在 target/x86_64-unknown-linux-musl/debug 中找到可执行文件。

关于rust - 如何为 x86_64-unknown-linux-musl 构建依赖于 curl 的可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41723327/

相关文章:

rust - 一次不能多次借用 `*self` 作为可变的

rust - 是否可以为结构的一部分派(dispatch)生(RustcEncodable)?

rust - 整数类型的 from_char() 函数在哪里?

generics - 难以理解 Rust 中的特征和泛型

mips - MIPS 上的 ELF 加载、malloc 问题

compilation - 如何动态链接你的 nim 应用程序和 musl?

arrays - Go 或 Rust 中的数组数组?

glibc - 在 AlpineLinux 上使用使用 glibc 的共享库

glibc - 在同一个进程中加载​​ musl libc.so 和 gcc libc.so?