@@ -240,6 +240,67 @@ get_endianness() {
240
240
fi
241
241
}
242
242
243
+ # Detect the Linux/LoongArch UAPI flavor, with all errors being non-fatal.
244
+ # Returns 0 or 234 in case of successful detection, 1 otherwise (/tmp being
245
+ # noexec, or other causes).
246
+ check_loongarch_uapi () {
247
+ need_cmd base64
248
+
249
+ local _tmp
250
+ if ! _tmp=" $( ensure mktemp) " ; then
251
+ return 1
252
+ fi
253
+
254
+ # Minimal Linux/LoongArch UAPI detection, exiting with 0 in case of
255
+ # upstream ("new world") UAPI, and 234 (-EINVAL truncated) in case of
256
+ # old-world (as deployed on several early commercial Linux distributions
257
+ # for LoongArch).
258
+ #
259
+ # See https://gist.github.com/xen0n/5ee04aaa6cecc5c7794b9a0c3b65fc7f for
260
+ # source to this helper binary.
261
+ ignore base64 -d > " $_tmp " << EOF
262
+ f0VMRgIBAQAAAAAAAAAAAAIAAgEBAAAAeAAgAAAAAABAAAAAAAAAAAAAAAAAAAAAQQAAAEAAOAAB
263
+ AAAAAAAAAAEAAAAFAAAAAAAAAAAAAAAAACAAAAAAAAAAIAAAAAAAJAAAAAAAAAAkAAAAAAAAAAAA
264
+ AQAAAAAABCiAAwUAFQAGABUAByCAAwsYggMAACsAC3iBAwAAKwAxen0n
265
+ EOF
266
+
267
+ ignore chmod u+x " $_tmp "
268
+ if [ ! -x " $_tmp " ]; then
269
+ ignore rm " $_tmp "
270
+ return 1
271
+ fi
272
+
273
+ " $_tmp "
274
+ local _retval=$?
275
+
276
+ ignore rm " $_tmp "
277
+ return " $_retval "
278
+ }
279
+
280
+ ensure_loongarch_uapi () {
281
+ check_loongarch_uapi
282
+ case $? in
283
+ 0)
284
+ return 0
285
+ ;;
286
+ 234)
287
+ echo >&2
288
+ echo ' Your Linux kernel does not provide the ABI required by this Rust' >&2
289
+ echo ' distribution. Please check with your OS provider for how to obtain a' >&2
290
+ echo ' compatible Rust package for your system.' >&2
291
+ echo >&2
292
+ exit 1
293
+ ;;
294
+ * )
295
+ echo " Warning: Cannot determine current system's ABI flavor, continuing anyway." >&2
296
+ echo >&2
297
+ echo ' Note that the official Rust distribution only works with the upstream' >&2
298
+ echo ' kernel ABI. Installation will fail if your running kernel happens to be' >&2
299
+ echo ' incompatible.' >&2
300
+ ;;
301
+ esac
302
+ }
303
+
243
304
get_architecture () {
244
305
local _ostype _cputype _bitness _arch _clibtype
245
306
_ostype=" $( uname -s) "
@@ -393,6 +454,7 @@ get_architecture() {
393
454
;;
394
455
loongarch64)
395
456
_cputype=loongarch64
457
+ ensure_loongarch_uapi
396
458
;;
397
459
* )
398
460
err " unknown CPU type: $_cputype "
0 commit comments