Cross-compile from Windows host to Linux-musl target not working for crate x11

I want to cross-compile as the title states. A not telling error is blocking me for compiling my project.

Followed a tutorial:

https://laptrinhx.com/an-example-of-cross-compiling-rust-apps-to-linux-on-windows-with-only-rustup-2854853859/#cross-compiling-to-linux

Which can be summarized as:

rustup target add x86_64-unknown-linux-musl

Then in "./cargo/config":

[target.x86_64-unknown-linux-musl]
linker = "rust-lld"

But build fails with:

> cargo build --target x86_64-unknown-linux-musl
   [... omitted for brevity ...]
   Compiling x11 v2.18.2
error: failed to run custom build command for `x11 v2.18.2`

Caused by:
  process didn't exit successfully: `C:\user\project\target\release\build\x11-c78bae3b1400f31f\build-script-build` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=X11_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: CrossCompilation', C:\user\.cargo\registry\src\github.com-1ecc6299db9ec823\x11-2.18.2\build.rs:36:67
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed

Found a similar question in StackOverflow: https://stackoverflow.com/q/61957621/2930101 but the error in that question is much more telling than my "value: CrossCompilation"

How can I fix the error?

Looks like there's a solution: https://github.com/erlepereira/x11-rs/issues/96#issuecomment-522299079

1 Like