Skip to content

Commit 96c197c

Browse files
authored
Merge pull request #4092 from heiher/loong-musl
ci: add support for loongarch64-unknown-linux-musl
2 parents 1e356f9 + e03b594 commit 96c197c

File tree

9 files changed

+76
-50
lines changed

9 files changed

+76
-50
lines changed

.github/workflows/full_ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ jobs:
165165
- i686-linux-android
166166
- i686-unknown-linux-musl
167167
- loongarch64-unknown-linux-gnu
168+
- loongarch64-unknown-linux-musl
168169
- powerpc-unknown-linux-gnu
169170
- powerpc64-unknown-linux-gnu
170171
- powerpc64le-unknown-linux-gnu
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM ubuntu:24.04
2+
3+
RUN apt-get update && apt-get install -y --no-install-recommends \
4+
ca-certificates curl gcc git libc6-dev make qemu-user xz-utils
5+
6+
COPY install-musl-cross.sh /
7+
RUN sh /install-musl-cross.sh loongarch64-unknown-linux-musl
8+
9+
ENV CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_LINKER=loongarch64-unknown-linux-musl-gcc \
10+
CARGO_TARGET_LOONGARCH64_UNKNOWN_LINUX_MUSL_RUNNER="qemu-loongarch64" \
11+
CC_loongarch64_unknown_linux_musl=loongarch64-unknown-linux-musl-gcc \
12+
CFLAGS_loongarch64_unknown_linux_musl="-mabi=lp64d -fPIC" \
13+
QEMU_LD_PREFIX=/loongarch64-unknown-linux-musl/loongarch64-unknown-linux-musl/sysroot \
14+
PATH=$PATH:/loongarch64-unknown-linux-musl/bin:/rust/bin

ci/install-musl-cross.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
#
3+
# Install musl cross toolchain
4+
5+
set -ex
6+
7+
MUSL_CROSS_VER=20241103
8+
MUSL_CROSS_URL=https://github.com/musl-cross/musl-cross/releases/download/$MUSL_CROSS_VER/$1.tar.xz
9+
10+
curl -L --retry 5 "$MUSL_CROSS_URL" | tar -xJf - -C /

libc-test/build.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -4489,14 +4489,14 @@ fn test_linux(target: &str) {
44894489
(struct_ == "iw_encode_ext" && field == "key") ||
44904490
// the `tcpi_snd_rcv_wscale` map two bitfield fields stored in a u8
44914491
(struct_ == "tcp_info" && field == "tcpi_snd_rcv_wscale") ||
4492-
// the `tcpi_delivery_rate_app_limited` field is a bitfield on musl
4493-
(musl && struct_ == "tcp_info" && field == "tcpi_delivery_rate_app_limited") ||
4494-
// the `tcpi_fast_open_client_fail` field is a bitfield on musl
4495-
(musl && struct_ == "tcp_info" && field == "tcpi_fast_open_client_fail") ||
4492+
// the `tcpi_delivery_fastopen_bitfields` map two bitfield fields stored in a u8
4493+
(musl && struct_ == "tcp_info" && field == "tcpi_delivery_fastopen_bitfields") ||
44964494
// either fsid_t or int[2] type
44974495
(struct_ == "fanotify_event_info_fid" && field == "fsid") ||
44984496
// `handle` is a VLA
4499-
(struct_ == "fanotify_event_info_fid" && field == "handle")
4497+
(struct_ == "fanotify_event_info_fid" && field == "handle") ||
4498+
// invalid application of 'sizeof' to incomplete type 'long unsigned int[]'
4499+
(musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64)
45004500
});
45014501

45024502
cfg.skip_roundtrip(move |s| match s {
+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
KEYCTL_CAPABILITIES
2+
KEYCTL_CAPS0_BIG_KEY
3+
KEYCTL_CAPS0_CAPABILITIES
4+
KEYCTL_CAPS0_DIFFIE_HELLMAN
5+
KEYCTL_CAPS0_INVALIDATE
6+
KEYCTL_CAPS0_MOVE
7+
KEYCTL_CAPS0_PERSISTENT_KEYRINGS
8+
KEYCTL_CAPS0_PUBLIC_KEY
9+
KEYCTL_CAPS0_RESTRICT_KEYRING
10+
KEYCTL_CAPS1_NS_KEYRING_NAME
11+
KEYCTL_CAPS1_NS_KEY_TAG
12+
KEYCTL_MOVE
13+
MADV_SOFT_OFFLINE
114
PTRACE_GETFPREGS
215
PTRACE_GETFPXREGS
316
PTRACE_GETREGS
417
PTRACE_SETFPREGS
518
PTRACE_SETFPXREGS
619
PTRACE_SETREGS
20+
PTRACE_SYSEMU
21+
PTRACE_SYSEMU_SINGLESTEP

libc-test/semver/linux-loongarch64.txt

-15
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,11 @@ BPF_XOR
4040
CIBAUD
4141
FICLONE
4242
FICLONERANGE
43-
KEYCTL_CAPABILITIES
44-
KEYCTL_CAPS0_BIG_KEY
45-
KEYCTL_CAPS0_CAPABILITIES
46-
KEYCTL_CAPS0_DIFFIE_HELLMAN
47-
KEYCTL_CAPS0_INVALIDATE
48-
KEYCTL_CAPS0_MOVE
49-
KEYCTL_CAPS0_PERSISTENT_KEYRINGS
50-
KEYCTL_CAPS0_PUBLIC_KEY
51-
KEYCTL_CAPS0_RESTRICT_KEYRING
52-
KEYCTL_CAPS1_NS_KEYRING_NAME
53-
KEYCTL_CAPS1_NS_KEY_TAG
54-
KEYCTL_MOVE
55-
MADV_SOFT_OFFLINE
5643
MAP_SYNC
5744
NFT_MSG_DELOBJ
5845
NFT_MSG_GETOBJ
5946
NFT_MSG_GETOBJ_RESET
6047
NFT_MSG_NEWOBJ
61-
PTRACE_SYSEMU
62-
PTRACE_SYSEMU_SINGLESTEP
6348
SCM_TIMESTAMPNS
6449
SCM_WIFI_STATUS
6550
SIGSTKFLT

src/unix/linux_like/linux/arch/generic/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,10 @@ cfg_if! {
353353
pub const RLIMIT_RTPRIO: ::c_int = 14;
354354
pub const RLIMIT_RTTIME: ::c_int = 15;
355355
#[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
356+
#[cfg(not(target_arch = "loongarch64"))]
356357
pub const RLIM_NLIMITS: ::c_int = 15;
358+
#[cfg(target_arch = "loongarch64")]
359+
pub const RLIM_NLIMITS: ::c_int = 16;
357360
#[allow(deprecated)]
358361
#[deprecated(since = "0.2.64", note = "Not stable across OS versions")]
359362
pub const RLIMIT_NLIMITS: ::c_int = RLIM_NLIMITS;

src/unix/linux_like/linux/musl/b64/loongarch64/mod.rs

+7-25
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ pub type __u64 = ::c_ulonglong;
1111
pub type __s64 = ::c_longlong;
1212

1313
s! {
14-
pub struct pthread_attr_t {
15-
__size: [::c_ulong; 7],
16-
}
17-
1814
pub struct stat {
1915
pub st_dev: ::dev_t,
2016
pub st_ino: ::ino_t,
@@ -59,21 +55,6 @@ s! {
5955
__unused: [::c_int; 2],
6056
}
6157

62-
pub struct statfs {
63-
pub f_type: ::c_long,
64-
pub f_bsize: ::c_long,
65-
pub f_blocks: ::fsblkcnt_t,
66-
pub f_bfree: ::fsblkcnt_t,
67-
pub f_bavail: ::fsblkcnt_t,
68-
pub f_files: ::fsfilcnt_t,
69-
pub f_ffree: ::fsfilcnt_t,
70-
pub f_fsid: ::fsid_t,
71-
pub f_namelen: ::c_long,
72-
pub f_frsize: ::c_long,
73-
pub f_flags: ::c_long,
74-
pub f_spare: [::c_long; 4],
75-
}
76-
7758
pub struct statfs64 {
7859
pub f_type: ::c_long,
7960
pub f_bsize: ::c_long,
@@ -96,7 +77,7 @@ s! {
9677
pub cuid: ::uid_t,
9778
pub cgid: ::gid_t,
9879
pub mode: ::c_uint,
99-
pub __seq: ::c_ushort,
80+
pub __seq: ::c_int,
10081
__pad2: ::c_ushort,
10182
__unused1: ::c_ulong,
10283
__unused2: ::c_ulong,
@@ -126,10 +107,10 @@ s! {
126107

127108
#[repr(align(16))]
128109
pub struct mcontext_t {
129-
pub __pc: ::c_ulonglong,
130-
pub __gregs: [::c_ulonglong; 32],
110+
pub __pc: ::c_ulong,
111+
pub __gregs: [::c_ulong; 32],
131112
pub __flags: ::c_uint,
132-
pub __extcontext: [::c_ulonglong; 0],
113+
pub __extcontext: [::c_ulong; 0],
133114
}
134115

135116
#[repr(align(8))]
@@ -467,7 +448,7 @@ pub const SYS_futex_requeue: ::c_long = 456;
467448
pub const O_APPEND: ::c_int = 1024;
468449
pub const O_DIRECT: ::c_int = 0x4000;
469450
pub const O_DIRECTORY: ::c_int = 0x10000;
470-
pub const O_LARGEFILE: ::c_int = 0;
451+
pub const O_LARGEFILE: ::c_int = 0o0100000;
471452
pub const O_NOFOLLOW: ::c_int = 0x20000;
472453
pub const O_CREAT: ::c_int = 64;
473454
pub const O_EXCL: ::c_int = 128;
@@ -476,7 +457,7 @@ pub const O_NONBLOCK: ::c_int = 2048;
476457
pub const O_SYNC: ::c_int = 1052672;
477458
pub const O_RSYNC: ::c_int = 1052672;
478459
pub const O_DSYNC: ::c_int = 4096;
479-
pub const O_ASYNC: ::c_int = 4096;
460+
pub const O_ASYNC: ::c_int = 0o20000;
480461

481462
pub const SIGSTKSZ: ::size_t = 16384;
482463
pub const MINSIGSTKSZ: ::size_t = 4096;
@@ -660,6 +641,7 @@ pub const ECHOPRT: ::tcflag_t = 0x00000400;
660641
pub const ECHOCTL: ::tcflag_t = 0x00000200;
661642
pub const ISIG: ::tcflag_t = 0x00000001;
662643
pub const ICANON: ::tcflag_t = 0x00000002;
644+
pub const XCASE: ::tcflag_t = 0x00000004;
663645
pub const PENDIN: ::tcflag_t = 0x00004000;
664646
pub const NOFLSH: ::tcflag_t = 0x00000080;
665647
pub const CIBAUD: ::tcflag_t = 0o02003600000;

src/unix/linux_like/linux/musl/mod.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,16 @@ s! {
355355
pub tcpi_backoff: u8,
356356
pub tcpi_options: u8,
357357
/*
358-
* FIXME(musl): when musl headers are more up to date
358+
* FIXME(musl): enable on all targets once musl headers are more up to date
359+
*/
359360
/// This contains the bitfields `tcpi_snd_wscale` and `tcpi_rcv_wscale`.
360361
/// Each is 4 bits.
362+
#[cfg(target_arch = "loongarch64")]
361363
pub tcpi_snd_rcv_wscale: u8,
362364
/// This contains the bitfields `tcpi_delivery_rate_app_limited` (1 bit) and
363365
/// `tcpi_fastopen_client_fail` (2 bits).
366+
#[cfg(target_arch = "loongarch64")]
364367
pub tcpi_delivery_fastopen_bitfields: u8,
365-
*/
366368
pub tcpi_rto: u32,
367369
pub tcpi_ato: u32,
368370
pub tcpi_snd_mss: u32,
@@ -407,9 +409,11 @@ s! {
407409
pub tcpi_bytes_retrans: u64,
408410
pub tcpi_dsack_dups: u32,
409411
pub tcpi_reord_seen: u32,
410-
// FIXME(musl): to uncomment once CI musl is updated
411-
//pub tcpi_rcv_ooopack: u32,
412-
//pub tcpi_snd_wnd: u32,
412+
// FIXME(musl): enable on all targets once CI musl is updated
413+
#[cfg(target_arch = "loongarch64")]
414+
pub tcpi_rcv_ooopack: u32,
415+
#[cfg(target_arch = "loongarch64")]
416+
pub tcpi_snd_wnd: u32,
413417
}
414418
}
415419

@@ -449,8 +453,17 @@ s_no_extra_traits! {
449453
pub ut_exit: __exit_status,
450454

451455
#[cfg(target_env = "musl")]
456+
#[cfg(not(target_arch = "loongarch64"))]
452457
pub ut_session: ::c_long,
453458

459+
#[cfg(target_env = "musl")]
460+
#[cfg(target_arch = "loongarch64")]
461+
pub ut_session: ::c_int,
462+
463+
#[cfg(target_env = "musl")]
464+
#[cfg(target_arch = "loongarch64")]
465+
__ut_pad2: ::c_int,
466+
454467
#[cfg(target_env = "ohos")]
455468
#[cfg(target_endian = "little")]
456469
pub ut_session: ::c_int,
@@ -712,7 +725,10 @@ pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
712725
pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8;
713726
pub const __SIZEOF_PTHREAD_BARRIERATTR_T: usize = 4;
714727

728+
#[cfg(not(target_arch = "loongarch64"))]
715729
pub const CPU_SETSIZE: ::c_int = 128;
730+
#[cfg(target_arch = "loongarch64")]
731+
pub const CPU_SETSIZE: ::c_int = 1024;
716732

717733
pub const PTRACE_TRACEME: ::c_int = 0;
718734
pub const PTRACE_PEEKTEXT: ::c_int = 1;

0 commit comments

Comments
 (0)