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

Add support for cross compilation in Bazel #2849

Closed
prestonvanloon opened this issue Jun 24, 2019 · 21 comments · Fixed by #4945
Closed

Add support for cross compilation in Bazel #2849

prestonvanloon opened this issue Jun 24, 2019 · 21 comments · Fixed by #4945
Labels
Help Wanted Extra attention is needed Priority: High High priority item

Comments

@prestonvanloon
Copy link
Member

prestonvanloon commented Jun 24, 2019

Currently, we're unable to build for other OS / architecture whenever the binary target depends on a cgo library. This includes any dependency on go-ethereum in the beacon-chain and potentially a future BLS library.

To reproduce the issue, try building the beacon chain with a different toolchain specified.

Building in on linux targeting windows:

bazel build --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //beacon-chain

Building on linux amd64 targeting arm64.

bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_arm64 //beacon-chain

Important caveats:

  • We're using a fork of go-ethereum which has the generated BUILD files to support bazel.
  • Removing cgo dependencies are not an option as we expect to have more cgo dependencies in the future. Pure go builds would be nice and we'd have support for windows / ARM from linux today if that were the case!
  • We must support linux -> [darwin_amd64, arm64, windows_amd64] targets. When you're writing cc toolchains, adding Mac OS as the host is optional, but appreciated (expect a bounty tip if Mac OS as host is supported!).
  • This is a pretty involved task. If you are up to taking it on, you'll be mostly on your own to figure it out. Good luck :)

These blocked issues may have some additional context from previous attempts to resolve this.

Blocking #654
Blocking #2546

@prestonvanloon prestonvanloon added Help Wanted Extra attention is needed Good For Bounty Priority: Medium Medium priority item labels Jun 24, 2019
@katzdan
Copy link
Contributor

katzdan commented Jun 26, 2019

Id' like to get into this one. Wanted to delve into Bazel for a while now.

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This issue now has a funding of 600.0 DAI (600.0 USD @ $1.0/DAI) attached to it.

@gitcoinbot
Copy link

gitcoinbot commented Jul 9, 2019

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


Workers have applied to start work.

These users each claimed they can complete the work by 3 months, 3 weeks from now.
Please review their action plans below:

1) suburbandad has applied to start work (Funders only: approve worker | reject worker).

Using https://github.com/emacski/tensorflow-serving-arm as an example, build cross compile configs for linux-arm64 and windows-x86_64, leveraging https://github.com/dockcross/dockcross as the build environment. The net result should be that any host execution with x86_64 architecture should be able to cross compile for windows_x86-64 and linux_arm64 targets.
2) thecydonian has applied to start work (Funders only: approve worker | reject worker).

I will first familiarize myself with the existing code, then I will research solutions to the problem. This seems potentially challenging, but I am willing to take it on, and I will not give up easily. If I am able to solve this, I will be sure to do so for MacOS as well.

I will make sure to keep you consistantly updated on my progress, and should be able to make signifigant progress over the weekend.

In the unlikely case that I do fail at fixing this issue. I will produce a write up with everything I found out while trying to do this bounty. Thank you for your consideration

Learn more on the Gitcoin Issue Details page.

@prestonvanloon
Copy link
Member Author

@lzxm160, it has to be bazel. We might be adding more complicated build logic that wouldn't be supported natively with gomod.

@coderbradlee
Copy link

@prestonvanloon sure,I'll try if you approve

@prestonvanloon
Copy link
Member Author

@lzxm160, I took a quick look at your profile on gitcoin and you have 3 abandoned tasks. I wouldn't want to award this task to you so that no one else has the opportunity to work on it then have it abandoned later.

Do you have a plan on how to do this? If you already know the solution then I'd accept it and award the bounty, but this is something that won't be easy for someone who isn't familiar with bazel toolchains.

@coderbradlee
Copy link

@prestonvanloon understand,I'll try first

@prestonvanloon
Copy link
Member Author

prestonvanloon commented Jul 15, 2019

To anyone interested in working on this, please build from branch spec-v0.6 unless #2312 is merged to master.

We've added some progress towards this goal with #2970. You can see the TODO here:

# Supported pairs of system and architecture. (GOOS, GOARCH).
binary_targets = [
("linux", "amd64"),
("linux", "arm64"),
# TODO(2849): Enable after cross OS compilation is supported.
# https://github.com/prysmaticlabs/prysm/issues/2849
# ("darwin", "amd64"),
# ("windows", "amd64"),
]

Suggested workflow here would be to uncomment those lines then build the following from linux:

  • //beacon-chain:beacon-chain-darwin-amd64
  • //beacon-chain:beacon-chain-windows-amd64

If both of those targets build on linux, then this issue can be resolved.

@3ach
Copy link
Contributor

3ach commented Oct 21, 2019

I tried building the darwin_amd64 and windows_amd64 rules on my machine and it worked fine. is this still an issue?

@prestonvanloon
Copy link
Member Author

This is resolved by toolchains in rules_go.

@prestonvanloon
Copy link
Member Author

Reopening this as we still have cross compile issues.

@prestonvanloon prestonvanloon added Priority: High High priority item Bounty and removed Priority: Medium Medium priority item labels Feb 14, 2020
@prestonvanloon
Copy link
Member Author

I have this script to build and upload multiple platform binaries here: https://gist.github.com/prestonvanloon/32fdec43aba8bd96c656739ada69a23e#file-build_and_upload-sh

To consider this issue resolved, we should be able to run the above script on linux and successfully build all four targets:

Host machine: linux amd64

Targets:

  • linux amd64
  • linux arm64
  • darwin amd64
  • windows amd64

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


The funding of this issue was increased to 1000.0 SAI (1000.0 USD @ $1.0/SAI) .

@SuburbanDad
Copy link
Contributor

I am working on a cross-compiling docker container and toolchains that will support cross compiling arm64, darwin and windows from any x86-64 machine that has docker installed.

So far I have docker images and toolchain branches for :

arm64/linux/clang10 -> successfully builds prysm beacon-chain and validator
x86_64/darwin/clang9 -> partial success; builds bls target but failing on beacon and validator
x86_64/win/clang10 -> no progress to report yet
Good progress, but still a ways out before a PR

@prestonvanloon
Copy link
Member Author

Awesome progress @SuburbanDad.

If possible, can you check in the ARM build? We can start providing arm64 docker images sooner

@SuburbanDad
Copy link
Contributor

If possible, can you check in the ARM build? We can start providing arm64 docker images sooner

I will get it into a committable state tonight and publish the MVP docker cross compiler image 👍

@SuburbanDad
Copy link
Contributor

PR submitted for all four working targets. 🎉

@prestonvanloon
Copy link
Member Author

Update: @SuburbanDad's PR meets all of the requirements of the bounty. In PR review, I asked if we could make use of bazel's remote build execution and/or docker sandbox. Over a few days of offline discussion, @SuburbanDad and I were able to connect the plumbing from PR #4945 into the bazel RBE and bazel docker sandbox functionality for cross compile.

So far, we are able to cross compile and confirm the following:

target linux_amd64 linux_arm64 osx_amd64 windows_amd64
//beacon-chain ✔️ docker-sandbox and RBE, libkafka supported locally only ✔️ docker-sandbox and RBE, no libkafka support ✔️ docker-sandbox, no libkafka support ✔️ docker-sandbox, no libkafka support
//validator ✔️ docker-sandbox and RBE ✔️ docker-sandbox and RBE ✔️ docker-sandbox ❌ Doesn't work. #5008

@SuburbanDad and I will work together to merge our changes into PR #4945 by the end of the week.This will enable us to leverage RBE in our continuous integration and more importantly provide signed executable binaries for each tagged release of Prysm's beacon-node and validator targets. 🎉

@prestonvanloon
Copy link
Member Author

@ceresstation This is good to go! Please release the bounty to @SuburbanDad

@gitcoinbot
Copy link

⚡️ A tip worth 1000.00000 SAI (1000.0 USD @ $1.0/SAI) has been granted to @SuburbanDad for this issue from @ceresstation. ⚡️

Nice work @SuburbanDad! Your tip has automatically been deposited in the ETH address we have on file.

@gitcoinbot
Copy link

Issue Status: 1. Open 2. Started 3. Submitted 4. Done


This Bounty has been completed.

Additional Tips for this Bounty:

  • ceresstation tipped 1000.0000 SAI worth 1000.0 USD to SuburbanDad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted Extra attention is needed Priority: High High priority item
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants