-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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 to build aarch64 wheels and artifacts #8196
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
@dlj-NaN can you please review? |
I've updated to build python 3.9 artifacts also. |
+Josh for a second set of eyes. Where is this expected to be run? |
@dlj-NaN In the internal ci (Kokoro?) with arm64 hosts. EC2 has Graviton2 (*6g) instances. |
I think we should add support for building aarch64 linux wheels sooner than later and this PR is a great first step towards that, but protobuf team won't be able to make these wheels "official" until we also have some test coverage for protobuf python on aarch64. Here's what's IMHO our best way forward:
|
While the EC2 Graviton instances will be useful for running gRPC tests (and perhaps for protobuf tests as well, but we still need to evaluate the best approach here), I think it makes sense to try to build ARM64 wheels by crosscompiling them. The reasons why that seems better are explained in my other comment. Have you experimented with wheel crosscompilation? (It shouldn't be very different from building on a real ARM64 linux machine). |
I haven't experimented with cross compilations. Though I have compiled under emulation. From v1.8.0, cibuildwheel allows to build wheels of non-native architecture using I've got a working PR for scikit-image using cibuildwheel and Github Actions (x86_64): scikit-image/scikit-image#5197 Though protobuf is structured differently, would running under emulation with cibuildwheel work as a solution? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://cibuildwheel.readthedocs.io/en/stable/options/#archs
I haven't experimented with cross compilations. Though I have compiled under emulation.
From v1.8.0, cibuildwheel allows to build wheels of non-native architecture using
CIBW_ARCHS_LINUX
. See https://cibuildwheel.readthedocs.io/en/stable/options/#archs for more details about it.I've got a working PR for scikit-image using cibuildwheel and Github Actions (x86_64): scikit-image/scikit-image#5197
Though protobuf is structured differently, would running under emulation with cibuildwheel work as a solution?
Building the wheel under an emulator is one of the options, but the biggest concern here is the speed of build. Protobuf's codebase is not small so the concern is whether the python wheel build will become very slow.
If the wheel build under emulator takes a few minutes, it would be a nice option, but if it takes e.g. 30mins, that wouldn't be acceptable I think. If we do use an emulator, we should just build off of quay.io/pypa/manylinux2014_aarch64
@@ -0,0 +1,7 @@ | |||
FROM quay.io/pypa/manylinux2014_aarch64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tried that out yet, but dockcross/manylinux2014-aarch64
should be a good start for being able to build aarch64 wheels on a x64 machine.
https://github.com/dockcross/dockcross
IIURC, the build process should be very similar to what's currently in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jtattermusch I've been trying to run with dockcross/manylinux2014-aarch64. I've run into issues with the protoc binary built. Error:
../src/protoc: line 117: /io/protobuf/src/.libs/lt-protoc: cannot execute binary file
../src/protoc: line 117: /io/protobuf/src/.libs/lt-protoc: Success
Generating google/protobuf/descriptor_pb2.py...
I checked the issues tab and found #3912 with a similar error signature. But that looks like it has been taken care of. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dlj-NaN Any suggestions on the cross compilation? Ran into the binary file issue. It continues with 'Success' but abruptly fails after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cross-compilation is not something I would expect to work as-is.
If everything runs under the target platform (hardware or emulator) -- and this means not just the Python build, but everything, starting from ./configure
-- then the build steps should work. It sounds like like your investigation was based on building the regular protobuf runtime (the part built by make
) for a different target (probably x86_64?).
A cross-build would instead have to build the protobuf runtime both for the target and the host running the build. In theory, this is possible... but it is very difficult to do (as you see).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dlj-NaN Currently I am running everything under dockcross/manylinux2014-aarch64.
In kokoro/release/python/linux/build_artifacts.sh if I set DOCKER_IMAGE to dockcross/manylinux2014-aarch64, multibuild will pull it in and use it to run everything from configure, to wheel building, to repair.
I had to modify the ./configure => ./configure --host=aarch64-linux-gnu (while building protoc) as part of the pre-build process in multibuild specified in kokoro/release/python/linux/config.sh
Immediately after, when running python setup.py build_py is when I run into the error. I've made sure that the env
PROTOC is set to pwd
/src/protoc. setup.py looks for it before anything.
The host is x86_64 and dockcross cross compiles for aarch64 using manylinux2014-aarch64.
@@ -17,11 +17,16 @@ if [ $# -lt 3 ]; then | |||
exit 1 | |||
fi | |||
|
|||
ARCH=`uname -m` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this file is now obsolete (I'm not 100% sure though): #8250
I've also experimented with crosscompiling the python wheels using the
This way the binary wheel build succeeds and all the native code gets crosscompiled correctly (both libprotobuf.a and the python extension) and all of the changes above would be quite easy to integrate into the existing script for building python wheels. Unfortunately there is two issue I've discovered:
I think both the issues I've ran into are fixable but the question is whether the fix would overly complicate the wheel build or not. |
As an aside, to test the whether the native extension works I came up with this little script: |
Update: looks like I've been able to successfully crosscompile an aarch64 wheel (in a way that's reasonably clean and integrates well with the existing script for building python wheels) and the wheel seems to work well on a real ARM machine and it passes the I'll try to put together a PR that demonstrates what I've done soon (hopefully tomorrow). |
Ok, looks like I've been able to solve all the remaining challenges in crosscompiling the python wheels and I now have a ready-to-review PR: #8280 |
Assuming this is no longer needed? |
Add support to build kokoro artifacts and python wheels