cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.53k stars 365 forks source link

Package libudev was not found in the pkg-config search path. #1295

Closed Danvil closed 1 year ago

Danvil commented 1 year ago

Checklist

Describe your issue

Cross-compiling a binary which indirectly depends on libudev-sys v0.1.4 gives an error:

warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /project/XXX/Cargo.toml
workspace: /project/Cargo.toml
   Compiling libc v0.2.147
   Compiling proc-macro2 v1.0.63
   Compiling quote v1.0.29
   Compiling memchr v2.5.0
   Compiling parking_lot_core v0.9.8
   Compiling futures-task v0.3.28
   Compiling syn v1.0.109
   Compiling nix v0.14.1
   Compiling rustix v0.38.3
   Compiling serde v1.0.164
   Compiling anyhow v1.0.71
   Compiling thiserror v1.0.40
   Compiling lock_api v0.4.10
   Compiling slab v0.4.8
   Compiling num-traits v0.2.15
   Compiling libudev-sys v0.1.4
   Compiling tokio v1.29.1
   Compiling async-trait v0.1.72
   Compiling serde_json v1.0.99
error: failed to run custom build command for `libudev-sys v0.1.4`

Caused by:
  process didn't exit successfully: `/target/release/build/libudev-sys-f4d656869383b154/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_unknown_linux_gnu
  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_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=LIBUDEV_STATIC
  cargo:rerun-if-env-changed=LIBUDEV_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-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_unknown_linux_gnu
  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_ALLOW_SYSTEM_CFLAGS=\"1\" PKG_CONFIG_ALLOW_SYSTEM_LIBS=\"1\" PKG_CONFIG_PATH=\"/usr/lib/aarch64-linux-gnu/pkgconfig/:\" \"pkg-config\" \"--libs\" \"--cflags\" \"libudev\"` did not exit successfully: exit status: 1\nerror: could not find system library 'libudev' required by the 'libudev-sys' crate\n\n--- stderr\nPackage libudev was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libudev.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'libudev' found\n"', /cargo/registry/src/index.crates.io-6f17d22bba15001f/libudev-sys-0.1.4/build.rs:38:41
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

What target(s) are you cross-compiling for?

aarch64-unknown-linux-gnu

Which operating system is the host (e.g computer cross is on) running?

What architecture is the host?

What container engine is cross using?

cross version

0.2.5

Example

No response

Additional information / notes

No response

NobodyXu commented 1 year ago

You need to install libudev inside the container for aarch64 using pre-exec hooks.

Emilgardis commented 1 year ago

this should solve your issue. See also the wiki

# Cross.toml
[target.aarch64-unknown-linux-gnu]
pre-build = [
    "dpkg --add-architecture $CROSS_DEB_ARCH",
    "apt-get update && apt-get install --assume-yes ",
    "apt-get update && apt-get install -y pkg-config libudev-dev:$CROSS_DEB_ARCH"
]
Danvil commented 1 year ago

@Emilgardis I tried the suggested solution, but now cross build seems to hang forever on the command line.

Previously a build would print:

PS I:\myproj> cross build --release -p myapp --target=aarch64-unknown-linux-gnu
workspace: /project/Cargo.toml
   Compiling libc v0.2.147
   ...

With the Cross.toml file above it now hangs at:

PS I:\myproj> cross build --release -p myapp --target=aarch64-unknown-linux-gnu

without further progress and with casual CPU consumption between 5% - 10%.

Emilgardis commented 1 year ago

Add -v to the command to see what its doing, i suspect its docker buildx that is stalling

Danvil commented 1 year ago

Here is the console output with -v:

PS I:\myproj> cross build --release -p myapp --target=aarch64-unknown-linux-gnu -v
+ cargo metadata --format-version 1 --filter-platform aarch64-unknown-linux-gnu
+ rustc --print sysroot
+ rustup toolchain list
+ rustup target list --toolchain stable-x86_64-unknown-linux-gnu
+ rustup component list --toolchain stable-x86_64-unknown-linux-gnu
+ "C:\Program Files\RedHat\Podman\podman.exe"
+ "I:\\myproj" "C:\Program Files\RedHat\Podman\podman.exe" build --label 'org.cross-rs.for-cross-target=aarch64-unknown-linux-gnu' --label 'org.cross-rs.workspace_root=I:\myproj' --tag cross-custom-myproj:aarch64-unknown-linux-gnu-207c1-pre-build --build-arg 'CROSS_CMD=dpkg --add-architecture $CROSS_DEB_ARCH
apt-get update && apt-get install -y pkg-config libudev-dev:$CROSS_DEB_ARCH' --build-arg 'CROSS_DEB_ARCH=arm64' --file 'I:\myproj\target\aarch64-unknown-linux-gnu\Dockerfile.aarch64-unknown-linux-gnu-custom' 'I:\myproj'

It seems to hang at the install command.

I tried to play around with it a little. Basically any command, even ls -l, will make it hang. If the list of commands is empty it proceeds.

Danvil commented 1 year ago

As an additional comment the solution does work under Linux. So this seems to be a Windows specific problem.

Danvil commented 1 year ago

As this seems to be a different problem now I filed a new issue for it: https://github.com/cross-rs/cross/issues/1303

Thank you for the help here!