pkg-config error during Rust cross-compilation
Asked Answered
N

2

30

I am getting this error when I try to cross-compile some Rust; does anyone know what I should be doing?

This happens when I run cargo build --target aarch64, I get:

Compiling glib-sys v0.10.1
error: failed to run custom build command for `glib-sys v0.10.1`
...
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.

I might have asked this before a year or so ago, but anyway I cannot find any answer. I have tried adding various lines to my Cargo.toml but nothing seems to help.

The relevant part of Cargo.toml has:

[target.'cfg(target_os = "android")'.dependencies]
cairo = "0.0.4"
freetype = "0.7.0"
glib = "0.14.2"
openssl = "0.10.36"
openssl-sys = {version = "0.9.66", features = ["vendored"]}

There is probably a one-line answer to this; can anyone help me please.

Niobium answered 21/8, 2021 at 8:0 Comment(0)
R
21

You could try adding feature vendored for the openssl crate.

openssl = { version = "0.10.35", features = ["vendored"] }

reference

Ralline answered 20/7, 2022 at 6:16 Comment(0)
P
11

I'm also new to rust so there may be some mistakes in my answer.

So the warning suggests that the pkg-config is not correctly set, which suggests that this is not a rust issue, it's a pkg-config issue.

If you check the doc of pkg-config, you might see there's an environment variable called PKG_CONFIG_SYSROOT_DIR which "is useful for cross compilation". What you'll need to do is to run cargo with this environment set, e.g. PKG_CONFIG_SYSROOT_DIR=/usr/x86_64-w64-mingw32/ cargo build, where /usr/x86_64-w64-mingw32 contains all the file necessary for cross build for windows (as you can see from the name).

I'm not sure how to cross compile for aarch64, and I'm not sure how to add environment variable for cargo build, but I hope my experience above can give you some hint.

Propst answered 30/8, 2021 at 4:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.