Skip to content

Commit

Permalink
Add experimental ARM cross compile image based on zigbuild
Browse files Browse the repository at this point in the history
Currently it can successfully cross compile and link shared OpenSSL, and
cross compile the query engine, but linking fails with:

```
error: linking with `/root/.cache/cargo-zigbuild/0.16.10/zigcc-aarch64-unknown-linux-gnu.2.17.sh` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/opt/zig-linux-x86_64-0.11.0-dev.3348+3faf376b0:/opt/cross/zig-linux-x86_64-0.11.0-dev.3348+3faf376b0:/root/.cargo/bin:/usr/local/lib/python3.11/dist-packages/ziglang:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "/root/.cache/cargo-zigbuild/0.16.10/zigcc-aarch64-unknown-linux-gnu.2.17.sh" "/tmp/rustcELa8b4/symbols.o" "/engines/target/aarch64-unknown-linux-gnu/release/deps/query_engine-9d1919b2d160d96a.query_engine.d22a280a-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/engines/target/aarch64-unknown-linux-gnu/release/deps" "-L" "/engines/target/release/deps" "-L" "/engines/target/aarch64-unknown-linux-gnu/release/build/ring-297fc3656113f209/out" "-L" "/engines/target/aarch64-unknown-linux-gnu/release/build/libsqlite3-sys-af7b3a4558256ab0/out" "-L" "/engines/target/aarch64-unknown-linux-gnu/release/build/libz-sys-27081a34b01142db/out/lib" "-L" "/engines/target/aarch64-unknown-linux-gnu/release/build/libz-sys-27081a34b01142db/out/lib" "-L" "/opt/cross/lib" "-L" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/tmp/rustcELa8b4/libring-634b5236e555c431.rlib" "/tmp/rustcELa8b4/liblibsqlite3_sys-c0f45f8017beeed7.rlib" "/tmp/rustcELa8b4/liblibz_sys-36ff76decbe5dfac.rlib" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib/libcompiler_builtins-25887170a022cc00.rlib" "-Wl,-Bdynamic" "-lssl" "-lcrypto" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/root/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/engines/target/aarch64-unknown-linux-gnu/release/deps/query_engine-9d1919b2d160d96a" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-all" "-nodefaultlibs"
  = note: ld.lld: error: undefined symbol: fcntl@GLIBC_2.2.5
          >>> referenced by sqlite3.c
          >>>               sqlite3.o:(aSyscall) in archive /tmp/rustcELa8b4/liblibsqlite3_sys-c0f45f8017beeed7.rlib
          >>> did you mean: fcntl
          >>> defined in: /root/.cache/zig/o/09512143defbe5a5bbd3426ded948a1a/libpthread.so.0
```
  • Loading branch information
aqrln committed Jun 2, 2023
1 parent 8b2d2ef commit c7b2f6b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions cross/linux-glibc-arm64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM debian:bookworm

RUN apt-get -y update && apt-get -y upgrade
RUN apt-get -y install curl git

ARG ZIG_VERSION=0.11.0-dev.3348+3faf376b0
RUN cd /opt && curl -O https://ziglang.org/builds/zig-linux-x86_64-${ZIG_VERSION}.tar.xz && \
tar xJf zig-linux-x86_64-${ZIG_VERSION}.tar.xz
ENV PATH=/opt/zig-linux-x86_64-${ZIG_VERSION}:$PATH

ENV PATH=/root/.cargo/bin:$PATH
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
RUN rustup target add aarch64-unknown-linux-gnu

RUN cargo install cargo-zigbuild

ENV CC="zig cc -target aarch64-linux-gnu.2.17"
ENV CXX="zig c++ -target aarch64-linux-gnu.2.17"
ENV AS="zig as -target aarch64-linux-gnu.2.17"
ENV AR="zig ar"
ENV RANLIB="zig ranlib"

ARG OPENSSL_1_1_VERSION=1.1.1u
ARG OPENSSL_3_0_VERSION=3.0.9

# Accepts 1.1.x or 3.0.x as a build arg
# ARG OPENSSL_VARIANT=3.0.x

ENV OPENSSL_VERSION=${OPENSSL_3_0_VERSION}

RUN curl -fLO https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz && \
tar xzf openssl-$OPENSSL_VERSION.tar.gz

RUN cd openssl-$OPENSSL_VERSION && \
./Configure shared linux-aarch64 no-tests --prefix=/opt/cross --openssldir=/opt/cross && \
make -j8 && make install_sw install_ssldirs

ENV OPENSSL_DIR=/opt/cross

0 comments on commit c7b2f6b

Please sign in to comment.