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

Define PKG_CONFIG_PATH in Docker images #404

Closed
gdesmott opened this issue Apr 7, 2020 · 7 comments · Fixed by #727
Closed

Define PKG_CONFIG_PATH in Docker images #404

gdesmott opened this issue Apr 7, 2020 · 7 comments · Fixed by #727

Comments

@gdesmott
Copy link
Contributor

gdesmott commented Apr 7, 2020

As stated on #149 (comment) one has to manually define PKG_CONFIG_PATH in their custom docker image in order to build Rust code relying on external libs.

Automatically defining it in the cross images would make things easier as users would just have to derive from the official images and install their extra packages.
Would you consider such change in the docker files?

@capnfabs
Copy link

capnfabs commented Oct 14, 2020

I just ran into this and agree that changing the docker images for this would be helpful. The fact that cross sets PKG_CONFIG_ALLOW_CROSS=1 in the env for the build without changing the path, set me up to make a mistake when building my own container: I installed both the host + target arch for a given lib, and then pkg-config picked the host arch.

In the end, my solution was to set PKG_CONFIG_LIBDIR in the Dockerfile, as per this article, so my Dockerfile now looks like this:

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

RUN dpkg --add-architecture armhf

RUN apt-get update && \
    apt-get install --assume-yes libasound2-dev:armhf libssl-dev:armhf

ENV PKG_CONFIG_LIBDIR=/usr/local/lib/arm-linux-gnueabihf/pkgconfig:/usr/lib/arm-linux-gnueabihf/pkgconfig

The advantage of PKG_CONFIG_LIBDIR over PKG_CONFIG_PATH is that it overrides what pkg-config selects by default, which means you can't accidentally link the host architecture version of something if you forget to install the target arch package.

@Crell
Copy link

Crell commented Nov 6, 2020

This seems to be causing issues with rust-openssl as well. I don't know the guts of Cross well enough to say what may be going on or how to fix it, but I can confirm the problem still exists.

@capnfabs
Copy link

capnfabs commented Nov 6, 2020

@Crell in case it's helpful to you (and others!), I kept digging into this after I left that comment, and have written a couple of in-depth blog posts about getting cross-compile working with system packages, they're here:

@zwhitchcox
Copy link

Is there a workaround?

@zwhitchcox
Copy link

I don't have the directory /usr/local/lib/arm-linux-gnueabihf/pkgconfig on my local computer

@zwhitchcox
Copy link

Ok, I'm able to buidl using the Dockerfile from @capnfabs

@zwhitchcox
Copy link

Was able to get this to work in the docker file.

Here's my file for aarch64 in case it helps anyone:

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

WORKDIR /home/src

RUN dpkg --add-architecture arm64

RUN apt-get update && \
    apt-get install --assume-yes libssl-dev:arm64

ENV PKG_CONFIG_LIBDIR=/usr/lib/aarch64-linux-gnu/pkgconfig

RUN curl https://sh.rustup.rs -sSf | \
    sh -s -- --default-toolchain stable -y

ENV PATH=/root/.cargo/bin:$PATH

RUN apt-get install libssl-dev pkg-config -y

COPY . .

CMD cargo build --release

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

Successfully merging a pull request may close this issue.

5 participants