From 0326fe5d3b33e55684141f2e4bbe844da0f1c987 Mon Sep 17 00:00:00 2001 From: Gleb Popov <6yearold@gmail.com> Date: Mon, 18 May 2026 14:54:18 +0300 Subject: [PATCH] Add linux-loongarch64 make target, now that loongarch dockcross is available This is a follow-up to #526 --- Makefile | 5 +- docker/dockcross-loongarch64 | 200 +++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+), 1 deletion(-) create mode 100755 docker/dockcross-loongarch64 diff --git a/Makefile b/Makefile index dc63ba92..47ceb1ec 100644 --- a/Makefile +++ b/Makefile @@ -151,7 +151,7 @@ native: jni-header snappy-header $(NATIVE_DLL) native-nocmake: jni-header $(NATIVE_DLL) snappy: native $(TARGET)/$(snappy-jar-version).jar -native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x musl-image musl +native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-loongarch64 linux-ppc64le linux-riscv64 linux-s390x musl-image musl ifdef CI # Clean docker images within CI to avoid no space left error @@ -228,6 +228,9 @@ linux-android-arm: jni-header linux-android-aarch64: jni-header ./docker/dockcross-android-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native OS_NAME=Linux OS_ARCH=android-aarch64' +linux-loongarch64: jni-header + ./docker/dockcross-loongarch64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=loongarch64-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=loongarch64' + linux-ppc64le: jni-header ./docker/dockcross-ppc64le -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64le-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64le' diff --git a/docker/dockcross-loongarch64 b/docker/dockcross-loongarch64 new file mode 100755 index 00000000..89b2316b --- /dev/null +++ b/docker/dockcross-loongarch64 @@ -0,0 +1,200 @@ +#!/bin/bash + +DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-loongarch64 + +#------------------------------------------------------------------------------ +# Helpers +# +err() { + echo -e >&2 ERROR: $@\\n +} + +die() { + err $@ + exit 1 +} + +has() { + # eg. has command update + local kind=$1 + local name=$2 + + type -t $kind:$name | grep -q function +} + +#------------------------------------------------------------------------------ +# Command handlers +# +command:update-image() { + docker pull $FINAL_IMAGE +} + +help:update-image() { + echo Pull the latest $FINAL_IMAGE . +} + +command:update-script() { + if cmp -s <( docker run $FINAL_IMAGE ) $0; then + echo $0 is up to date + else + echo -n Updating $0 '... ' + docker run $FINAL_IMAGE > $0 && echo ok + fi +} + +help:update-image() { + echo Update $0 from $FINAL_IMAGE . +} + +command:update() { + command:update-image + command:update-script +} + +help:update() { + echo Pull the latest $FINAL_IMAGE, and then update $0 from that. +} + +command:help() { + if [[ $# != 0 ]]; then + if ! has command $1; then + err \"$1\" is not an dockcross command + command:help + elif ! has help $1; then + err No help found for \"$1\" + else + help:$1 + fi + else + cat >&2 < +ENDHELP + exit 1 + fi +} + +#------------------------------------------------------------------------------ +# Option processing +# +special_update_command='' +while [[ $# != 0 ]]; do + case $1 in + + --) + break + ;; + + --args|-a) + ARG_ARGS="$2" + shift 2 + ;; + + --config|-c) + ARG_CONFIG="$2" + shift 2 + ;; + + --image|-i) + ARG_IMAGE="$2" + shift 2 + ;; + update|update-image|update-script) + special_update_command=$1 + break + ;; + -*) + err Unknown option \"$1\" + command:help + exit + ;; + + *) + break + ;; + + esac +done + +# The precedence for options is: +# 1. command-line arguments +# 2. environment variables +# 3. defaults + +# Source the config file if it exists +DEFAULT_DOCKCROSS_CONFIG=~/.dockcross +FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}} + +[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG" + +# Set the docker image +FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}} + +# Handle special update command +if [ "$special_update_command" != "" ]; then + case $special_update_command in + + update) + command:update + exit $? + ;; + + update-image) + command:update-image + exit $? + ;; + + update-script) + command:update-script + exit $? + ;; + + esac +fi + +# Set the docker run extra args (if any) +FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}} + +# If we are not running via boot2docker +if [ -z $DOCKER_HOST ]; then + USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )" +fi + +#------------------------------------------------------------------------------ +# Now, finally, run the command in a container +# +docker run --rm \ + -v $PWD:/work \ + $USER_IDS \ + $FINAL_ARGS \ + $FINAL_IMAGE "$@" + +################################################################################ +# +# This image is not intended to be run manually. +# +# To create a dockcross helper script for the +# dockcross/linux-loongarch64 image, run: +# +# docker run --rm dockcross/linux-loongarch64 > dockcross-loongarch64 +# chmod +x dockcross-loongarch64 +# +# You may then wish to move the dockcross script to your PATH. +# +################################################################################