Skip to content

Commit 91748de

Browse files
committed
cleanup libc-test for OpenBSD
1 parent 2ea7206 commit 91748de

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

libc-test/build.rs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn do_ctest() {
3737

3838
match &target {
3939
t if t.contains("apple") => return test_apple(t),
40+
t if t.contains("openbsd") => return test_openbsd(t),
4041
t if t.contains("windows") => return test_windows(t),
4142
_ => (),
4243
}
@@ -1028,6 +1029,150 @@ fn test_apple(target: &str) {
10281029
cfg.generate("../src/lib.rs", "main.rs");
10291030
}
10301031

1032+
fn test_openbsd(target: &str) {
1033+
assert!(target.contains("openbsd"));
1034+
1035+
let mut cfg = ctest::TestGenerator::new();
1036+
cfg.flag("-Wno-deprecated-declarations");
1037+
1038+
headers! { cfg:
1039+
"errno.h",
1040+
"fcntl.h",
1041+
"limits.h",
1042+
"locale.h",
1043+
"stddef.h",
1044+
"stdint.h",
1045+
"stdio.h",
1046+
"stdlib.h",
1047+
"sys/stat.h",
1048+
"sys/types.h",
1049+
"time.h",
1050+
"wchar.h",
1051+
"ctype.h",
1052+
"dirent.h",
1053+
"sys/socket.h",
1054+
"net/if.h",
1055+
"net/route.h",
1056+
"net/if_arp.h",
1057+
"netdb.h",
1058+
"netinet/in.h",
1059+
"netinet/ip.h",
1060+
"netinet/tcp.h",
1061+
"netinet/udp.h",
1062+
"resolv.h",
1063+
"pthread.h",
1064+
"dlfcn.h",
1065+
"signal.h",
1066+
"string.h",
1067+
"sys/file.h",
1068+
"sys/ioctl.h",
1069+
"sys/mman.h",
1070+
"sys/resource.h",
1071+
"sys/socket.h",
1072+
"sys/time.h",
1073+
"sys/un.h",
1074+
"sys/wait.h",
1075+
"unistd.h",
1076+
"utime.h",
1077+
"pwd.h",
1078+
"grp.h",
1079+
"sys/utsname.h",
1080+
"sys/ptrace.h",
1081+
"sys/mount.h",
1082+
"sys/uio.h",
1083+
"sched.h",
1084+
"termios.h",
1085+
"poll.h",
1086+
"syslog.h",
1087+
"semaphore.h",
1088+
"sys/statvfs.h",
1089+
"sys/times.h",
1090+
"glob.h",
1091+
"ifaddrs.h",
1092+
"langinfo.h",
1093+
"sys/sysctl.h",
1094+
"utmp.h",
1095+
"sys/event.h",
1096+
"net/if_dl.h",
1097+
"util.h",
1098+
"ufs/ufs/quota.h",
1099+
"pthread_np.h",
1100+
"sys/syscall.h",
1101+
}
1102+
1103+
cfg.skip_struct(move |ty| {
1104+
match ty {
1105+
// FIXME: actually a union
1106+
"sigval" => true,
1107+
1108+
_ => false,
1109+
}
1110+
});
1111+
1112+
cfg.skip_const(move |name| {
1113+
match name {
1114+
// Removed in OpenBSD 6.0
1115+
"KERN_USERMOUNT" | "KERN_ARND" => true,
1116+
_ => false,
1117+
}
1118+
});
1119+
1120+
cfg.skip_fn(move |name| {
1121+
match name {
1122+
"execv" | "execve" | "execvp" | "execvpe" => true,
1123+
1124+
// typed 2nd arg
1125+
"gettimeofday" => true,
1126+
1127+
// Removed in OpenBSD 6.5
1128+
// https://marc.info/?l=openbsd-cvs&m=154723400730318
1129+
"mincore" => true,
1130+
1131+
_ => false,
1132+
}
1133+
});
1134+
1135+
cfg.type_name(move |ty, is_struct, is_union| {
1136+
match ty {
1137+
// Just pass all these through, no need for a "struct" prefix
1138+
"FILE" | "DIR" | "Dl_info" => ty.to_string(),
1139+
1140+
// OSX calls this something else
1141+
"sighandler_t" => "sig_t".to_string(),
1142+
1143+
t if is_union => format!("union {}", t),
1144+
t if t.ends_with("_t") => t.to_string(),
1145+
t if is_struct => format!("struct {}", t),
1146+
t => t.to_string(),
1147+
}
1148+
});
1149+
1150+
cfg.field_name(move |struct_, field| {
1151+
match field {
1152+
"st_birthtime" if struct_.starts_with("stat") => {
1153+
"__st_birthtime".to_string()
1154+
}
1155+
"st_birthtime_nsec" if struct_.starts_with("stat") => {
1156+
"__st_birthtimensec".to_string()
1157+
}
1158+
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
1159+
s.replace("e_nsec", ".tv_nsec")
1160+
}
1161+
"sa_sigaction" if struct_ == "sigaction" => {
1162+
"sa_handler".to_string()
1163+
}
1164+
s => s.to_string(),
1165+
}
1166+
});
1167+
1168+
cfg.skip_field_type(move |struct_, field| {
1169+
// type siginfo_t.si_addr changed from OpenBSD 6.0 to 6.1
1170+
(struct_ == "siginfo_t" && field == "si_addr")
1171+
});
1172+
1173+
cfg.generate("../src/lib.rs", "linux_fcntl.rs");
1174+
}
1175+
10311176
fn test_windows(target: &str) {
10321177
assert!(target.contains("windows"));
10331178
let gnu = target.contains("gnu");

0 commit comments

Comments
 (0)