Skip to content

Commit 6a522c4

Browse files
committed
Tweak the #[cfg()] statements in sys/ioctl/linux a little
This should give Nix a better chance of building on architectures that aren't specifically-supported.
1 parent 2d18d63 commit 6a522c4

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

src/sys/ioctl/linux.rs

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use cfg_if::cfg_if;
2+
13
/// The datatype used for the ioctl number
24
#[cfg(any(target_os = "android", target_env = "musl"))]
35
#[doc(hidden)]
@@ -14,48 +16,41 @@ pub const NRBITS: ioctl_num_type = 8;
1416
#[doc(hidden)]
1517
pub const TYPEBITS: ioctl_num_type = 8;
1618

17-
#[cfg(any(
18-
target_arch = "mips",
19-
target_arch = "mips64",
20-
target_arch = "powerpc",
21-
target_arch = "powerpc64",
22-
target_arch = "sparc64"
23-
))]
24-
mod consts {
25-
#[doc(hidden)]
26-
pub const NONE: u8 = 1;
27-
#[doc(hidden)]
28-
pub const READ: u8 = 2;
29-
#[doc(hidden)]
30-
pub const WRITE: u8 = 4;
31-
#[doc(hidden)]
32-
pub const SIZEBITS: u8 = 13;
33-
#[doc(hidden)]
34-
pub const DIRBITS: u8 = 3;
35-
}
36-
37-
// "Generic" ioctl protocol
38-
#[cfg(any(
39-
target_arch = "x86",
40-
target_arch = "arm",
41-
target_arch = "s390x",
42-
target_arch = "x86_64",
43-
target_arch = "aarch64",
44-
target_arch = "riscv32",
45-
target_arch = "riscv64",
46-
target_arch = "loongarch64"
47-
))]
48-
mod consts {
49-
#[doc(hidden)]
50-
pub const NONE: u8 = 0;
51-
#[doc(hidden)]
52-
pub const READ: u8 = 2;
53-
#[doc(hidden)]
54-
pub const WRITE: u8 = 1;
55-
#[doc(hidden)]
56-
pub const SIZEBITS: u8 = 14;
57-
#[doc(hidden)]
58-
pub const DIRBITS: u8 = 2;
19+
cfg_if! {
20+
if #[cfg(any(
21+
target_arch = "mips",
22+
target_arch = "mips64",
23+
target_arch = "powerpc",
24+
target_arch = "powerpc64",
25+
target_arch = "sparc64"
26+
))] {
27+
mod consts {
28+
#[doc(hidden)]
29+
pub const NONE: u8 = 1;
30+
#[doc(hidden)]
31+
pub const READ: u8 = 2;
32+
#[doc(hidden)]
33+
pub const WRITE: u8 = 4;
34+
#[doc(hidden)]
35+
pub const SIZEBITS: u8 = 13;
36+
#[doc(hidden)]
37+
pub const DIRBITS: u8 = 3;
38+
}
39+
} else {
40+
// "Generic" ioctl protocol
41+
mod consts {
42+
#[doc(hidden)]
43+
pub const NONE: u8 = 0;
44+
#[doc(hidden)]
45+
pub const READ: u8 = 2;
46+
#[doc(hidden)]
47+
pub const WRITE: u8 = 1;
48+
#[doc(hidden)]
49+
pub const SIZEBITS: u8 = 14;
50+
#[doc(hidden)]
51+
pub const DIRBITS: u8 = 2;
52+
}
53+
}
5954
}
6055

6156
pub use self::consts::*;

0 commit comments

Comments
 (0)