Skip to content

Commit 2afff81

Browse files
asomersSteveLauC
andauthored
Add more cfg aliases (#2205)
* Add more cfg aliases Add cfg aliases for linux_android, bsd, and freebsdlike. Use them in many places, though not everywhere they could theoretically be used. Fixes #2188 * Use apple_targets in build.rs Co-authored-by: SteveLauC <[email protected]> * whitespace Co-authored-by: SteveLauC <[email protected]> * Define a "solarish" target alias. * Describe cfg aliases in CONVENTIONS.md * solarish in line 803 * solarish in line 845 * fix fmt --------- Co-authored-by: SteveLauC <[email protected]>
1 parent 28e2a5e commit 2afff81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+547
-1152
lines changed

CONVENTIONS.md

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ impl SigSet {
3737

3838
When creating newtypes, we use Rust's `CamelCase` type naming convention.
3939

40+
## cfg gates
41+
42+
When creating operating-system-specific functionality, we gate it by
43+
`#[cfg(target_os = ...)]`. If more than one operating system is affected, we
44+
prefer to use the cfg aliases defined in build.rs, like `#[cfg(bsd)]`.
45+
4046
## Bitflags
4147

4248
Many C functions have flags parameters that are combined from constants using

build.rs

+12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@ use cfg_aliases::cfg_aliases;
22

33
fn main() {
44
cfg_aliases! {
5+
android: { target_os = "android" },
6+
dragonfly: { target_os = "dragonfly" },
57
ios: { target_os = "ios" },
8+
freebsd: { target_os = "freebsd" },
9+
illumos: { target_os = "illumos" },
10+
linux: { target_os = "linux" },
611
macos: { target_os = "macos" },
12+
netbsd: { target_os = "netbsd" },
13+
openbsd: { target_os = "openbsd" },
14+
solarish: { target_os = "solaris" },
715
watchos: { target_os = "watchos" },
816
tvos: { target_os = "tvos" },
917
apple_targets: { any(ios, macos, watchos, tvos) },
18+
bsd: { any(freebsd, dragonfly, netbsd, openbsd, apple_targets) },
19+
linux_android: { any(android, linux) },
20+
freebsdlike: { any(dragonfly, freebsd) },
21+
solarish: { any(illumos, solaris) },
1022
}
1123
}

src/errno.rs

+27-156
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ cfg_if! {
2525
unsafe fn errno_location() -> *mut c_int {
2626
unsafe { libc::__errno_location() }
2727
}
28-
} else if #[cfg(any(target_os = "illumos", target_os = "solaris"))] {
28+
} else if #[cfg(solarish)] {
2929
unsafe fn errno_location() -> *mut c_int {
3030
unsafe { libc::___errno() }
3131
}
@@ -501,7 +501,7 @@ fn desc(errno: Errno) -> &'static str {
501501
))]
502502
EBADMSG => "Not a data message",
503503

504-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
504+
#[cfg(solarish)]
505505
EBADMSG => "Trying to read unreadable message",
506506

507507
#[cfg(any(
@@ -745,7 +745,7 @@ fn desc(errno: Errno) -> &'static str {
745745
))]
746746
EOWNERDEAD => "Owner died",
747747

748-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
748+
#[cfg(solarish)]
749749
EOWNERDEAD => "Process died with lock",
750750

751751
#[cfg(any(
@@ -756,7 +756,7 @@ fn desc(errno: Errno) -> &'static str {
756756
))]
757757
ENOTRECOVERABLE => "State not recoverable",
758758

759-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
759+
#[cfg(solarish)]
760760
ENOTRECOVERABLE => "Lock is not recoverable",
761761

762762
#[cfg(any(
@@ -794,25 +794,10 @@ fn desc(errno: Errno) -> &'static str {
794794
#[cfg(target_os = "freebsd")]
795795
ECAPMODE => "Not permitted in capability mode",
796796

797-
#[cfg(any(
798-
target_os = "freebsd",
799-
target_os = "dragonfly",
800-
apple_targets,
801-
target_os = "openbsd",
802-
target_os = "netbsd"
803-
))]
797+
#[cfg(bsd)]
804798
ENEEDAUTH => "Need authenticator",
805799

806-
#[cfg(any(
807-
target_os = "freebsd",
808-
target_os = "dragonfly",
809-
apple_targets,
810-
target_os = "openbsd",
811-
target_os = "netbsd",
812-
target_os = "redox",
813-
target_os = "illumos",
814-
target_os = "solaris"
815-
))]
800+
#[cfg(any(bsd, target_os = "redox", solarish))]
816801
EOVERFLOW => "Value too large to be stored in data type",
817802

818803
#[cfg(any(
@@ -825,36 +810,13 @@ fn desc(errno: Errno) -> &'static str {
825810
))]
826811
EILSEQ => "Illegal byte sequence",
827812

828-
#[cfg(any(
829-
target_os = "freebsd",
830-
target_os = "dragonfly",
831-
apple_targets,
832-
target_os = "openbsd",
833-
target_os = "netbsd",
834-
target_os = "haiku"
835-
))]
813+
#[cfg(any(bsd, target_os = "haiku"))]
836814
ENOATTR => "Attribute not found",
837815

838-
#[cfg(any(
839-
target_os = "freebsd",
840-
target_os = "dragonfly",
841-
apple_targets,
842-
target_os = "openbsd",
843-
target_os = "netbsd",
844-
target_os = "redox",
845-
target_os = "haiku"
846-
))]
816+
#[cfg(any(bsd, target_os = "redox", target_os = "haiku"))]
847817
EBADMSG => "Bad message",
848818

849-
#[cfg(any(
850-
target_os = "freebsd",
851-
target_os = "dragonfly",
852-
apple_targets,
853-
target_os = "openbsd",
854-
target_os = "netbsd",
855-
target_os = "redox",
856-
target_os = "haiku"
857-
))]
819+
#[cfg(any(bsd, target_os = "redox", target_os = "haiku"))]
858820
EPROTO => "Protocol error",
859821

860822
#[cfg(any(
@@ -873,46 +835,17 @@ fn desc(errno: Errno) -> &'static str {
873835
))]
874836
EOWNERDEAD => "Previous owner died",
875837

876-
#[cfg(any(
877-
target_os = "freebsd",
878-
target_os = "dragonfly",
879-
apple_targets,
880-
target_os = "openbsd",
881-
target_os = "netbsd",
882-
target_os = "aix",
883-
target_os = "illumos",
884-
target_os = "solaris",
885-
target_os = "haiku"
886-
))]
838+
#[cfg(any(bsd, target_os = "aix", solarish, target_os = "haiku"))]
887839
ENOTSUP => "Operation not supported",
888840

889-
#[cfg(any(
890-
target_os = "freebsd",
891-
target_os = "dragonfly",
892-
apple_targets,
893-
target_os = "aix",
894-
target_os = "openbsd",
895-
target_os = "netbsd"
896-
))]
841+
#[cfg(any(bsd, target_os = "aix"))]
897842
EPROCLIM => "Too many processes",
898843

899-
#[cfg(any(
900-
target_os = "freebsd",
901-
target_os = "dragonfly",
902-
apple_targets,
903-
target_os = "aix",
904-
target_os = "openbsd",
905-
target_os = "netbsd",
906-
target_os = "redox"
907-
))]
844+
#[cfg(any(bsd, target_os = "aix", target_os = "redox"))]
908845
EUSERS => "Too many users",
909846

910847
#[cfg(any(
911-
target_os = "freebsd",
912-
target_os = "dragonfly",
913-
apple_targets,
914-
target_os = "openbsd",
915-
target_os = "netbsd",
848+
bsd,
916849
target_os = "redox",
917850
target_os = "aix",
918851
target_os = "illumos",
@@ -922,11 +855,7 @@ fn desc(errno: Errno) -> &'static str {
922855
EDQUOT => "Disc quota exceeded",
923856

924857
#[cfg(any(
925-
target_os = "freebsd",
926-
target_os = "dragonfly",
927-
apple_targets,
928-
target_os = "openbsd",
929-
target_os = "netbsd",
858+
bsd,
930859
target_os = "redox",
931860
target_os = "aix",
932861
target_os = "illumos",
@@ -935,89 +864,31 @@ fn desc(errno: Errno) -> &'static str {
935864
))]
936865
ESTALE => "Stale NFS file handle",
937866

938-
#[cfg(any(
939-
target_os = "freebsd",
940-
target_os = "dragonfly",
941-
apple_targets,
942-
target_os = "aix",
943-
target_os = "openbsd",
944-
target_os = "netbsd",
945-
target_os = "redox"
946-
))]
867+
#[cfg(any(bsd, target_os = "aix", target_os = "redox"))]
947868
EREMOTE => "Too many levels of remote in path",
948869

949-
#[cfg(any(
950-
target_os = "freebsd",
951-
target_os = "dragonfly",
952-
apple_targets,
953-
target_os = "openbsd",
954-
target_os = "netbsd"
955-
))]
870+
#[cfg(bsd)]
956871
EBADRPC => "RPC struct is bad",
957872

958-
#[cfg(any(
959-
target_os = "freebsd",
960-
target_os = "dragonfly",
961-
apple_targets,
962-
target_os = "openbsd",
963-
target_os = "netbsd"
964-
))]
873+
#[cfg(bsd)]
965874
ERPCMISMATCH => "RPC version wrong",
966875

967-
#[cfg(any(
968-
target_os = "freebsd",
969-
target_os = "dragonfly",
970-
apple_targets,
971-
target_os = "openbsd",
972-
target_os = "netbsd"
973-
))]
876+
#[cfg(bsd)]
974877
EPROGUNAVAIL => "RPC prog. not avail",
975878

976-
#[cfg(any(
977-
target_os = "freebsd",
978-
target_os = "dragonfly",
979-
apple_targets,
980-
target_os = "openbsd",
981-
target_os = "netbsd"
982-
))]
879+
#[cfg(bsd)]
983880
EPROGMISMATCH => "Program version wrong",
984881

985-
#[cfg(any(
986-
target_os = "freebsd",
987-
target_os = "dragonfly",
988-
apple_targets,
989-
target_os = "openbsd",
990-
target_os = "netbsd"
991-
))]
882+
#[cfg(bsd)]
992883
EPROCUNAVAIL => "Bad procedure for program",
993884

994-
#[cfg(any(
995-
target_os = "freebsd",
996-
target_os = "dragonfly",
997-
apple_targets,
998-
target_os = "openbsd",
999-
target_os = "netbsd"
1000-
))]
885+
#[cfg(bsd)]
1001886
EFTYPE => "Inappropriate file type or format",
1002887

1003-
#[cfg(any(
1004-
target_os = "freebsd",
1005-
target_os = "dragonfly",
1006-
apple_targets,
1007-
target_os = "openbsd",
1008-
target_os = "netbsd"
1009-
))]
888+
#[cfg(bsd)]
1010889
EAUTH => "Authentication error",
1011890

1012-
#[cfg(any(
1013-
target_os = "freebsd",
1014-
target_os = "dragonfly",
1015-
apple_targets,
1016-
target_os = "aix",
1017-
target_os = "openbsd",
1018-
target_os = "netbsd",
1019-
target_os = "redox"
1020-
))]
891+
#[cfg(any(bsd, target_os = "aix", target_os = "redox"))]
1021892
ECANCELED => "Operation canceled",
1022893

1023894
#[cfg(apple_targets)]
@@ -1099,13 +970,13 @@ fn desc(errno: Errno) -> &'static str {
1099970
#[cfg(target_os = "dragonfly")]
1100971
EASYNC => "Async",
1101972

1102-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
973+
#[cfg(solarish)]
1103974
EDEADLOCK => "Resource deadlock would occur",
1104975

1105-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
976+
#[cfg(solarish)]
1106977
ELOCKUNMAPPED => "Locked lock was unmapped",
1107978

1108-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
979+
#[cfg(solarish)]
1109980
ENOTACTIVE => "Facility is not active",
1110981
}
1111982
}
@@ -2688,7 +2559,7 @@ mod consts {
26882559
}
26892560
}
26902561

2691-
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
2562+
#[cfg(solarish)]
26922563
mod consts {
26932564
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
26942565
#[repr(i32)]

0 commit comments

Comments
 (0)