rust-cross / rust-musl-cross

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

Unconditionally setting CC and C_INCLUDE_PATH breaks crosscompiling ring/rocket_codegen #10

Closed weiznich closed 6 years ago

weiznich commented 6 years ago

Setting CC and C_INCLUDE_PATH unconditionally breaks compiling ring as dependency of rocket_codegen while cross compiling to another architecture (e.g. from x86_64 to arm). The ring build script will fail with error messages complaining that the -m64 switch is unknown on the arm-unknown-linux-musleabi crosscompiler. The underlying issue is that ring is build twice, once for usage in the codegen compilerplugin and once for usage in the final binary. This means ring must be build for the target and host. Ring tries to use the compiler provided by the environment, so setting unconditionally CC will cause ring to use that compiler everywhere. Building for the host-platform may not work while crosscompiling.

The solution is to set TARGET_CC to the compiler of the target platform and let CC unspecified.

messense commented 6 years ago

I am not sure what has changed in ring, but last time I used this to build kafka-view it worked.

What version of Rocket are you using?

weiznich commented 6 years ago

I've tried Rocket 0.3.6 and 0.3.8. Both are using ring 0.11.0.

jan-auer commented 6 years ago

We also ran into this issue, just with backtrace-sys. To provide some more context on this issue:

The CC environment variable is picked up when compiling both build dependencies and normal dependencies. However, build dependencies must be compiled for the host architecture and normal dependencies for the target architecture (obviously). The problem is the mismatch between the target triple when compiling the build dependency (mostly x86_64-unknown-linux-gnu) and the CC environment variable (which is based on the target).

I assume this might have worked before because the build dependencies probably have changed and might not have required invoking a c compiler before.

Anyway, the solution is to set the $TARGET_CC environment variable, as @weiznich has already said in his original post. Workaround for now:

docker run -e "CC=" -e "TARGET_CC=$TARGET-gcc" ...