rust-cross / rust-musl-cross

Docker images for compiling static Rust binaries using musl-cross
MIT License
620 stars 68 forks source link

Can't build with x86_64-musl around pkg-config #51

Closed HiraokaTakuya closed 1 year ago

HiraokaTakuya commented 2 years ago

I want to build the plotters example in x86_64-musl.
I did these commands.

git clone https://github.com/plotters-rs/plotters.git --recursive
cd plotters
docker run --rm -it -v `pwd`:/home/rust/src messense/rust-musl-cross:x86_64-musl
# in the container.
cd plotters
RUST_BACKTRACE=1 cargo run --example histogram

And I got errors.

error: failed to run custom build command for `yeslogic-fontconfig-sys v3.2.0`

Caused by:
  process didn't exit successfully: `/home/rust/src/target/debug/build/yeslogic-fontconfig-sys-cac8f25c1297fba5/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/github.com-1ecc6299db9ec823/yeslogic-fontconfig-sys-3.2.0/build.rs:8:48
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:584:5
     1: core::panicking::panic_fmt
               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:142:14
     2: core::result::unwrap_failed
               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/result.rs:1785:5
     3: core::result::Result<T,E>::unwrap
               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/result.rs:1078:23
     4: build_script_build::main
               at ./build.rs:8:9
     5: core::ops::function::FnOnce::call_once
               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/ops/function.rs:248:5
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...

It seems to be a problem with the configuration around pkg-config.
Sorry if this is not appropriate as an issue.
Is this a problem with messense/rust-musl-cross:x86_64-musl ?
Or should I create a properly configured Docker container based on messense/rust-musl-cross:x86_64-musl ?

messense commented 1 year ago

I don't know much about pkg-config, I'm afraid I'm unable to help you.

prisme60 commented 1 year ago

I think if you are building a musl executable, you don't have the right to use local libraries that are using glibc. That's why you need a pkg-config of a cross build environment. You can try to use buildroot https://buildroot.org/ and add your own package(s).

paulwratt commented 1 year ago

@HiraokaTakuya can you not edit the Docker file and add pkg-config or did you not want a full OS docker image?

(or is that docker file explicitly for building rust-musl-cross - you could try pulling pkg-config off an Alpine image)