Repository: rust-cross/rust-musl-cross (language: rust)

Issue:
Can't build with x86_64-musl around pkg-config
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 ?  



Discussion / hints:
I don't know much about pkg-config, I'm afraid I'm unable to help you.
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/](https://buildroot.org/) and add your own package(s).
@HiraokaTakuya can you not edit the [Docker file](https://github.com/messense/rust-musl-cross/blob/master/Dockerfile) 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)

Fix patch:
diff --git a/Dockerfile b/Dockerfile
index 1cbe12a..fd0f1c0 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -65,6 +65,12 @@ ENV TARGET_RANLIB=$TARGET-ranlib
 ENV TARGET_HOME=/usr/local/musl/$TARGET
 ENV TARGET_C_INCLUDE_PATH=$TARGET_HOME/include/
 
+# pkg-config cross compilation support
+ENV TARGET_PKG_CONFIG_ALLOW_CROSS=1
+ENV TARGET_PKG_CONFIG_SYSROOT_DIR=$TARGET_HOME
+ENV TARGET_PKG_CONFIG_PATH=$TARGET_HOME/lib/pkgconfig:/usr/local/musl/lib/pkgconfig
+ENV TARGET_PKG_CONFIG_LIBDIR=$TARGET_PKG_CONFIG_PATH
+
 # We'll build our libraries in subdirectories of /home/rust/libs.  Please
 # clean up when you're done.
 WORKDIR /home/rust/libs


Test patch: