Skip to content

Commit 87f10ab

Browse files
committed
Cleanup NetBSD logic in libc-test/build.rs
1 parent 09afebe commit 87f10ab

File tree

1 file changed

+211
-39
lines changed

1 file changed

+211
-39
lines changed

libc-test/build.rs

Lines changed: 211 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@ fn do_ctest() {
2626
let freebsd = target.contains("freebsd");
2727
let dragonfly = target.contains("dragonfly");
2828
let mips = target.contains("mips");
29-
let netbsd = target.contains("netbsd");
3029
let openbsd = target.contains("openbsd");
31-
let rumprun = target.contains("rumprun");
32-
let bsdlike = freebsd || netbsd || openbsd || dragonfly;
30+
let bsdlike = freebsd || openbsd || dragonfly;
3331
let mut cfg = ctest::TestGenerator::new();
3432

3533
match &target {
@@ -38,14 +36,13 @@ fn do_ctest() {
3836
t if t.contains("redox") => return test_redox(t),
3937
t if t.contains("cloudabi") => return test_cloudabi(t),
4038
t if t.contains("solaris") => return test_solaris(t),
39+
t if t.contains("netbsd") => return test_netbsd(t),
4140
_ => (),
4241
}
4342

4443
// Pull in extra goodies
4544
if linux || android || emscripten {
4645
cfg.define("_GNU_SOURCE", None);
47-
} else if netbsd {
48-
cfg.define("_NETBSD_SOURCE", Some("1"));
4946
} else if freebsd {
5047
cfg.define("_WITH_GETLINE", None);
5148
}
@@ -144,7 +141,7 @@ fn do_ctest() {
144141
}
145142

146143
if !musl && !uclibc {
147-
if !netbsd && !openbsd && !uclibc {
144+
if !openbsd && !uclibc {
148145
cfg.header("execinfo.h");
149146
}
150147

@@ -274,17 +271,6 @@ fn do_ctest() {
274271
cfg.header("spawn.h");
275272
}
276273

277-
if netbsd {
278-
cfg.header("mqueue.h");
279-
cfg.header("ufs/ufs/quota.h");
280-
cfg.header("ufs/ufs/quota1.h");
281-
cfg.header("sys/extattr.h");
282-
cfg.header("sys/ioctl_compat.h");
283-
284-
// DCCP support
285-
cfg.header("netinet/dccp.h");
286-
}
287-
288274
if openbsd {
289275
cfg.header("ufs/ufs/quota.h");
290276
cfg.header("pthread_np.h");
@@ -298,7 +284,7 @@ fn do_ctest() {
298284
cfg.header("sys/rtprio.h");
299285
}
300286

301-
if linux || freebsd || dragonfly || netbsd || emscripten {
287+
if linux || freebsd || dragonfly || emscripten {
302288
if !uclibc {
303289
cfg.header("aio.h");
304290
}
@@ -403,7 +389,7 @@ fn do_ctest() {
403389
"uuid_t" if dragonfly => true,
404390
n if n.starts_with("pthread") => true,
405391
// sem_t is a struct or pointer
406-
"sem_t" if openbsd || freebsd || dragonfly || netbsd => true,
392+
"sem_t" if openbsd || freebsd || dragonfly => true,
407393
// mqd_t is a pointer on FreeBSD and DragonFly
408394
"mqd_t" if freebsd || dragonfly => true,
409395

@@ -614,26 +600,6 @@ fn do_ctest() {
614600
"dlerror" if android => true, // const-ness is added
615601
"dladdr" if musl => true, // const-ness only added recently
616602

617-
// These functions presumably exist on netbsd but don't look like
618-
// they're implemented on rumprun yet, just let them slide for now.
619-
// Some of them look like they have headers but then don't have
620-
// corresponding actual definitions either...
621-
"shm_open" |
622-
"shm_unlink" |
623-
"syscall" |
624-
"mq_open" |
625-
"mq_close" |
626-
"mq_getattr" |
627-
"mq_notify" |
628-
"mq_receive" |
629-
"mq_send" |
630-
"mq_setattr" |
631-
"mq_timedreceive" |
632-
"mq_timedsend" |
633-
"mq_unlink" |
634-
"ptrace" |
635-
"sigaltstack" if rumprun => true,
636-
637603
// There seems to be a small error in EGLIBC's eventfd.h header. The
638604
// [underlying system call][1] always takes its first `count`
639605
// argument as an `unsigned int`, but [EGLIBC's <sys/eventfd.h>
@@ -1350,3 +1316,209 @@ fn test_solaris(target: &str) {
13501316

13511317
cfg.generate("../src/lib.rs", "main.rs");
13521318
}
1319+
1320+
fn test_netbsd(target: &str) {
1321+
assert!(target.contains("netbsd"));
1322+
let rumprun = target.contains("rumprun");
1323+
let mut cfg = ctest::TestGenerator::new();
1324+
1325+
cfg.flag("-Wno-deprecated-declarations");
1326+
cfg.define("_NETBSD_SOURCE", Some("1"));
1327+
1328+
headers! {
1329+
cfg:
1330+
"errno.h",
1331+
"fcntl.h",
1332+
"limits.h",
1333+
"locale.h",
1334+
"stddef.h",
1335+
"stdint.h",
1336+
"stdio.h",
1337+
"stdlib.h",
1338+
"sys/stat.h",
1339+
"sys/types.h",
1340+
"time.h",
1341+
"wchar.h",
1342+
"aio.h",
1343+
"ctype.h",
1344+
"dirent.h",
1345+
"dlfcn.h",
1346+
"glob.h",
1347+
"grp.h",
1348+
"ifaddrs.h",
1349+
"langinfo.h",
1350+
"net/if.h",
1351+
"net/if_arp.h",
1352+
"net/if_dl.h",
1353+
"net/route.h",
1354+
"netdb.h",
1355+
"netinet/in.h",
1356+
"netinet/ip.h",
1357+
"netinet/tcp.h",
1358+
"netinet/udp.h",
1359+
"poll.h",
1360+
"pthread.h",
1361+
"pwd.h",
1362+
"resolv.h",
1363+
"sched.h",
1364+
"semaphore.h",
1365+
"signal.h",
1366+
"string.h",
1367+
"sys/extattr.h",
1368+
"sys/file.h",
1369+
"sys/ioctl.h",
1370+
"sys/ioctl_compat.h",
1371+
"sys/mman.h",
1372+
"sys/mount.h",
1373+
"sys/ptrace.h",
1374+
"sys/resource.h",
1375+
"sys/socket.h",
1376+
"sys/statvfs.h",
1377+
"sys/sysctl.h",
1378+
"sys/time.h",
1379+
"sys/times.h",
1380+
"sys/uio.h",
1381+
"sys/un.h",
1382+
"sys/utsname.h",
1383+
"sys/wait.h",
1384+
"syslog.h",
1385+
"termios.h",
1386+
"ufs/ufs/quota.h",
1387+
"ufs/ufs/quota1.h",
1388+
"unistd.h",
1389+
"util.h",
1390+
"utime.h",
1391+
"mqueue.h",
1392+
"netinet/dccp.h",
1393+
"sys/event.h",
1394+
"sys/quota.h",
1395+
}
1396+
1397+
cfg.type_name(move |ty, is_struct, is_union| {
1398+
match ty {
1399+
// Just pass all these through, no need for a "struct" prefix
1400+
"FILE" | "fd_set" | "Dl_info" | "DIR" | "Elf32_Phdr"
1401+
| "Elf64_Phdr" | "Elf32_Shdr" | "Elf64_Shdr" | "Elf32_Sym"
1402+
| "Elf64_Sym" | "Elf32_Ehdr" | "Elf64_Ehdr" | "Elf32_Chdr"
1403+
| "Elf64_Chdr" => ty.to_string(),
1404+
1405+
// OSX calls this something else
1406+
"sighandler_t" => "sig_t".to_string(),
1407+
1408+
t if is_union => format!("union {}", t),
1409+
1410+
t if t.ends_with("_t") => t.to_string(),
1411+
1412+
// put `struct` in front of all structs:.
1413+
t if is_struct => format!("struct {}", t),
1414+
1415+
t => t.to_string(),
1416+
}
1417+
});
1418+
1419+
cfg.field_name(move |struct_, field| {
1420+
match field {
1421+
// Our stat *_nsec fields normally don't actually exist but are part
1422+
// of a timeval struct
1423+
s if s.ends_with("_nsec") && struct_.starts_with("stat") => {
1424+
s.replace("e_nsec", ".tv_nsec")
1425+
}
1426+
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
1427+
s => s.to_string(),
1428+
}
1429+
});
1430+
1431+
cfg.skip_type(move |ty| {
1432+
match ty {
1433+
// FIXME: sighandler_t is crazy across platforms
1434+
"sighandler_t" => true,
1435+
_ => false,
1436+
}
1437+
});
1438+
1439+
cfg.skip_struct(move |ty| {
1440+
match ty {
1441+
// This is actually a union, not a struct
1442+
"sigval" => true,
1443+
// These are tested as part of the linux_fcntl tests since there are
1444+
// header conflicts when including them with all the other structs.
1445+
"termios2" => true,
1446+
_ => false,
1447+
}
1448+
});
1449+
1450+
cfg.skip_signededness(move |c| {
1451+
match c {
1452+
"LARGE_INTEGER" | "float" | "double" => true,
1453+
// uuid_t is a struct, not an integer.
1454+
n if n.starts_with("pthread") => true,
1455+
// sem_t is a struct or pointer
1456+
"sem_t" => true,
1457+
_ => false,
1458+
}
1459+
});
1460+
1461+
cfg.skip_const(move |name| {
1462+
match name {
1463+
"SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true, // sighandler_t weirdness
1464+
"SIGUNUSED" => true, // removed in glibc 2.26
1465+
1466+
// weird signed extension or something like that?
1467+
"MS_NOUSER" => true,
1468+
"MS_RMT_MASK" => true, // updated in glibc 2.22 and musl 1.1.13
1469+
"BOTHER" => true,
1470+
1471+
_ => false,
1472+
}
1473+
});
1474+
1475+
cfg.skip_fn(move |name| {
1476+
match name {
1477+
// FIXME: incorrect API
1478+
"execv" |
1479+
"execve" |
1480+
"execvp" |
1481+
"execvpe" |
1482+
"fexecve" => true,
1483+
1484+
"getrlimit" | "getrlimit64" | // non-int in 1st arg
1485+
"setrlimit" | "setrlimit64" | // non-int in 1st arg
1486+
"prlimit" | "prlimit64" | // non-int in 2nd arg
1487+
1488+
// These functions presumably exist on netbsd but don't look like
1489+
// they're implemented on rumprun yet, just let them slide for now.
1490+
// Some of them look like they have headers but then don't have
1491+
// corresponding actual definitions either...
1492+
"shm_open" |
1493+
"shm_unlink" |
1494+
"syscall" |
1495+
"mq_open" |
1496+
"mq_close" |
1497+
"mq_getattr" |
1498+
"mq_notify" |
1499+
"mq_receive" |
1500+
"mq_send" |
1501+
"mq_setattr" |
1502+
"mq_timedreceive" |
1503+
"mq_timedsend" |
1504+
"mq_unlink" |
1505+
"ptrace" |
1506+
"sigaltstack" if rumprun => true,
1507+
1508+
_ => false,
1509+
}
1510+
});
1511+
1512+
cfg.skip_field_type(move |struct_, field| {
1513+
// This is a weird union, don't check the type.
1514+
(struct_ == "ifaddrs" && field == "ifa_ifu") ||
1515+
// sighandler_t type is super weird
1516+
(struct_ == "sigaction" && field == "sa_sigaction") ||
1517+
// sigval is actually a union, but we pretend it's a struct
1518+
(struct_ == "sigevent" && field == "sigev_value") ||
1519+
// aio_buf is "volatile void*" and Rust doesn't understand volatile
1520+
(struct_ == "aiocb" && field == "aio_buf")
1521+
});
1522+
1523+
cfg.generate("../src/lib.rs", "main.rs");
1524+
}

0 commit comments

Comments
 (0)