Skip to content

Commit 337f857

Browse files
authored
Merge pull request #127 from infosiftr/arm64-host
Support building on an arm64 host too
2 parents 6ad8af5 + f689a8d commit 337f857

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
*.sh
55
.dockerignore
66
.git*
7+
.host-arch
78
Dockerfile*
89
LICENSE

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.host-arch

Dockerfile.build

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM debian:bookworm-slim
33

44
RUN set -eux; \
55
apt-get update; \
6+
dpkgArch="$(dpkg --print-architecture)"; \
67
apt-get install -y --no-install-recommends \
78
ca-certificates \
89
gnupg \
@@ -12,6 +13,8 @@ RUN set -eux; \
1213
libc6-dev \
1314
make \
1415
\
16+
# these are all "arch:all" so we can just install all of them
17+
libc6-dev-amd64-cross \
1518
libc6-dev-arm64-cross \
1619
libc6-dev-armel-cross \
1720
libc6-dev-armhf-cross \
@@ -21,7 +24,9 @@ RUN set -eux; \
2124
libc6-dev-riscv64-cross \
2225
libc6-dev-s390x-cross \
2326
\
24-
gcc-aarch64-linux-gnu \
27+
# the cross-compilers are particular about which architectures they build for, so for now we'll only support a host architecture of amd64 or arm64
28+
$([ "$dpkgArch" = 'amd64' ] || echo 'gcc-x86-64-linux-gnu') \
29+
$([ "$dpkgArch" = 'arm64' ] || echo 'gcc-aarch64-linux-gnu') \
2530
gcc-arm-linux-gnueabi \
2631
gcc-arm-linux-gnueabihf \
2732
gcc-i686-linux-gnu \
@@ -54,44 +59,43 @@ RUN set -eux; \
5459
WORKDIR /usr/src/hello
5560
COPY . .
5661

62+
# the following steps are grouped into "architecture families" and roughly ordered in a descending compatibility way such that we end up with the most accurate ".host-arch" symlink we can reasonably get
63+
5764
RUN set -ex; \
5865
make clean all test \
5966
TARGET_ARCH='amd64' \
6067
CROSS_COMPILE='x86_64-linux-gnu-' \
6168
ARCH_TEST='amd64'
62-
6369
RUN set -ex; \
6470
make clean all test \
65-
TARGET_ARCH='arm32v5' \
66-
CROSS_COMPILE='arm-linux-gnueabi-' \
67-
# EXTRA_CFLAGS='-march=armv5te' \
68-
ARCH_TEST='armel'
71+
TARGET_ARCH='i386' \
72+
CROSS_COMPILE='i686-linux-gnu-' \
73+
ARCH_TEST='i386'
6974

7075
RUN set -ex; \
7176
make clean all test \
72-
TARGET_ARCH='arm32v6' \
73-
CROSS_COMPILE='arm-linux-gnueabi-' \
74-
EXTRA_CFLAGS='-march=armv6+fp' \
75-
ARCH_TEST='armhf'
77+
TARGET_ARCH='arm64v8' \
78+
CROSS_COMPILE='aarch64-linux-gnu-' \
79+
ARCH_TEST='arm64'
7680

7781
RUN set -ex; \
7882
make clean all test \
7983
TARGET_ARCH='arm32v7' \
8084
CROSS_COMPILE='arm-linux-gnueabihf-' \
8185
# EXTRA_CFLAGS='-march=armv7-a+fp' \
8286
ARCH_TEST='armhf'
83-
8487
RUN set -ex; \
8588
make clean all test \
86-
TARGET_ARCH='arm64v8' \
87-
CROSS_COMPILE='aarch64-linux-gnu-' \
88-
ARCH_TEST='arm64'
89-
89+
TARGET_ARCH='arm32v6' \
90+
CROSS_COMPILE='arm-linux-gnueabi-' \
91+
EXTRA_CFLAGS='-march=armv6+fp' \
92+
ARCH_TEST='armhf'
9093
RUN set -ex; \
9194
make clean all test \
92-
TARGET_ARCH='i386' \
93-
CROSS_COMPILE='i686-linux-gnu-' \
94-
ARCH_TEST='i386'
95+
TARGET_ARCH='arm32v5' \
96+
CROSS_COMPILE='arm-linux-gnueabi-' \
97+
# EXTRA_CFLAGS='-march=armv5te' \
98+
ARCH_TEST='armel'
9599

96100
RUN set -ex; \
97101
make clean all test \
@@ -118,6 +122,6 @@ RUN set -ex; \
118122
CROSS_COMPILE='s390x-linux-gnu-' \
119123
ARCH_TEST='s390x'
120124

121-
RUN find \( -name 'hello' -or -name 'hello.txt' \) -exec file '{}' + -exec ls -lh '{}' +
125+
RUN find \( -name 'hello' -or -name 'hello.txt' -or -name '.host-arch' \) -exec file '{}' + -exec ls -lh '{}' +
122126

123-
CMD ["./amd64/hello-world/hello"]
127+
CMD [".host-arch/hello-world/hello"]

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ test: $(C_TARGETS)
5555
if [ -n "$$ARCH_TEST" ] && command -v arch-test > /dev/null && arch-test "$$ARCH_TEST" > /dev/null; then \
5656
( set -x && "./$$b" ); \
5757
( set -x && "./$$b" | grep -q '"'"$$(basename "$$(dirname "$$b")")"'"' ); \
58+
if [ ! -e .host-arch ] && arch-test -n "$$ARCH_TEST" > /dev/null; then \
59+
ln -svfT "$${b%%/*}" .host-arch; \
60+
fi; \
5861
else \
5962
echo >&2 "warning: $$TARGET_ARCH ($$ARCH_TEST) not supported; skipping test"; \
6063
fi; \

update.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -x
88
docker build -f Dockerfile.build -t hello-world:build .
99

1010
find */ \( -name hello -or -name hello.txt \) -delete
11-
docker run --rm hello-world:build sh -c 'find \( -name hello -or -name hello.txt \) -print0 | xargs -0 tar --create' | tar --extract --verbose
11+
docker run --rm hello-world:build sh -c 'find \( -name hello -or -name hello.txt -or -name .host-arch \) -print0 | xargs -0 tar --create' | tar --extract --verbose
1212

1313
find -name hello -type f -exec dirname '{}' ';' | xargs -n1 -i'{}' cp Dockerfile-linux.template '{}/Dockerfile'
1414
find -name hello.txt -type f -exec dirname '{}' ';' | xargs -n1 -i'{}' cp Dockerfile-windows.template '{}/Dockerfile'
@@ -20,7 +20,7 @@ for h in */*/nanoserver-*/Dockerfile; do
2020
sed -i 's!FROM .*!FROM mcr.microsoft.com/windows/nanoserver:'"$nano"'!' "$h"
2121
done
2222

23-
for h in amd64/*/hello; do
23+
for h in .host-arch/*/hello; do
2424
d="$(dirname "$h")"
2525
b="$(basename "$d")"
2626
"$h" > /dev/null

0 commit comments

Comments
 (0)