Skip to content

Commit

Permalink
Add linux-loongarch64 images
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Dec 22, 2024
1 parent 4e74d3d commit 92e5375
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 5 deletions.
36 changes: 36 additions & 0 deletions src/azurelinux/3.0/net10.0/cross/loongarch64-musl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ARG ROOTFS_DIR=/crossrootfs/loongarch64

FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-builder-amd64 AS builder
ARG ROOTFS_DIR

RUN /scripts/eng/common/cross/build-rootfs.sh loongarch64 alpine3.20 --skipunmount

RUN TARGET_TRIPLE="loongarch64-alpine-linux-musl" && \
cmake -S llvm-project.src/runtimes -B runtimes \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ASM_COMPILER=clang \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_ASM_COMPILER_TARGET="$TARGET_TRIPLE" \
-DCMAKE_C_COMPILER_TARGET="$TARGET_TRIPLE" \
-DCMAKE_CXX_COMPILER_TARGET="$TARGET_TRIPLE" \
# We're going to link the static libraries we build here into PIC images, so build the static libraries as PIC.
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_SYSROOT="$ROOTFS_DIR" \
# Specify linker to use for exes directly for CMake toolchain detection
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
# Don't search for tools in the sysroot as we're cross-compiling
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="NEVER" \
-DLLVM_USE_LINKER=lld \
-DLLVM_ENABLE_RUNTIMES="libcxx" \
-DLIBCXX_ENABLE_SHARED=OFF \
-DLIBCXX_HAS_MUSL_LIBC=ON \
-DLIBCXX_CXX_ABI=libstdc++ \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS="$ROOTFS_DIR/usr/include/c++/14.2.0/;$ROOTFS_DIR/usr/include/c++/14.2.0/$TARGET_TRIPLE" && \
cmake --build runtimes -j $(getconf _NPROCESSORS_ONLN) && \
cmake --install runtimes --prefix "$ROOTFS_DIR/usr"

FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-llvm-amd64
ARG ROOTFS_DIR

COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
57 changes: 57 additions & 0 deletions src/azurelinux/3.0/net10.0/cross/loongarch64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
ARG ROOTFS_DIR=/crossrootfs/loongarch64

FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-builder-amd64 AS builder
ARG ROOTFS_DIR

# Install the latest debootstrap
RUN tdnf remove -y debootstrap && \
curl -fsL -o debootstrap.tar.gz https://deb.debian.org/debian/pool/main/d/debootstrap/debootstrap_1.0.138.tar.gz && \
echo "e8e8b72388b6e5ced65d1b5e69ce0b9e13f4813da0c328a52add57ee5f79430a debootstrap.tar.gz" | sha256sum -c - && \
tar xzf debootstrap.tar.gz -C / && \
ln -s /debootstrap/debootstrap -t /usr/local/bin && \
rm -f debootstrap.tar.gz

# temp
RUN rm -rf /scripts && git clone --depth 1 --single-branch https://github.com/am11/arcade -b patch-14 /scripts

RUN /scripts/eng/common/cross/build-rootfs.sh loongarch64 sid --skipunmount --skipsigcheck

RUN TARGET_TRIPLE="loongarch64-linux-gnu" && \
CLANG_MAJOR_VERSION=$(clang --version | grep -oP "(?<=version )\d+") && \
cmake -S llvm-project.src/runtimes -B runtimes \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_ASM_COMPILER=clang \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DCMAKE_ASM_COMPILER_TARGET="$TARGET_TRIPLE" \
-DCMAKE_C_COMPILER_TARGET="$TARGET_TRIPLE" \
-DCMAKE_CXX_COMPILER_TARGET="$TARGET_TRIPLE" \
# We're going to link the static libraries we build here into PIC images, so build the static libraries as PIC.
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_SYSROOT="$ROOTFS_DIR" \
# Specify linker to use for exes directly for CMake toolchain detection
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
# Don't search for tools in the sysroot as we're cross-compiling
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM="NEVER" \
-DLLVM_USE_LINKER=lld \
-DLLVM_ENABLE_RUNTIMES="libcxx;compiler-rt" \
-DLIBCXX_ENABLE_SHARED=OFF \
-DLIBCXX_CXX_ABI=libstdc++ \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS="$ROOTFS_DIR/usr/include/c++/13/;$ROOTFS_DIR/usr/include/$TARGET_TRIPLE" \
-DCOMPILER_RT_CXX_LIBRARY="libcxx" \
-DCOMPILER_RT_STATIC_CXX_LIBRARY=ON \
-DCOMPILER_RT_BUILD_SANITIZERS=OFF \
-DCOMPILER_RT_BUILD_MEMPROF=OFF \
# The libfuzzer build in LLVM doesn't correctly forward the required CMake properties to the "fuzzed libc++" build
# so skip it here.
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF \
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
-DCOMPILER_RT_INSTALL_PATH="/usr/local/lib/clang/$CLANG_MAJOR_VERSION" && \
cmake --build runtimes -j $(getconf _NPROCESSORS_ONLN) && \
cmake --install runtimes --prefix "$ROOTFS_DIR/usr"

FROM mcr.microsoft.com/dotnet-buildtools/prereqs:azurelinux-3.0-net10.0-crossdeps-llvm-amd64
ARG ROOTFS_DIR

COPY --from=builder /usr/local/lib/clang /usr/local/lib/clang/
COPY --from=builder $ROOTFS_DIR $ROOTFS_DIR
23 changes: 23 additions & 0 deletions src/azurelinux/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,29 @@
}
]
},
{
"platforms": [
{
"dockerfile": "src/azurelinux/3.0/net10.0/cross/loongarch64",
"os": "linux",
"osVersion": "azurelinux3.0",
"tags": {
"azurelinux-3.0-net10.0-cross-loongarch64": {}
}
}
]
}, {
"platforms": [
{
"dockerfile": "src/azurelinux/3.0/net10.0/cross/loongarch64-musl",
"os": "linux",
"osVersion": "azurelinux3.0",
"tags": {
"azurelinux-3.0-net10.0-cross-loongarch64-musl": {}
}
}
]
},
{
"platforms": [
{
Expand Down
47 changes: 42 additions & 5 deletions src/ubuntu/build-scripts/install-cross-build-prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ set -e
# Stop script if unbound variable found (use ${var:-} if intentional)
set -u

# we need to make sure that we install binfmt >= 2.2.0 and qemu-user-static >= 1.4.2,
# which are available in Ubuntu 20.04+ repositories
# we need to use ubuntu repo for new architectures like qemu-loongarch64-static which are not available in microsoft sources

# backup and create single source for this distro
find /etc/apt
sudo mv /etc/apt/sources.list.d{,_}
sudo mkdir /etc/apt/sources.list.d

. /etc/os-release
if [ "$(echo "$VERSION_ID" | tr -d .)" -lt 2004 ]; then
sed "s/$UBUNTU_CODENAME/focal/g" /etc/apt/sources.list | sudo dd of=/etc/apt/sources.list.d/focal.list
fi
sudo tee "/etc/apt/sources.list.d/ubuntu.sources" > /dev/null <<EOF
Types: deb
URIs: http://archive.ubuntu.com/ubuntu
Suites: ${UBUNTU_CODENAME} ${UBUNTU_CODENAME}-updates ${UBUNTU_CODENAME}-security
Components: main restricted universe multiverse
EOF

# Function to install necessary packages
function installPkgs {
sudo apt-get update
# see (see https://github.com/dotnet/dotnet-buildtools-prereqs-docker/issues/120)
Expand All @@ -34,3 +43,31 @@ until installPkgs; do
exit 1
fi
done

# restore the original sources
sudo rm -rf /etc/apt/sources.list.d
sudo mv /etc/apt/sources.list.d{_,}

docker version
docker info
echo testing
ls /proc/sys/fs/binfmt_misc
echo testing---1
ls /usr/bin/qemu*
echo testing---2
qemu-riscv64-static --version
echo cat binfmt
cat /proc/sys/fs/binfmt_misc/status
echo testing0
for entry in /proc/sys/fs/binfmt_misc/*; do
if [[ $(basename "$entry") != "status" && $(basename "$entry") != "register" ]]; then
echo "=== $(basename "$entry") ==="
cat "$entry"
echo
fi
done
echo testing---z
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i ls /proc/sys/fs/binfmt_misc
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh -c 'ls /usr/bin/qemu*'
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i qemu-riscv64-static --version
docker run --rm --privileged --pid=host debian nsenter -t 1 -m -u -n -i qemu-loongarch64-static --version

0 comments on commit 92e5375

Please sign in to comment.