Skip to content

Always deny warnings in CI #4363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ on:
types: [opened, synchronize, reopened]

env:
CARGO_TERM_COLOR: always
CARGO_TERM_VERBOSE: true
LIBC_CI: 1
RUSTDOCFLAGS: -Dwarnings
RUSTFLAGS: -Dwarnings
RUST_BACKTRACE: full

defaults:
run:
Expand Down Expand Up @@ -41,6 +45,12 @@ jobs:
TOOLCHAIN: ${{ matrix.toolchain }}
steps:
- uses: actions/checkout@v4
# Remove `-Dwarnings` at the MSRV since lints may be different or buffier
- name: Update RUSTFLAGS
run: |
set -eux
[ "${{ matrix.toolchain }}" = "1.63.0" ] && echo 'RUSTFLAGS=' >> "$GITHUB_ENV" || true

- name: Setup Rust toolchain
run: ./ci/install-rust.sh

Expand Down
1 change: 1 addition & 0 deletions libc-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ A test crate for the libc crate.
"""

[dependencies]
cfg-if = "1.0.0"
libc = { path = "..", version = "1.0.0-alpha.1", default-features = false }

[dev-dependencies]
Expand Down
223 changes: 106 additions & 117 deletions libc-test/test/makedev.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,7 @@
//! Compare libc's makedev, major, minor functions against the actual C macros, for various
//! inputs.

#[cfg(any(target_os = "solaris", target_os = "illumos"))]
mod ret {
pub type MajorRetType = libc::major_t;
pub type MinorRetType = libc::minor_t;
}

#[cfg(any(
target_os = "linux",
target_os = "l4re",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "aix",
target_os = "nto",
target_os = "hurd",
target_os = "openbsd",
target_os = "cygwin",
))]
mod ret {
pub type MajorRetType = libc::c_uint;
pub type MinorRetType = libc::c_uint;
}

#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "freebsd",
))]
mod ret {
pub type MajorRetType = libc::c_int;
pub type MinorRetType = libc::c_int;
}

#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))]
mod ret {
pub type MajorRetType = i32;
pub type MinorRetType = i32;
}

#[cfg(any(
#![cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "emscripten",
Expand All @@ -57,100 +12,134 @@ mod ret {
target_os = "openbsd",
target_os = "cygwin",
))]
mod t {
use libc::{self, c_uint, dev_t};

use super::ret::*;
use libc::{self, c_uint, dev_t};

extern "C" {
pub fn makedev_ffi(major: c_uint, minor: c_uint) -> dev_t;
pub fn major_ffi(dev: dev_t) -> c_uint;
pub fn minor_ffi(dev: dev_t) -> c_uint;
cfg_if::cfg_if! {
if #[cfg(any(target_os = "solaris", target_os = "illumos"))] {
pub type MajorRetType = libc::major_t;
pub type MinorRetType = libc::minor_t;
} else if #[cfg(any(
target_os = "linux",
target_os = "l4re",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "aix",
target_os = "nto",
target_os = "hurd",
target_os = "openbsd",
target_os = "cygwin",
))] {
pub type MajorRetType = libc::c_uint;
pub type MinorRetType = libc::c_uint;
} else if #[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "netbsd",
target_os = "freebsd",
))] {
pub type MajorRetType = libc::c_int;
pub type MinorRetType = libc::c_int;
} else if #[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos"
))] {
pub type MajorRetType = i32;
pub type MinorRetType = i32;
}
}

fn compare(major: c_uint, minor: c_uint) {
let dev = unsafe { makedev_ffi(major, minor) };
assert_eq!(libc::makedev(major, minor), dev);
let major = unsafe { major_ffi(dev) };
assert_eq!(libc::major(dev), major as MajorRetType);
let minor = unsafe { minor_ffi(dev) };
assert_eq!(libc::minor(dev), minor as MinorRetType);
}
extern "C" {
pub fn makedev_ffi(major: c_uint, minor: c_uint) -> dev_t;
pub fn major_ffi(dev: dev_t) -> c_uint;
pub fn minor_ffi(dev: dev_t) -> c_uint;
}

// Every OS should be able to handle 8 bit major and minor numbers
#[test]
fn test_8bits() {
for major in 0..256 {
for minor in 0..256 {
compare(major, minor);
}
fn compare(major: c_uint, minor: c_uint) {
let dev = unsafe { makedev_ffi(major, minor) };
assert_eq!(libc::makedev(major, minor), dev);
let major = unsafe { major_ffi(dev) };
assert_eq!(libc::major(dev), major as MajorRetType);
let minor = unsafe { minor_ffi(dev) };
assert_eq!(libc::minor(dev), minor as MinorRetType);
}

// Every OS should be able to handle 8 bit major and minor numbers
#[test]
fn test_8bits() {
for major in 0..256 {
for minor in 0..256 {
compare(major, minor);
}
}
}

// Android allows 12 bits for major and 20 for minor
#[test]
#[cfg(target_os = "android")]
fn test_android_like() {
for major in [0, 1, 255, 256, 4095] {
for minor_exp in [1, 8, 16] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
// Android allows 12 bits for major and 20 for minor
#[test]
#[cfg(target_os = "android")]
fn test_android_like() {
for major in [0, 1, 255, 256, 4095] {
for minor_exp in [1, 8, 16] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
compare(major, (1 << 20) - 1);
}
compare(major, (1 << 20) - 1);
}
}

// These OSes allow 32 bits for minor, but only 8 for major
#[test]
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd",))]
fn test_fbsd11_like() {
for major in [0, 1, 255] {
for minor_exp in [1, 8, 16, 24, 31] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
// These OSes allow 32 bits for minor, but only 8 for major
#[test]
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd",))]
fn test_fbsd11_like() {
for major in [0, 1, 255] {
for minor_exp in [1, 8, 16, 24, 31] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
compare(major, c_uint::MAX);
}
compare(major, c_uint::MAX);
}
}

// OpenBSD allows 8 bits for major and 24 for minor
#[test]
#[cfg(target_os = "openbsd")]
fn test_openbsd_like() {
for major in [0, 1, 255] {
for minor_exp in [1, 8, 16] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
// OpenBSD allows 8 bits for major and 24 for minor
#[test]
#[cfg(target_os = "openbsd")]
fn test_openbsd_like() {
for major in [0, 1, 255] {
for minor_exp in [1, 8, 16] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
compare(major, (1 << 24) - 1);
}
compare(major, (1 << 24) - 1);
}
}

// These OSes allow 32 bits for both minor and major
#[cfg(any(
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "cygwin",
))]
#[test]
fn test_fbsd12_like() {
if std::mem::size_of::<dev_t>() >= 8 {
for major_exp in [0, 16, 24, 31] {
for major in [(1 << major_exp) - 1, (1 << major_exp)] {
for minor_exp in [1, 8, 16, 24, 31] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
// These OSes allow 32 bits for both minor and major
#[cfg(any(
target_os = "emscripten",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "cygwin",
))]
#[test]
fn test_fbsd12_like() {
if std::mem::size_of::<dev_t>() >= 8 {
for major_exp in [0, 16, 24, 31] {
for major in [(1 << major_exp) - 1, (1 << major_exp)] {
for minor_exp in [1, 8, 16, 24, 31] {
for minor in [(1 << minor_exp) - 1, (1 << minor_exp)] {
compare(major, minor);
}
compare(major, c_uint::MAX);
}
compare(c_uint::MAX, c_uint::MAX);
compare(major, c_uint::MAX);
}
compare(c_uint::MAX, c_uint::MAX);
}
}
}
Loading