Cross-Compile failed on Ubuntu20.04
YingJie-Zhao opened this issue · comments
Hi, there!
I recently used plotters
in my project and I want to compile the project to x86_64-unknown-linux-musl
on ubuntu20.04, then I met the error below
failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`
...
...pkg-config not configured for cross-compilation...
...
the fontconfig
has been installed before compilation, but I can't find fontconfig-devel
or fontconfig-dev
on ubuntu.
May be someone can give me some tips?
Thanks!
Here is the full error log
Compiling yeslogic-fontconfig-sys v3.2.0
error: failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`
Caused by:
process didn't exit successfully: `/root/pili/target/release/build/yeslogic-fontconfig-sys-3d6e06f420f36c05/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=RUST_FONTCONFIG_DLOPEN
cargo:rerun-if-env-changed=FONTCONFIG_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-unknown-linux-musl
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_unknown_linux_musl
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-musl
cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_musl
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
--- stderr
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "pkg-config has not been configured to support cross-compilation.\n\nInstall a sysroot for the target platform and configure it via\nPKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\ncross-compiling wrapper for pkg-config and set it via\nPKG_CONFIG environment variable."', /root/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/yeslogic-fontconfig-sys-3.2.0/build.rs:8:48
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
In order to cross-compile you need to have fontconfig available compiled for the cross-target you're building for. The error message suggests what you need to do:
pkg-config has not been configured to support cross-compilation.
Install a sysroot for the target platform and configure it via
PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
cross-compiling wrapper for pkg-config and set it via
PKG_CONFIG environment variable.
So you will need to build fontconfig for x86_64-unknown-linux-musl
using a musl toolchain then use one of the environment variables above to point pkg-config
at it. On Debian/Ubuntu you can install the musl toolchain with the musl-tools
package.
@wezm
Also seeing the same issue when building inside an alpine docker container. For a new-to-rust person like myself how do I go about building fontconfig
for my target (aarch64-unknown-linux-musl
) as a 3rd party dependency and point pkg-config
to it?
This is what i'm seeing:
Compiling yeslogic-fontconfig-sys v3.2.0
error: failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`
Caused by:
process didn't exit successfully: `/usr/src/servus-proof/target/release/build/yeslogic-fontconfig-sys-050ef9f59bed60e3/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-env-changed=RUST_FONTCONFIG_DLOPEN
cargo:rerun-if-env-changed=FONTCONFIG_NO_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-unknown-linux-musl
cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_unknown_linux_musl
cargo:rerun-if-env-changed=HOST_PKG_CONFIG
cargo:rerun-if-env-changed=PKG_CONFIG
cargo:rerun-if-env-changed=FONTCONFIG_STATIC
cargo:rerun-if-env-changed=FONTCONFIG_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64-unknown-linux-musl
cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_unknown_linux_musl
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_PATH
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-unknown-linux-musl
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_unknown_linux_musl
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-unknown-linux-musl
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_unknown_linux_musl
cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
...
Any help on this will be greatly appreciated.
For a new-to-rust person like myself how do I go about building fontconfig for my target (aarch64-unknown-linux-musl) as a 3rd party dependency and point pkg-config to it?
@alifarooq0 inside Docker is simpler as you're probably not cross-compiling so you don't need to build it yourself, you can install the Alpine package. Here's an example Dockerfile
that works for me:
FROM alpine:3.17
RUN apk --update add cargo gcc musl-dev pkgconfig fontconfig-dev
RUN cargo new demo && \
cd demo && \
cargo add fontconfig && \
cargo build
The main bit is that pkgconfig
fontconfig-dev
need to be installed.
Amazing! That worked for me. Thanks for your help @wezm!
@wezm
Another follow-up: In the case where I'm also cross-compiling, in that case how do I build pkgconfig
fontconfig-dev
and fix the issue in that case?
@wezm Another follow-up: In the case where I'm also cross-compiling, in that case how do I build
pkgconfig
fontconfig-dev
and fix the issue in that case?
You would need to follow each project's instructions for building from source and set things via environment variables or configure
script arguments to point at the cross-compiling C tool chain that you built or installed.
This post seems like a reasonable summary: https://jensd.be/1126/linux/cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu