Skip to content

Commit f9ebf17

Browse files
committed
Add linux-loongarch64 images
1 parent 4e74d3d commit f9ebf17

File tree

4 files changed

+159
-6
lines changed

4 files changed

+159
-6
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
ARG ROOTFS_DIR=/crossrootfs/loongarch64
2+
3+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-builder-amd64 AS builder
4+
ARG ROOTFS_DIR
5+
6+
RUN /scripts/eng/common/cross/build-rootfs.sh loongarch64 alpine3.20 --skipunmount
7+
8+
RUN TARGET_TRIPLE="loongarch64-alpine-linux-musl" && \
9+
cmake -S llvm-project.src/runtimes -B runtimes \
10+
-DCMAKE_BUILD_TYPE=Release \
11+
-DCMAKE_ASM_COMPILER=clang \
12+
-DCMAKE_C_COMPILER=clang \
13+
-DCMAKE_CXX_COMPILER=clang++ \
14+
-DCMAKE_ASM_COMPILER_TARGET="$TARGET_TRIPLE" \
15+
-DCMAKE_C_COMPILER_TARGET="$TARGET_TRIPLE" \
16+
-DCMAKE_CXX_COMPILER_TARGET="$TARGET_TRIPLE" \
17+
# We're going to link the static libraries we build here into PIC images, so build the static libraries as PIC.
18+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
19+
-DCMAKE_SYSROOT="$ROOTFS_DIR" \
20+
# Specify linker to use for exes directly for CMake toolchain detection
21+
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
22+
# Don't search for tools in the sysroot as we're cross-compiling
23+
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="NEVER" \
24+
-DLLVM_USE_LINKER=lld \
25+
-DLLVM_ENABLE_RUNTIMES="libcxx" \
26+
-DLIBCXX_ENABLE_SHARED=OFF \
27+
-DLIBCXX_HAS_MUSL_LIBC=ON \
28+
-DLIBCXX_CXX_ABI=libstdc++ \
29+
-DLIBCXX_CXX_ABI_INCLUDE_PATHS="$ROOTFS_DIR/usr/include/c++/14.2.0/;$ROOTFS_DIR/usr/include/c++/14.2.0/$TARGET_TRIPLE" && \
30+
cmake --build runtimes -j $(getconf _NPROCESSORS_ONLN) && \
31+
cmake --install runtimes --prefix "$ROOTFS_DIR/usr"
32+
33+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-llvm-amd64
34+
ARG ROOTFS_DIR
35+
36+
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ARG ROOTFS_DIR=/crossrootfs/loongarch64
2+
3+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-builder-amd64 AS builder
4+
ARG ROOTFS_DIR
5+
6+
# Install the latest debootstrap
7+
RUN tdnf remove -y debootstrap && \
8+
curl -fsL -o debootstrap.tar.gz https://deb.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.138.tar.gz && \
9+
echo "e8e8b72388b6e5ced65d1b5e69ce0b9e13f4813da0c328a52add57ee5f79430a debootstrap.tar.gz" | sha256sum -c - && \
10+
tar xzf debootstrap.tar.gz -C / && \
11+
ln -s /debootstrap/debootstrap -t /usr/local/bin && \
12+
rm -f debootstrap.tar.gz
13+
14+
# temp
15+
RUN rm -rf /scripts && git clone --depth 1 --single-branch https://github.com/am11/arcade -b patch-14 /scripts
16+
17+
RUN /scripts/eng/common/cross/build-rootfs.sh loongarch64 sid --skipunmount --skipsigcheck
18+
19+
RUN TARGET_TRIPLE="loongarch64-linux-gnu" && \
20+
CLANG_MAJOR_VERSION=$(clang --version | grep -oP "(?<=version )\d+") && \
21+
cmake -S llvm-project.src/runtimes -B runtimes \
22+
-DCMAKE_BUILD_TYPE=Release \
23+
-DCMAKE_ASM_COMPILER=clang \
24+
-DCMAKE_C_COMPILER=clang \
25+
-DCMAKE_CXX_COMPILER=clang++ \
26+
-DCMAKE_ASM_COMPILER_TARGET="$TARGET_TRIPLE" \
27+
-DCMAKE_C_COMPILER_TARGET="$TARGET_TRIPLE" \
28+
-DCMAKE_CXX_COMPILER_TARGET="$TARGET_TRIPLE" \
29+
# We're going to link the static libraries we build here into PIC images, so build the static libraries as PIC.
30+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
31+
-DCMAKE_SYSROOT="$ROOTFS_DIR" \
32+
# Specify linker to use for exes directly for CMake toolchain detection
33+
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
34+
# Don't search for tools in the sysroot as we're cross-compiling
35+
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="NEVER" \
36+
-DLLVM_USE_LINKER=lld \
37+
-DLLVM_ENABLE_RUNTIMES="libcxx;compiler-rt" \
38+
-DLIBCXX_ENABLE_SHARED=OFF \
39+
-DLIBCXX_CXX_ABI=libstdc++ \
40+
-DLIBCXX_CXX_ABI_INCLUDE_PATHS="$ROOTFS_DIR/usr/include/c++/13/;$ROOTFS_DIR/usr/include/$TARGET_TRIPLE" \
41+
-DCOMPILER_RT_CXX_LIBRARY="libcxx" \
42+
-DCOMPILER_RT_STATIC_CXX_LIBRARY=ON \
43+
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
44+
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
45+
# The libfuzzer build in LLVM doesn't correctly forward the required CMake properties to the "fuzzed libc++" build
46+
# so skip it here.
47+
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
48+
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
49+
-DCOMPILER_RT_INSTALL_PATH="/usr/local/lib/clang/$CLANG_MAJOR_VERSION" && \
50+
cmake --build runtimes -j $(getconf _NPROCESSORS_ONLN) && \
51+
cmake --install runtimes --prefix "$ROOTFS_DIR/usr"
52+
53+
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-llvm-amd64
54+
ARG ROOTFS_DIR
55+
56+
COPY --from=builder /usr/local/lib/clang /usr/local/lib/clang/
57+
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR

src/azurelinux/manifest.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,29 @@
650650
}
651651
]
652652
},
653+
{
654+
"platforms": [
655+
{
656+
"dockerfile": "src/azurelinux/3.0/net10.0/cross/loongarch64",
657+
"os": "linux",
658+
"osVersion": "azurelinux3.0",
659+
"tags": {
660+
"azurelinux-3.0-net10.0-cross-loongarch64": {}
661+
}
662+
}
663+
]
664+
}, {
665+
"platforms": [
666+
{
667+
"dockerfile": "src/azurelinux/3.0/net10.0/cross/loongarch64-musl",
668+
"os": "linux",
669+
"osVersion": "azurelinux3.0",
670+
"tags": {
671+
"azurelinux-3.0-net10.0-cross-loongarch64-musl": {}
672+
}
673+
}
674+
]
675+
},
653676
{
654677
"platforms": [
655678
{

src/ubuntu/build-scripts/install-cross-build-prereqs.sh

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ set -e
55
# Stop script if unbound variable found (use ${var:-} if intentional)
66
set -u
77

8-
# we need to make sure that we install binfmt >= 2.2.0 and qemu-user-static >= 1.4.2,
9-
# which are available in Ubuntu 20.04+ repositories
10-
. /etc/os-release
11-
if [ "$(echo "$VERSION_ID" | tr -d .)" -lt 2004 ]; then
12-
sed "s/$UBUNTU_CODENAME/focal/g" /etc/apt/sources.list | sudo dd of=/etc/apt/sources.list.d/focal.list
13-
fi
8+
# we need to use ubuntu repo for new architectures like qemu-loongarch64-static which are not available in microsoft sources
149

10+
# backup and create single source for this distro
11+
sudo mv /etc/apt/sources.list.d{,_}
12+
sudo mv /etc/apt/sources.list{,_}
13+
sudo mkdir /etc/apt/sources.list.d
14+
15+
sudo tee "/etc/apt/sources.list.d/ubuntu.sources" > /dev/null <<EOF
16+
Types: deb
17+
URIs: http://archive.ubuntu.com/ubuntu
18+
Suites: noble noble-updates noble-security
19+
Components: main restricted universe multiverse
20+
EOF
21+
22+
# Function to install necessary packages
1523
function installPkgs {
1624
sudo apt-get update
1725
# see (see https://github.com/dotnet/dotnet-buildtools-prereqs-docker/issues/120)
@@ -34,3 +42,32 @@ until installPkgs; do
3442
exit 1
3543
fi
3644
done
45+
46+
# restore the original sources
47+
sudo rm -rf /etc/apt/sources.list.d
48+
sudo mv /etc/apt/sources.list.d{_,}
49+
sudo mv /etc/apt/sources.list{_,}
50+
51+
docker version
52+
docker info
53+
echo testing
54+
ls /proc/sys/fs/binfmt_misc
55+
echo testing---1
56+
ls /usr/bin/qemu*
57+
echo testing---2
58+
qemu-riscv64-static --version
59+
echo cat binfmt
60+
cat /proc/sys/fs/binfmt_misc/status
61+
echo testing0
62+
for entry in /proc/sys/fs/binfmt_misc/*; do
63+
if [[ $(basename "$entry") != "status" && $(basename "$entry") != "register" ]]; then
64+
echo "=== $(basename "$entry") ==="
65+
cat "$entry"
66+
echo
67+
fi
68+
done
69+
echo testing---z
70+
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i ls /proc/sys/fs/binfmt_misc
71+
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh -c 'ls /usr/bin/qemu*'
72+
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i qemu-riscv64-static --version
73+
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i qemu-loongarch64-static --version

0 commit comments

Comments
 (0)