-
Notifications
You must be signed in to change notification settings - Fork 83
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
Better API for cross-compilation support #347
Comments
Just a quick note here: Aliases are cumbersome as you can only alias targets, not full-blown external repositories. So you need to know all the bazel targets declared in a nixpkgs_package to alias them. |
@layus Yes, that's true - and annoying. Unfortunately, I'm not sure what a better approach may look like. Short of defining toolchains. |
I'm interesting in tackling this. I put together a hacky proof of concept of a pretty involved repository set up that works off of #240 where I can cross compile for linux x86_64 on my M1 macbook, and then run the resulting binaries in Docker using There are only minor changes required to rules_nixpkgs (namely, that the toolchain CPU for C++ is hard coded to the system CPU). I ended up with something like this in my
and in my bazelrc
For Linux only dependencies, I ended up writing a macro that looks like:
So I could define something like:
I we could write macros that could automatically handle the select() boiler plate as well if we want to have nixpkgs_package dependencies that depend on a config_setting or something? That said, initially I'd like to maybe take over #240 and fix the hardcoded CPU in There's probably a lot of cleanup that's viable in my set up, but I think this is a good start. WDYT? |
Hi @DolceTriade, cross compilation is something that comes up a lot since the M1 was released, so it's great that you're interested in tackling this issue.
I think this would be a good approach. Getting #240 merged has been on my list of things to do for a while — there were some conflicts but I just resolved them so I think it should be okay now. Feel free to open a PR based on that branch to fix the hardcoded CPU in If you feel like it, I think it would be great to add your proof of concept as an example here. Then we have something concrete to refer people to when they want to do cross compilation, even before we undertake the more lengthy task of improving the API. |
@DolceTriade #240 was just merged, so you can base your PR to fix the hardcoded CPU off |
Currently, we hardcode the CPU architecture of the toolchain to the host toolchain. However, this breaks cross compilation as we will probably want to set the CPU of the toolchain to the target architecture. The `cross_cpu` flag can be used to specify the target architecture. If the `cross_cpu` flag is not set, we will auto detect the host CPU architecture and use that for the toolchain. Is part of an effort to address tweag#347
Currently, we hardcode the CPU architecture of the toolchain to the host toolchain. However, this breaks cross compilation as we will probably want to set the CPU of the toolchain to the target architecture. The `cross_cpu` flag can be used to specify the target architecture. If the `cross_cpu` flag is not set, we will auto detect the host CPU architecture and use that for the toolchain. Is part of an effort to address tweag#347
Currently, we hardcode the CPU architecture of the toolchain to the host toolchain. However, this breaks cross compilation as we will probably want to set the CPU of the toolchain to the target architecture. The `cross_cpu` flag can be used to specify the target architecture. If the `cross_cpu` flag is not set, we will auto detect the host CPU architecture and use that for the toolchain. Is part of an effort to address tweag#347
Thanks for adding this! I'm currently trying this out for the Linux -> MacOS direction (both x86-64); one blocker I notice is that the cross-toolchain targeting darwin wants to to use the gold linker, which only works on ELF. As far as I can see, the problem is that the generated
which I think comes from the nix expression that generates the toolchain info, since it add that to the link-flags whenever ld.gold is available. I guess an extra needs need to be added that takes into account the target? |
Is your feature request related to a problem? Please describe.
In principle cross-compilation is already supported thanks to the nixpkgs
system
andtargetSystem
parameters. However this requires the user to write their own nix expressions and does not integrate nicely with how Bazel handles cross-compilation. Hence the need for a better API around this.Describe the solution you'd like
We can generate toolchain instances for a set of exec and target platform pairs and apply appropriate Bazel constraints automatically. This needs to be configurable. The nodejs toolchain is an example where this is somewhat supported.
For packages, we want to generate instances for a set of platforms. Build tool packages may incur separate exec and target constraints (i.e. a package with a binary that runs during the build and a shared library for the target platform). There should be an alias target that uses
select
to pick the appropriate package instance.Tasks
--platforms
passed into the various targets to get platform specific versions of nix packages #608The text was updated successfully, but these errors were encountered: