-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: Add s390x architecture support via cross-compilation #5300
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
Draft
Lan Yao (lyao-77)
wants to merge
2
commits into
master
Choose a base branch
from
feat/s390x-cross-compilation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+174
−0
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # syntax=docker/dockerfile:1 | ||
| # | ||
| # Cross-compilation Dockerfile for building librdkafka for s390x architecture | ||
| # Uses BuildKit cross-compilation with tonistiigi/xx toolkit to avoid QEMU slowness | ||
| # | ||
|
|
||
| ARG BASE_IMAGE=ubuntu:24.04 | ||
|
|
||
| # Cross-compilation helpers | ||
| FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.5.0 AS xx | ||
|
|
||
| # Build stage runs on native platform (AMD64), outputs s390x binaries | ||
| FROM --platform=$BUILDPLATFORM ${BASE_IMAGE} AS builder | ||
|
|
||
| COPY --from=xx / / | ||
|
|
||
| ARG TARGETPLATFORM | ||
| ARG LIBRDKAFKA_VERSION | ||
|
|
||
| # Install native build tools and cross-compilation toolchain | ||
| RUN NEEDRESTART_MODE=a apt-get update && apt-get install -y \ | ||
| wget curl python3 git build-essential \ | ||
| clang lld pkg-config \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install cross-compilation toolchain for s390x | ||
| RUN xx-apt-get install -y \ | ||
| gcc g++ libc6-dev \ | ||
| libssl-dev \ | ||
| libsasl2-dev \ | ||
| libcurl4-openssl-dev \ | ||
| zlib1g-dev \ | ||
| libzstd-dev \ | ||
| liblz4-dev | ||
|
|
||
| # Set up cross-compilation environment | ||
| ENV PKG_CONFIG_PATH=/usr/lib/$(xx-info)-linux-gnu/pkgconfig | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| # Copy source code | ||
| COPY . /build/ | ||
|
|
||
| # Configure for cross-compilation | ||
| # --host tells configure we're cross-compiling for s390x | ||
| # --enable-static builds static libraries | ||
| # We use system packages for dependencies (installed via xx-apt-get above) | ||
| # Must explicitly set CC, AR, etc. as configure doesn't pick up ENV vars reliably | ||
| RUN CC=$(xx-info)-gcc \ | ||
| CXX=$(xx-info)-g++ \ | ||
| AR=$(xx-info)-ar \ | ||
| RANLIB=$(xx-info)-ranlib \ | ||
| STRIP=$(xx-info)-strip \ | ||
| ./configure \ | ||
| --host=$(xx-info) \ | ||
| --prefix=/usr/local \ | ||
| --enable-static \ | ||
| --enable-strip \ | ||
| --enable-ssl \ | ||
| --enable-sasl \ | ||
| --enable-zstd \ | ||
| --enable-lz4-ext | ||
|
|
||
| # Build librdkafka | ||
| RUN make -j$(nproc) | ||
|
|
||
| # Run examples to verify build (using QEMU for this step) | ||
| RUN xx-verify --static src/librdkafka.a | ||
| RUN xx-verify src/librdkafka.so.1 | ||
|
|
||
| # Install to staging directory | ||
| RUN DESTDIR=/artifacts make install | ||
|
|
||
| # Show what was built | ||
| RUN ls -lh /artifacts/usr/local/lib/ | ||
| RUN file /artifacts/usr/local/lib/librdkafka.so.1 | ||
|
|
||
| # Final stage: Package the artifacts | ||
| FROM scratch AS artifacts | ||
| COPY --from=builder /artifacts / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Build librdkafka for s390x using cross-compilation | ||
| # | ||
| # This script uses Docker BuildKit with cross-compilation to build | ||
| # s390x binaries on AMD64 hosts, avoiding QEMU emulation issues. | ||
| # | ||
| # Usage: | ||
| # packaging/tools/build-s390x-cross.sh <output-tarball-path.tgz> | ||
| # | ||
| # Requirements: | ||
| # - Docker with BuildKit support | ||
| # - QEMU binfmt support (for verification only) | ||
| # | ||
|
|
||
| set -e | ||
|
|
||
| if [ $# -ne 1 ]; then | ||
| echo "Usage: $0 <output-path.tgz>" | ||
| echo "" | ||
| echo "Example:" | ||
| echo " $0 artifacts/librdkafka-s390x.tgz" | ||
| exit 1 | ||
| fi | ||
|
|
||
| output="$1" | ||
| output_dir=$(dirname "$output") | ||
| output_file=$(basename "$output") | ||
|
|
||
| # Ensure output directory exists | ||
| mkdir -p "$output_dir" | ||
|
|
||
| # Get absolute path for output | ||
| output_abs=$(cd "$output_dir" && pwd)/$output_file | ||
|
|
||
| echo "Building librdkafka for s390x using cross-compilation..." | ||
| echo "Output will be: $output_abs" | ||
|
|
||
| # Enable Docker BuildKit | ||
| export DOCKER_BUILDKIT=1 | ||
|
|
||
| # Build using cross-compilation Dockerfile | ||
| docker buildx build \ | ||
| --platform linux/s390x \ | ||
| --file packaging/tools/Dockerfile.s390x \ | ||
| --target artifacts \ | ||
| --output type=local,dest=/tmp/librdkafka-s390x-build \ | ||
| . | ||
|
|
||
| # Package the artifacts | ||
| echo "Packaging artifacts..." | ||
| cd /tmp/librdkafka-s390x-build | ||
| tar czf "$output_abs" . | ||
| cd - | ||
|
|
||
| # Clean up | ||
| rm -rf /tmp/librdkafka-s390x-build | ||
|
|
||
| # Emit SHA256 for verification | ||
| echo "" | ||
| echo "Build complete!" | ||
| echo "SHA256 $output:" | ||
| sha256sum "$output" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The artifact key 'p-librdkafka__plat-linux__dist-ubuntu__arch-s390x__lnk-all' suggests this build includes all linkage types, but the comment indicates it's building with gssapi, which is inconsistent with the naming. The build should either actually exclude gssapi (to match the 'lnk-all' naming convention) or the artifact key should be renamed to clarify that gssapi is included.