Skip to content
Merged
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 @@ -27,6 +27,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 @@ -40,4 +52,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.

high

Using the main tag for the base image can lead to non-reproducible builds. Pinning the base image to a specific, stable tag (e.g., a release version) ensures build consistency.

FROM ghcr.io/cross-rs/cross:v0.2.5


# 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 && \
Comment on lines +5 to +12

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

Using --no-install-recommends with apt-get install reduces the final image size by preventing the installation of optional packages.

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        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/*

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 +17 to +27

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

Combining multiple ENV instructions and using a variable for repeated values improves readability and reduces Docker image layers.

ENV AARCH64_INCLUDE_PATH="-I/usr/aarch64-linux-gnu/include -I/usr/include"
ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
    CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++ \
    AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar \
    STRIP_aarch64_unknown_linux_gnu=aarch64-linux-gnu-strip \
    PKG_CONFIG_aarch64_unknown_linux_gnu=aarch64-linux-gnu-pkg-config \
    CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
    BINDGEN_EXTRA_CLANG_ARGS="${AARCH64_INCLUDE_PATH}" \
    CFLAGS_aarch64_unknown_linux_gnu="${AARCH64_INCLUDE_PATH}" \
    CPPFLAGS_aarch64_unknown_linux_gnu="${AARCH64_INCLUDE_PATH}" \
    JEMALLOC_SYS_WITH_LG_PAGE=16 \
    PKG_CONFIG_ALLOW_CROSS=1

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.

high

Using the main tag for the base image can lead to non-reproducible builds. Pinning the base image to a specific, stable tag (e.g., a release version) ensures build consistency.

FROM ghcr.io/cross-rs/cross:v0.2.5


# Install additional build tools and headers
RUN apt-get update && \
apt-get install -y \
build-essential \
pkg-config \
libclang-dev \
clang && \
Comment on lines +5 to +9

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

Using --no-install-recommends with apt-get install reduces the final image size by preventing the installation of optional packages.

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        build-essential \
        pkg-config \
        libclang-dev \
        clang && \
    rm -rf /var/lib/apt/lists/*

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"
Comment on lines +13 to +19

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

Combining multiple ENV instructions and using a variable for repeated values improves readability and reduces Docker image layers.

ENV X86_64_INCLUDE_PATH="-I/usr/include -I/usr/include/x86_64-linux-gnu"
ENV CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc \
    CXX_x86_64_unknown_linux_gnu=x86_64-linux-gnu-g++ \
    AR_x86_64_unknown_linux_gnu=x86_64-linux-gnu-ar \
    STRIP_x86_64_unknown_linux_gnu=x86_64-linux-gnu-strip \
    BINDGEN_EXTRA_CLANG_ARGS_x86_64_unknown_linux_gnu="${X86_64_INCLUDE_PATH}" \
    CFLAGS_x86_64_unknown_linux_gnu="${X86_64_INCLUDE_PATH}" \
    CPPFLAGS_x86_64_unknown_linux_gnu="${X86_64_INCLUDE_PATH}"