Closed Bug 1337895 Opened 3 years ago Closed 3 years ago

Allow cross-compiling rust crates


(Firefox Build System :: General, defect)

Other Branch
Not set


(firefox54 fixed)

Tracking Status
firefox54 --- fixed


(Reporter: kats, Assigned: kats)




(1 file)

Right now if you try to do a linux32 taskcluster build, the job runs on a linux64 machine in AWS, so we are effectively cross-compiling from linux64 to linux32. If you then try to build rust code that uses the pkg-config crate, it fails because in the default configuration pkg-config throws an error if it detects cross-compilation [1].

Right now we're not hitting this scenario in any of our builds, but if we try to enable 32-bit linux QuantumRender builds, we hit this problem. An example error can be seen in bug 1336479 comment 1. I suspect the mozjs-sys crate will have the same problem if built for linux32 in automation, because it also uses libc which uses pkg-config.

The solution seems to be pretty simple: set the PKG_CONFIG_ALLOW_CROSS=1 environment variable, and pkg-config is happy. I verified that doing this fixes the linux32-qr builds as well. 

froydnj and I were talking about something similar on IRC yesterday--we should find a way to ensure that -sys crates we're linking aren't pulling in extraneous copies of libs that we already have in Gecko, or adding new dependencies on system libraries. For example, the mozjs-sys crate uses libz-sys, and Gecko already ships a zlib. That might be fine for standalone JS builds, but for Gecko we should definitely not be linking against system zlib.
That seems a bit orthogonal, but I agree. In the case of extraneous copies of libs that we already have, I guess it's up to whoever is adding the code, or the reviewer, to catch that and try to avoid it. In the webrender case we were at one point pulling in servo-freetype-sys which is all of freetype. We no longer do that - we discovered we didn't really need it for anything and so we were able to add a feature that made that dependency optional.

In the "linking against system libs" case again for webrender we have that problem, and we had to explicitly add stuff to a file [1] to allow the build to work. I presume these cases should be easier to catch since it requires explicitly capturing.

Comment on attachment 8835027 [details]
Bug 1337895 - Make the pkg-config rust crate happy when cross-compiling.
Attachment #8835027 - Flags: review?(nfroyd) → review+
Pushed by
Make the pkg-config rust crate happy when cross-compiling. r=froydnj
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.