Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ jobs:
contents: read
steps:
- uses: actions/checkout@v4
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
libclang-dev \
clang \
llvm-dev \
gcc-multilib \
g++-multilib
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
Expand All @@ -37,4 +49,14 @@ jobs:
docker run --privileged --rm tonistiigi/binfmt --install arm64,amd64
docker buildx create --use --name cross-builder
- name: Build and push image
run: make docker-build-push
run: |
export LIBCLANG_PATH=/usr/lib/llvm-18/lib
export BINDGEN_EXTRA_CLANG_ARGS="-I/usr/include"
export CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc
export CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++
export AR_x86_64_unknown_linux_gnu=x86_64-linux-gnu-ar
export CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
export CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
export AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar
export PKG_CONFIG_ALLOW_CROSS=1
make docker-build-push
14 changes: 14 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[build]
# Custom Docker images with proper build environment for native dependencies

[target.x86_64-unknown-linux-gnu]
dockerfile = "Dockerfile.cross-x86_64"

[target.aarch64-unknown-linux-gnu]
dockerfile = "Dockerfile.cross-aarch64"

[build.env]
passthrough = [
"RUST_LOG",
"CARGO_TERM_COLOR",
]
27 changes: 27 additions & 0 deletions Dockerfile.cross-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ghcr.io/cross-rs/cross:main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For improved build reproducibility and stability in CI/CD pipelines, it's generally recommended to pin Docker base images to a specific version tag or a digest instead of using a mutable tag like main. While cross:main might be intended to be stable, a specific version (e.g., cross:0.2.x or cross@sha256:digest) would prevent unexpected build failures if the main tag is updated with breaking changes.


# Install ARM64 cross-compilation toolchain
RUN apt-get update && \
apt-get install -y \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
libc6-dev-arm64-cross \
pkg-config-aarch64-linux-gnu \
build-essential \
clang \
libclang-dev && \
rm -rf /var/lib/apt/lists/*

# Set up environment variables for ARM64 cross-compilation
# Keep host compiler for build scripts, only set target-specific variables
ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
ENV CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
ENV AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar
ENV STRIP_aarch64_unknown_linux_gnu=aarch64-linux-gnu-strip
ENV PKG_CONFIG_aarch64_unknown_linux_gnu=aarch64-linux-gnu-pkg-config
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
ENV BINDGEN_EXTRA_CLANG_ARGS="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV CFLAGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV CPPFLAGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV JEMALLOC_SYS_WITH_LG_PAGE=16
ENV PKG_CONFIG_ALLOW_CROSS=1
Comment on lines +15 to +27

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Environment-variable inconsistency will confuse Cross / bindgen

For x86_64 you used a target-scoped variable
BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu,
but here you set the global BINDGEN_EXTRA_CLANG_ARGS.
This value will bleed into all targets and host builds.

Align naming and avoid accidental host pollution:

-ENV BINDGEN_EXTRA_CLANG_ARGS="-I/usr/aarch64-linux-gnu/include -I/usr/include"
+ENV BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"

Do the same for CFLAGS / CPPFLAGS if you want them target-scoped.

πŸ“ Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Set up environment variables for ARM64 cross-compilation
# Keep host compiler for build scripts, only set target-specific variables
ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
ENV CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
ENV AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar
ENV STRIP_aarch64_unknown_linux_gnu=aarch64-linux-gnu-strip
ENV PKG_CONFIG_aarch64_unknown_linux_gnu=aarch64-linux-gnu-pkg-config
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
ENV BINDGEN_EXTRA_CLANG_ARGS="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV CFLAGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV CPPFLAGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV JEMALLOC_SYS_WITH_LG_PAGE=16
ENV PKG_CONFIG_ALLOW_CROSS=1
# Set up environment variables for ARM64 cross-compilation
# Keep host compiler for build scripts, only set target-specific variables
ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
ENV CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
ENV AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar
ENV STRIP_aarch64_unknown_linux_gnu=aarch64-linux-gnu-strip
ENV PKG_CONFIG_aarch64_unknown_linux_gnu=aarch64-linux-gnu-pkg-config
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
ENV BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV CFLAGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV CPPFLAGS_aarch64_unknown_linux_gnu="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV JEMALLOC_SYS_WITH_LG_PAGE=16
ENV PKG_CONFIG_ALLOW_CROSS=1
πŸ€– Prompt for AI Agents
In Dockerfile.cross-aarch64 around lines 15 to 27, the environment variables
BINDGEN_EXTRA_CLANG_ARGS, CFLAGS_aarch64_unknown_linux_gnu, and
CPPFLAGS_aarch64_unknown_linux_gnu are inconsistently scoped;
BINDGEN_EXTRA_CLANG_ARGS is set globally while others are target-scoped. To fix
this, rename BINDGEN_EXTRA_CLANG_ARGS to
BINDGEN_EXTRA_CLANG_ARGS_aarch64_unknown_linux_gnu to match the target-specific
pattern and similarly ensure CFLAGS and CPPFLAGS are consistently target-scoped
by using the appropriate target suffix in their variable names.

19 changes: 19 additions & 0 deletions Dockerfile.cross-x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM ghcr.io/cross-rs/cross:main

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the aarch64 Dockerfile, consider pinning the base image to a specific version tag or digest (e.g., ghcr.io/cross-rs/cross:0.2.x or cross@sha256:digest) instead of main. This practice enhances reproducibility and prevents potential issues arising from unexpected updates to the main tag.


# Install additional build tools and headers
RUN apt-get update && \
apt-get install -y \
build-essential \
pkg-config \
libclang-dev \
clang && \
rm -rf /var/lib/apt/lists/*

# Set up environment variables for x86_64 cross-compilation
ENV CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc
ENV CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++
ENV AR_x86_64_unknown_linux_gnu=x86_64-linux-gnu-ar
ENV STRIP_x86_64_unknown_linux_gnu=x86_64-linux-gnu-strip
ENV BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu="-I/usr/include -I/usr/include/x86_64-linux-gnu"
ENV CFLAGS_x86_64_unknown_linux_gnu="-I/usr/include -I/usr/include/x86_64-linux-gnu"
ENV CPPFLAGS_x86_64_unknown_linux_gnu="-I/usr/include -I/usr/include/x86_64-linux-gnu"