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

Building crate with dependency on libclang? #45

Closed davechallis closed 6 years ago

davechallis commented 6 years ago

Is this something that is possible using this Docker image?

Currently trying to build something that depends on findshlibs (0.4.0), which fails to build using the latest rust-musl-builder image.

Minimal example:

Cargo.toml

[package]
name = "ftest"
version = "0.1.0"

[dependencies]
findshlibs = "0.4.0"

main.rs

fn main() {
    println!("Hello, world!");
}

Then building with:

docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder cargo build

eventually fails with:

   ... packages omitted ...
   Compiling clap v2.31.2
   Compiling thread_local v0.3.5
   Compiling cexpr v0.2.3
   Compiling findshlibs v0.4.0
error: failed to run custom build command for `findshlibs v0.4.0`
process didn't exit successfully: `/home/rust/src/target/debug/build/findshlibs-82fc297a20c1d8dd/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any of [\'libclang.so\', \'libclang.so.*\', \'libclang-*.so\'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (skipped: [])"', libcore/result.rs:945:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

So wondering if I can use a custom Dockerfile to make those libraries available when building? Or whether the above is just masking some other issue.

davechallis commented 6 years ago

After some experimenting, fixed by installing additional packages before compilation, e.g.:

FROM ekidd/rust-musl-builder:1.25.0 AS builder
COPY . ./
RUN sudo apt-get update && sudo apt-get install -y libclang-3.9 clang-3.9 llvm-3.9
RUN sudo chown -R rust:rust /home/rust && cargo build --release