Skip to content

Commit 385504e

Browse files
committed
Use unions and const size_of only if the Rust version supports them
1 parent 4fdbb44 commit 385504e

File tree

6 files changed

+67
-27
lines changed

6 files changed

+67
-27
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ matrix:
4949
- env: TARGET=sparc64-unknown-linux-gnu
5050
- env: TARGET=asmjs-unknown-emscripten
5151
- env: TARGET=wasm32-unknown-emscripten
52-
- env: TARGET=wasm32-unknown-unknown
53-
install: rustup target add $TARGET
54-
script: cargo build --no-default-features --target $TARGET --release
52+
- env: TARGET=wasm32-unknown-unknown BUILD_ONLY=1
5553

5654
allow_failures:
5755
# FIXME: https://github.com/rust-lang/libc/issues/1226
@@ -62,10 +60,16 @@ install:
6260
- rustup install beta
6361
- rustup install stable
6462
- rustup install 1.13.0
63+
- rustup install 1.19.0
64+
- rustup install 1.24.0
65+
- rustup install 1.30.0
6566
- rustup target add $TARGET || true
6667
- rustup target add $TARGET --toolchain beta || true
6768
- rustup target add $TARGET --toolchain stable || true
6869
- rustup target add $TARGET --toolchain 1.13.0 || true
70+
- rustup target add $TARGET --toolchain 1.19.0 || true
71+
- rustup target add $TARGET --toolchain 1.24.0 || true
72+
- rustup target add $TARGET --toolchain 1.30.0 || true
6973

7074
script:
7175
- cargo generate-lockfile --manifest-path libc-test/Cargo.toml

build.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@ use std::process::Command;
33
use std::str;
44

55
fn main() {
6-
/*
7-
* If `core::ffi::c_void` exists, libc can just re-export it. Otherwise, it
8-
* must define an incompatible type to retain backwards-compatibility.
9-
*/
10-
if rustc_minor_version().expect("Failed to get rustc version") >= 30 {
6+
7+
let rustc_minor_ver = rustc_minor_version().expect("Failed to get rustc version");
8+
9+
// Rust >= 1.19 supports unions:
10+
if rustc_minor_ver >= 19 {
11+
println!("cargo:rustc-cfg=libc_union");
12+
}
13+
14+
// Rust >= 1.24 supports const mem::size_of:
15+
if rustc_minor_ver >= 24 {
16+
println!("cargo:rustc-cfg=libc_const_size_of");
17+
}
18+
19+
// If `core::ffi::c_void` exists, libc can just re-export it. Otherwise, it
20+
// must define an incompatible type to retain backwards-compatibility.
21+
if rustc_minor_ver >= 30 {
1122
println!("cargo:rustc-cfg=core_cvoid");
1223
}
1324
}

ci/run-docker.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ run() {
2828
--volume "$(pwd)":/checkout:ro \
2929
--volume "$(pwd)"/target:/checkout/target \
3030
--env CARGO_TARGET_DIR=/checkout/target \
31+
--env BUILD_ONLY="$BUILD_ONLY" \
3132
--workdir /checkout \
3233
libc \
3334
ci/run.sh "${1}"

ci/run.sh

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ if [ "$QEMU" != "" ]; then
8080
exec grep "^PASSED .* tests" "${CARGO_TARGET_DIR}/out.log"
8181
fi
8282

83-
build_types="+nightly +beta +stable +1.13.0"
83+
build_types="+nightly +beta +stable +1.13.0 +1.19.0 +1.24.0 +1.30.0"
8484
for build_type in $build_types;
8585
do
86-
8786
opt=
8887
if [ "$TARGET" = "x86_64-unknown-linux-gnux32" ]; then
89-
# FIXME: x86_64-unknown-linux-gnux32 fail to compile without --release
88+
# FIXME: x86_64-unknown-linux-gnux32 fail to compile without
89+
# --release
90+
#
9091
# See https://github.com/rust-lang/rust/issues/45417
9192
opt="--release"
9293

@@ -96,17 +97,29 @@ do
9697
fi
9798
fi
9899

99-
# Building with --no-default-features is currently broken on rumprun because we
100-
# need cfg(target_vendor), which is currently unstable.
101-
if [ "$TARGET" != "x86_64-rumprun-netbsd" ]; then
102-
cargo "$build_type" test $opt --no-default-features --manifest-path libc-test/Cargo.toml --target "${TARGET}"
103-
fi
100+
if [ "$BUILD_ONLY" = "1" ]; then
101+
cargo "$build_type" build $opt --target "${TARGET}"
102+
else
103+
# Building with --no-default-features is currently broken on rumprun
104+
# because we need cfg(target_vendor), which is currently unstable.
105+
if [ "$TARGET" != "x86_64-rumprun-netbsd" ]; then
106+
cargo "$build_type" test $opt \
107+
--no-default-features \
108+
--manifest-path libc-test/Cargo.toml \
109+
--target "${TARGET}"
110+
fi
104111

105-
# Test the #[repr(align(x))] feature; requires Rust >= 1.25.0
106-
if [ "$build_type" != "+1.13.0" ]; then
107-
cargo "$build_type" test $opt --features align --manifest-path libc-test/Cargo.toml --target "${TARGET}"
108-
fi
112+
# Test the #[repr(align(x))] feature; requires Rust >= 1.25.0
113+
if [ "$build_type" != "+1.13.0" ]; then
114+
cargo "$build_type" test $opt \
115+
--features align \
116+
--manifest-path libc-test/Cargo.toml \
117+
--target "${TARGET}"
118+
fi
109119

110-
exec cargo "$build_type" test $opt --manifest-path libc-test/Cargo.toml --target "${TARGET}"
120+
cargo "$build_type" test $opt \
121+
--manifest-path libc-test/Cargo.toml \
122+
--target "${TARGET}"
123+
fi
111124
done
112125

src/unix/bsd/apple/mod.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,6 @@ s! {
557557
pub sem_pad3: [::int32_t; 4],
558558
}
559559

560-
pub union semun {
561-
pub val: ::c_int,
562-
pub buf: *mut semid_ds,
563-
pub array: *mut ::c_ushort,
564-
}
565-
566560
// sys/shm.h
567561

568562
#[cfg_attr(feature = "rustc-dep-of-std", repr(packed(4)))]
@@ -589,6 +583,15 @@ s! {
589583
}
590584
}
591585

586+
#[cfg(libc_union)]
587+
s! {
588+
pub union semun {
589+
pub val: ::c_int,
590+
pub buf: *mut semid_ds,
591+
pub array: *mut ::c_ushort,
592+
}
593+
}
594+
592595
pub const _UTX_USERSIZE: usize = 256;
593596
pub const _UTX_LINESIZE: usize = 32;
594597
pub const _UTX_IDSIZE: usize = 4;
@@ -2384,11 +2387,18 @@ pub const SF_IMMUTABLE: ::c_uint = 0x00020000;
23842387
pub const SF_APPEND: ::c_uint = 0x00040000;
23852388
pub const UF_HIDDEN: ::c_uint = 0x00008000;
23862389

2390+
#[cfg(libc_const_size_of)]
23872391
fn __DARWIN_ALIGN32(p: usize) -> usize {
23882392
const __DARWIN_ALIGNBYTES32: usize = mem::size_of::<u32>() - 1;
23892393
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
23902394
}
23912395

2396+
#[cfg(not(libc_const_size_of))]
2397+
fn __DARWIN_ALIGN32(p: usize) -> usize {
2398+
let __DARWIN_ALIGNBYTES32: usize = mem::size_of::<u32>() - 1;
2399+
p + __DARWIN_ALIGNBYTES32 & !__DARWIN_ALIGNBYTES32
2400+
}
2401+
23922402
f! {
23932403
pub fn CMSG_NXTHDR(mhdr: *const ::msghdr,
23942404
cmsg: *const ::cmsghdr) -> *mut ::cmsghdr {

src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ s! {
5151
pub mount_info: mount_info,
5252
}
5353

54+
#[cfg(libc_union)]
5455
pub union mount_info {
5556
pub ufs_args: ufs_args,
5657
pub mfs_args: mfs_args,

0 commit comments

Comments
 (0)