Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bindgen seems to don't work inside cross containers #257

Closed
siscia opened this issue Feb 14, 2019 · 9 comments
Closed

bindgen seems to don't work inside cross containers #257

siscia opened this issue Feb 14, 2019 · 9 comments

Comments

@siscia
Copy link

siscia commented Feb 14, 2019

Hi,

I am trying to use cross to build a project which requires bindgen.

If I build the process directly from cross, bindgen is not able to find the needed library (namely libclang.so), however, if I start the same container and clone the repo inside, everything works just fine.

What can be the causes?
Open similar issue on bindgen: rust-lang/rust-bindgen#1411 (comment)

@jamesmunns
Copy link
Contributor

@siscia this sounds a bit like a problem with your PATH variable. I'm guessing you might be using two different shells when using the container. I think by default docker uses the Dash shell, and you (or cross) might be using Bash instead.

Maybe in both cases, try adding the following to the procedure, and see if your outputs are different?

# print the current shell, one of these should work
echo $0
echo $SHELL

# print the current path variable
echo $PATH

@siscia
Copy link
Author

siscia commented Feb 14, 2019

Sorry, I wrote very badly.

So, if I execute

cross build --target `....`

The build process start but it broke as soon as it need the libclang libraries.

While if I run the same container, the I git clone the repo, and finally I use the standard cargo build everything works.

I am not quite sure how to print the SHELL and the PATH variable while executing cross.

I agree that it may be the problem though...

@siscia
Copy link
Author

siscia commented Feb 14, 2019

Sorry, it seems that everything is just fixed using a different docker image.

@siscia siscia closed this as completed Feb 14, 2019
@hug-dev
Copy link

hug-dev commented Oct 30, 2019

Hi @siscia
We have the exact same problem, using bindgen in our build script, it complains that it can not find libclang.so.

Just for reference: which Docker image were you using that worked? If you remember, I know it was some times ago 😃

@siscia
Copy link
Author

siscia commented Oct 30, 2019

Sorry guys, really no idea at all... :(

@hug-dev
Copy link

hug-dev commented Oct 30, 2019

For future reference: we created a new Dockerfile with the following content to make bindgen work inside cross:

FROM rustembedded/cross:aarch64-unknown-linux-gnu-0.1.16

RUN apt-get update && \
    apt-get install -y clang libclang-dev libc6-dev-i386

@Nnubes256
Copy link

Nnubes256 commented Mar 21, 2021

Very late to the party, but: some images (in my case, arm-unknown-linux-gnueabi-0.2.1) are still on Ubuntu 16.04.

In these cases, it seems the latest version of Clang available on Ubuntu's official repositories is still 3.8, which is incompatible with current versions of bindgen, as it requires Clang 3.9. I've somewhat hastily constructed an image that fixes this by fetching from LLVM's own repository:

FROM rustembedded/cross:arm-unknown-linux-gnueabi-0.2.1

RUN dpkg --add-architecture arm && \
    apt-get update && \
    apt-get install -y apt-transport-https wget && \
    (wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -) && \
    printf "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main\ndeb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main" > /etc/apt/sources.list.d/backports.list && \
    apt-get update && \
    apt-get install -y llvm-3.9-dev libclang-3.9-dev clang-3.9 && \
    apt-get purge -y apt-transport-https wget

@timstokman
Copy link

To get bindgen working, all I did was use this docker image:

FROM rustembedded/cross:armv7-unknown-linux-gnueabihf-0.2.1

RUN apt-get update && apt-get install --assume-yes libclang-3.9-dev

Just libclang-3.9-dev is enough.

@Alexhuszagh
Copy link
Contributor

This is now extensively documented on the wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants