Cross-compiling from Mac OS to Linux docker image

1,931 views
Skip to first unread message

Hyrum Wright

unread,
Oct 25, 2017, 9:38:16 AM10/25/17
to bazel-discuss
I'm working on getting Bazel to build statically-linked binaries which will run in a linux docker image, from a Mac OS X host.

This seems like something somebody else would have done before.  Before I go through the process of digging into what bits of additional CROSSTOOL configuration I would need, as well as the compiler, libraries and include files for the target system, has anybody done this before and would like to share the appropriate configuration?  If not, are there any pointers from the community which would make this task easier?

For reference, I've looked at https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain which describes how to write the appropriate CROSSTOOL file, but handwaves over how to get the relevant target libraries and include files installed for an arbitrary platform.  I intend to use Clang, which can easily generate code for the linux target, but I'm not sure where to put the relevant libraries and headers so bazel can find them.

Thanks,
-Hyrum

Chris

unread,
Nov 2, 2017, 1:25:17 PM11/2/17
to bazel-discuss
Hi Hyrum,

Did you ever get this to work? I'm currently facing the same issue - trying to get bazel on OS X to use a C++ toolchain that's in a docker container.

Thanks

Hyrum Wright

unread,
Nov 2, 2017, 1:39:06 PM11/2/17
to Chris, bazel-discuss
Chris,
I have not gotten this to work (though I haven't put much time into the problem recently).

I know most of the core bazel team is at a summit this week, and a conference next week.  There's also been a promise of an update to the instructions on writing a custom crosstool (see https://groups.google.com/d/msg/bazel-discuss/DfbqtrH95g0/pQTtooYmAwAJ).  My plan was to wait a couple of weeks, and then ping again to see if people had the cycles to give some advice.

However, if you've figured this out, I'd be happy to validate your solution. :)

-Hyrum

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/c73beca7-6523-4faf-8f89-52d550ab0cde%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hyrum Wright

unread,
Nov 3, 2017, 4:40:09 PM11/3/17
to Chris, bazel-discuss
Using the new wiki at https://github.com/bazelbuild/bazel/wiki/Yet-Another-CROSSTOOL-Writing-Tutorial, I've managed to get at least a few steps down the path.  My current Hello World results are here: https://github.com/hwright/hello-bazel-docker

I'm still struggling to get the underlying compiler to find the system headers for the target platform, however.  All the tutorials online assume that the crosscompiling environment is already available as a tarball from some third-party, but that's not the case here.

Hopefully somebody from the core team can take a look and let me know where my CROSSTOOL is wrong.

nher...@google.com

unread,
Nov 6, 2017, 10:14:41 AM11/6/17
to bazel-discuss
I've run into the same, trying to run the e2e tests for bazelbuild/rules_docker on a Mac OS X host. Not seeing this, I posted https://stackoverflow.com/questions/47120292/how-do-i-install-linux-crosstool-compilers-for-bazel-via-brew. I had only been fumbling around with using --crosstool_top=@bazel_tools//tools/cpp:default-toolchain --cpu=k8, but that gives an error about unknown flag -fno-canonical-system-headers and I'm seriously unsure as to whether it's an appropriate approach to begin with (does default-toolchain imply linux?).

Nathan Herring

unread,
Nov 10, 2017, 3:27:21 AM11/10/17
to bazel-discuss
Not sure if this works for you, but given I'm trying to work with rules_docker and that relies on local Docker installation, I wonder if a Docker-image-hosted toolchain could be used (e.g., https://github.com/dockcross/dockcross). i.e., have a set of bazel toolchain targets that invoke docker with the associated crosstool linux image you want?

On Mon, Nov 6, 2017 at 4:14 PM, <nher...@google.com> wrote:
I've run into the same, trying to run the e2e tests for bazelbuild/rules_docker on a Mac OS X host. Not seeing this, I posted https://stackoverflow.com/questions/47120292/how-do-i-install-linux-crosstool-compilers-for-bazel-via-brew. I had only been fumbling around with using --crosstool_top=@bazel_tools//tools/cpp:default-toolchain --cpu=k8, but that gives an error about unknown flag -fno-canonical-system-headers and I'm seriously unsure as to whether it's an appropriate approach to begin with (does default-toolchain imply linux?).



--
Nathan Herring | Software Engineer | nher...@google.com | 616-466-4646

rodr...@google.com

unread,
Nov 10, 2017, 4:40:53 AM11/10/17
to bazel-discuss
You could also consider using dazel to run bazel inside a Debian docker container. I found it easy to get started with, but I've run into some issues (eg file permissions, as bazel runs as root inside the container).

https://github.com/nadirizr/dazel

Marcel Hlopko

unread,
Nov 17, 2017, 3:20:36 AM11/17/17
to rodr...@google.com, ngir...@google.com, bazel-discuss
+Nicolas Lopez who has "some" ;) experience with writing docker C++ toolchains.



On Fri, Nov 10, 2017 at 10:40 AM rodrigoq via bazel-discuss <bazel-...@googlegroups.com> wrote:
You could also consider using dazel to run bazel inside a Debian docker container. I found it easy to get started with, but I've run into some issues (eg file permissions, as bazel runs as root inside the container).

https://github.com/nadirizr/dazel

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/369f7c1b-9a63-439b-97ea-534da1748968%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Hyrum Wright

unread,
Dec 6, 2017, 11:33:07 AM12/6/17
to Marcel Hlopko, rodr...@google.com, ngir...@google.com, bazel-discuss
Any additional insight here?

On Fri, Nov 17, 2017 at 3:20 AM, 'Marcel Hlopko' via bazel-discuss <bazel-...@googlegroups.com> wrote:
+Nicolas Lopez who has "some" ;) experience with writing docker C++ toolchains.
On Fri, Nov 10, 2017 at 10:40 AM rodrigoq via bazel-discuss <bazel-discuss@googlegroups.com> wrote:
You could also consider using dazel to run bazel inside a Debian docker container. I found it easy to get started with, but I've run into some issues (eg file permissions, as bazel runs as root inside the container).

https://github.com/nadirizr/dazel

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
--
-- 
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | GermanyGeschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAFuL9G%3DhybOtuxOs%2BjHSWA4PdCQ8Jzur47J-0B676%2BAOfVt-aQ%40mail.gmail.com.

emaildev...@gmail.com

unread,
Nov 7, 2018, 1:00:57 PM11/7/18
to bazel-discuss
On Wednesday, October 25, 2017 at 6:38:16 AM UTC-7, Hyrum Wright wrote:
i , did you get this to work ? I am facing similar situation as well
Reply all
Reply to author
Forward
0 new messages