Skip to content

Commit 40dc3a4

Browse files
committed
Add linux-loongarch64 make target, now that loongarch dockcross is available
This is a follow-up to #526
1 parent b68e18d commit 40dc3a4

2 files changed

Lines changed: 204 additions & 1 deletion

File tree

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ native: jni-header snappy-header $(NATIVE_DLL)
151151
native-nocmake: jni-header $(NATIVE_DLL)
152152
snappy: native $(TARGET)/$(snappy-jar-version).jar
153153

154-
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x musl-image musl
154+
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-loongarch64 linux-ppc64le linux-riscv64 linux-s390x musl-image musl
155155

156156
ifdef CI
157157
# Clean docker images within CI to avoid no space left error
@@ -228,6 +228,9 @@ linux-android-arm: jni-header
228228
linux-android-aarch64: jni-header
229229
./docker/dockcross-android-arm64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native OS_NAME=Linux OS_ARCH=android-aarch64'
230230

231+
linux-loongarch64: jni-header
232+
./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'
233+
231234
linux-ppc64le: jni-header
232235
./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'
233236

docker/dockcross-loongarch64

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#!/bin/bash
2+
3+
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-loongarch64
4+
5+
#------------------------------------------------------------------------------
6+
# Helpers
7+
#
8+
err() {
9+
echo -e >&2 ERROR: $@\\n
10+
}
11+
12+
die() {
13+
err $@
14+
exit 1
15+
}
16+
17+
has() {
18+
# eg. has command update
19+
local kind=$1
20+
local name=$2
21+
22+
type -t $kind:$name | grep -q function
23+
}
24+
25+
#------------------------------------------------------------------------------
26+
# Command handlers
27+
#
28+
command:update-image() {
29+
docker pull $FINAL_IMAGE
30+
}
31+
32+
help:update-image() {
33+
echo Pull the latest $FINAL_IMAGE .
34+
}
35+
36+
command:update-script() {
37+
if cmp -s <( docker run $FINAL_IMAGE ) $0; then
38+
echo $0 is up to date
39+
else
40+
echo -n Updating $0 '... '
41+
docker run $FINAL_IMAGE > $0 && echo ok
42+
fi
43+
}
44+
45+
help:update-image() {
46+
echo Update $0 from $FINAL_IMAGE .
47+
}
48+
49+
command:update() {
50+
command:update-image
51+
command:update-script
52+
}
53+
54+
help:update() {
55+
echo Pull the latest $FINAL_IMAGE, and then update $0 from that.
56+
}
57+
58+
command:help() {
59+
if [[ $# != 0 ]]; then
60+
if ! has command $1; then
61+
err \"$1\" is not an dockcross command
62+
command:help
63+
elif ! has help $1; then
64+
err No help found for \"$1\"
65+
else
66+
help:$1
67+
fi
68+
else
69+
cat >&2 <<ENDHELP
70+
Usage: dockcross [options] [--] command [args]
71+
72+
By default, run the given *command* in an dockcross Docker container.
73+
74+
The *options* can be one of:
75+
76+
--args|-a Extra args to the *docker run* command
77+
--image|-i Docker cross-compiler image to use
78+
--config|-c Bash script to source before running this script
79+
80+
81+
Additionally, there are special update commands:
82+
83+
update-image
84+
update-script
85+
update
86+
87+
For update command help use: $0 help <command>
88+
ENDHELP
89+
exit 1
90+
fi
91+
}
92+
93+
#------------------------------------------------------------------------------
94+
# Option processing
95+
#
96+
special_update_command=''
97+
while [[ $# != 0 ]]; do
98+
case $1 in
99+
100+
--)
101+
break
102+
;;
103+
104+
--args|-a)
105+
ARG_ARGS="$2"
106+
shift 2
107+
;;
108+
109+
--config|-c)
110+
ARG_CONFIG="$2"
111+
shift 2
112+
;;
113+
114+
--image|-i)
115+
ARG_IMAGE="$2"
116+
shift 2
117+
;;
118+
update|update-image|update-script)
119+
special_update_command=$1
120+
break
121+
;;
122+
-*)
123+
err Unknown option \"$1\"
124+
command:help
125+
exit
126+
;;
127+
128+
*)
129+
break
130+
;;
131+
132+
esac
133+
done
134+
135+
# The precedence for options is:
136+
# 1. command-line arguments
137+
# 2. environment variables
138+
# 3. defaults
139+
140+
# Source the config file if it exists
141+
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
142+
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
143+
144+
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
145+
146+
# Set the docker image
147+
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
148+
149+
# Handle special update command
150+
if [ "$special_update_command" != "" ]; then
151+
case $special_update_command in
152+
153+
update)
154+
command:update
155+
exit $?
156+
;;
157+
158+
update-image)
159+
command:update-image
160+
exit $?
161+
;;
162+
163+
update-script)
164+
command:update-script
165+
exit $?
166+
;;
167+
168+
esac
169+
fi
170+
171+
# Set the docker run extra args (if any)
172+
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
173+
174+
# If we are not running via boot2docker
175+
if [ -z $DOCKER_HOST ]; then
176+
USER_IDS="-e BUILDER_UID=$( id -u ) -e BUILDER_GID=$( id -g ) -e BUILDER_USER=$( id -un ) -e BUILDER_GROUP=$( id -gn )"
177+
fi
178+
179+
#------------------------------------------------------------------------------
180+
# Now, finally, run the command in a container
181+
#
182+
docker run --rm \
183+
-v $PWD:/work \
184+
$USER_IDS \
185+
$FINAL_ARGS \
186+
$FINAL_IMAGE "$@"
187+
188+
################################################################################
189+
#
190+
# This image is not intended to be run manually.
191+
#
192+
# To create a dockcross helper script for the
193+
# dockcross/linux-armv7 image, run:
194+
#
195+
# docker run --rm dockcross/linux-armv7 > dockcross-linux-armv7
196+
# chmod +x dockcross-linux-armv7
197+
#
198+
# You may then wish to move the dockcross script to your PATH.
199+
#
200+
################################################################################

0 commit comments

Comments
 (0)