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

Use of bindgen #49

Closed siscia closed 6 years ago

siscia commented 6 years ago

Hi,

thanks for this amazing docker file, it was really helpful.

In my project I use bindgen which requires:

llvm-3.9-dev libclang-3.9-dev clang-3.9

Can we install them in the docker file?

They increase sensibly the overall size of the image.

I can go ahead and provide a PR if needed.

emk commented 6 years ago

That's an excellent idea! I'd really love to have those packages, and a PR would be welcome.

Do you have any idea how many MBs those packages add to the image? I suppose that we should check this first. :-)

siscia commented 6 years ago

I am working on it now.

From what I can see:

rust@0dcb273013b1:~/src$ sudo apt-get install llvm-3.9-dev libclang-3.9-dev clang-3.9                                                                                   
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  binfmt-support libclang-common-3.9-dev libclang1-3.9 libffi-dev libllvm3.9 libobjc-5-dev libobjc4 libpipeline1 libpython-stdlib libpython2.7-minimal
  libpython2.7-stdlib libtinfo-dev llvm-3.9 llvm-3.9-runtime mime-support python python-minimal python2.7 python2.7-minimal
Suggested packages:
  gnustep gnustep-devel clang-3.9-doc llvm-3.9-doc python-doc python-tk python2.7-doc
The following NEW packages will be installed:
  binfmt-support clang-3.9 libclang-3.9-dev libclang-common-3.9-dev libclang1-3.9 libffi-dev libllvm3.9 libobjc-5-dev libobjc4 libpipeline1 libpython-stdlib
  libpython2.7-minimal libpython2.7-stdlib libtinfo-dev llvm-3.9 llvm-3.9-dev llvm-3.9-runtime mime-support python python-minimal python2.7 python2.7-minimal
0 upgraded, 22 newly installed, 0 to remove and 0 not upgraded.
Need to get 97.1 MB of archives.
After this operation, 628 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

I am not sure if those 628MB will be reduced once we put everything inside the docker image, but I am quite pessimistic.

emk commented 6 years ago

That's big! I really want to support bindgen, but that's pretty large relative to the rest of the image.

One possible approach would be to add the following to your project's Dockerfile:

FROM ekidd/rust-musl-builder:latest

RUN apt-get update && \
    apt-get install -y \
        clang-3.9 \
        libclang-3.9-dev \
        llvm-3.9-dev \
        && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# ADD your sources, specify a CMD, etc.

This would be enough to allow you to test the idea.

Alternatively, we could build a second set of images including bindgen, plus all the stuff we normally include. Also, how well does bindgen work with libmusl? Do you need to do anything special to set it up, like configuring an LLVM cross compiler or something like that?

siscia commented 6 years ago

I believe the options you provided are quite clear and the best way forward.

Thanks for your time. I am closing the issue now.