emk / rust-musl-builder

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static versions of useful C libraries. Supports openssl and diesel crates.
Apache License 2.0
1.54k stars 193 forks source link

Question: Why PG_CONFIG set to non static version? #86

Closed iav closed 4 years ago

iav commented 4 years ago

Why set PG_CONFIG_X86_64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config , not just builded /usr/local/musl/bin/pg_config?

emk commented 4 years ago

When cross-compiling Rust code using an Ubuntu host and a musl-libc target, rustc actually needs to compile code for two different architectures.

  1. build.rs and macro code are compiled for the host Ubuntu system.
  2. Application code is compiled for the target system.

Carefully setting up environment variables to support (1) and (2) is tricky. In this case, pg_config is needed by build.rs scripts which run at build time on the host. This is why there's a X86_64_UNKNOWN_LINUX_GNU in the variable PG_CONFIG_X86_64_UNKNOWN_LINUX_GNU. That information specified that when running pg_config in the host environment, to use the copy in /usr/bin.