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-compiling for s390x platform #9455

Merged
merged 10 commits into from Mar 23, 2023

Conversation

haubenr
Copy link
Contributor

@haubenr haubenr commented Aug 18, 2022

This PR adds s390x binaries to the maven artifacts published for this component. This PR builds on changes that were added with #6441 and #9284

Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
@haubenr
Copy link
Contributor Author

haubenr commented Aug 18, 2022

@ejona86 Can you please take a look at this? Should be pretty straightforward.

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Aug 18, 2022
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Aug 18, 2022
@ejona86
Copy link
Member

ejona86 commented Aug 18, 2022

Uhh... this isn't the sort of build failure I was expecting:

  CXX      google/protobuf/compiler/importer.lo
  CXX      google/protobuf/compiler/parser.lo
  CXX      google/protobuf/descriptor.lo
  CXX      google/protobuf/descriptor.pb.lo
google/protobuf/generated_message_tctable_lite.cc: In static member function 'static const char* google::protobuf::internal::TcParser::MiniParse(google::protobuf::MessageLite*, const char*, google::protobuf::internal::ParseContext*, const google::protobuf::internal::TcParseTableBase*, uint64_t, google::protobuf::internal::TcFieldData)':
google/protobuf/generated_message_tctable_lite.cc:342:1: internal compiler error: output_operand: invalid %-code
 }
 ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions.
Makefile:4514: recipe for target 'google/protobuf/generated_message_tctable_lite.lo' failed
make[2]: *** [google/protobuf/generated_message_tctable_lite.lo] Error 1

(I triggered a rebuild; we'll see if it is consistent.)

@haubenr
Copy link
Contributor Author

haubenr commented Aug 19, 2022

Thanks for taking a look! I tested the protobuf compilation on two servers - one running Ubuntu 22.04.1 LTS on x86_64 and the other one running Ubuntu 18.04.6 LTS on s390x.

On x86_64, the installed cross-compilation binary for s390x outputs this:

$ s390x-linux-gnu-g++ --version
s390x-linux-gnu-g++ (Ubuntu 11.2.0-17ubuntu1) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

On s390x where cross-compilation isn't needed g++ compiler reports this:

$ g++ --version
g++ (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

With this compiler, protobuf doesn't built natively on s390x but fails with the same error message we get from this PR's build run. On the x86_64 server the cross compilation works just fine and the build produces the binary as expected.

I suspect that the compiler package is of importance - it would seem that one needs the latest and greatest version to be able to compile protobuf for s390x, even in a cross compilation scenario. Which Ubuntu version is the PR build server running?

@haubenr
Copy link
Contributor Author

haubenr commented Aug 19, 2022

Experimented some more... the key is the compiler version - g++-7 is not able to compile the protobuf source code. One must upgrade to g++-11 to succeed. On my s390x server I did this:

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt update && sudo apt install gcc-11 g++-11
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 110 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-11 --slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-11 --slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-11
sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-11 110

After that, the build for protobuf succeeds.

Not sure how to deal with this for the cross-compilation package for Ubuntu... on Ubuntu 22.04.1 LTS it would seem you get a compatible compiler when running apt-get install g++-s390x-linux-gnu. On older Ubuntu release this is likely not the case.

Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
@haubenr
Copy link
Contributor Author

haubenr commented Aug 19, 2022

I fixed the issue - turns out g++ version 8.x is able to compile protobuf for s390x.

Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
@haubenr
Copy link
Contributor Author

haubenr commented Aug 19, 2022

Nope, that didn't work... looks like g++ version 11.x is required for building protobuf for s390x. Unfortunately this compiler package is only available on Ubuntu 22.04 LTS.

Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
@haubenr
Copy link
Contributor Author

haubenr commented Aug 19, 2022

@ejona86 Sorry for all the back and forth... I've introduced a somewhat substantial change to the build mechanism by utilizing a dedicated Ubuntu 22.04 LTS Docker container for building the s390x artifacts. This solves the dependency issue for GCC/G++ version 11.x without the need of any modifications to the underlying build server.

If you think this approach makes sense all protobuf-related artifact builds could be handled via this container: arm64, ppc64le, s390x and even x86_64 (in that case it would replace the CentOS-based Docker image).

@haubenr
Copy link
Contributor Author

haubenr commented Aug 24, 2022

@ejona86 Could you please take another look? Thanks!

@dilipgb
Copy link

dilipgb commented Mar 8, 2023

@ejona86 any update on this?

@dilipgb
Copy link

dilipgb commented Mar 20, 2023

@ejona86 I'm looking for s390x support for one of our component and this comes as hard dependency. Please let us know if there are any changes needed before merge. Any input from you will be helpful in speed up our implementation.

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Mar 20, 2023
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry this has languished. We've got a work item to upgrade the kokoro environment we're using, as I think it is 16.04, and I didn't expect it to draw out like it has. I didn't realize you had swapped to the dockerfile. I think that is the right approach.

I've made one comment, which I can take or leave.

set -exu -o pipefail

# first we need to install the prerequisites required for s390x cross compilation
apt-get update && apt-get install -y g++-s390x-linux-gnu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to install g++-s390x-linux-gnu within the Dockerfile.

If we do that, do we need this build_s390x_artifacts_in_docker.sh any more? "$GRPC_JAVA_DIR"/buildscripts/run_in_docker.sh grpc-java-artifacts-x86 SKIP_TESTS=true ARCH=s390_64 /grpc-java/buildscripts/kokoro/unix.sh might just work.

(And that's making me want to remove build_artifacts_in_docker.sh, because we can simply run docker twice.)

@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Mar 20, 2023
@larry-safran larry-safran merged commit 99cbdd5 into grpc:master Mar 23, 2023
5 checks passed
larry-safran pushed a commit to larry-safran/grpc-java that referenced this pull request Mar 29, 2023
* Added s390x platform support
* Adapt to existing platform naming scheme
* Updated s390_64 library whitelist
* Use g++ compiler version 8.x for s390x
* Introduced dedicated Docker container for building s390x artifacts Minor fix

---------

Signed-off-by: Dirk Haubenreisser <haubenr@de.ibm.com>
Co-authored-by: Eric Anderson <ejona@google.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants