diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3364e78..2d50641 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: matrix: os: - ubuntu-latest - - macOS-latest + - macos-latest - windows-latest steps: - uses: actions/checkout@v7 @@ -90,7 +90,7 @@ jobs: # # See https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-2-with-host-tools name: Tier 2 (with Host Tools) - needs: tier1 + needs: msrv runs-on: ${{ matrix.os }} strategy: matrix: @@ -138,7 +138,7 @@ jobs: # # See https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-2-with-host-tools name: Tier 2 (with Host Tools, via Cross) - needs: tier1 + needs: msrv runs-on: ubuntu-latest strategy: matrix: @@ -165,7 +165,7 @@ jobs: # # See https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-2-with-host-tools name: Tier 2 (without Host Tools) - needs: tier1 + needs: msrv runs-on: ${{ matrix.os }} strategy: matrix: @@ -241,7 +241,7 @@ jobs: # # See https://doc.rust-lang.org/nightly/rustc/platform-support.html#tier-2-with-host-tools name: Tier 2 (without Host Tools) - needs: tier1 + needs: msrv runs-on: ${{ matrix.os }} strategy: matrix: @@ -261,21 +261,56 @@ jobs: run: | cross build --locked --target=${{ matrix.target }} - msrv: - name: MSRV + tier3: + # Matches Rust "Tier 3" platform support + # For as much as possible, but where `cross` is needed for cross-compilation + # + # See https://doc.rust-lang.org/rustc/platform-support.html#tier-3 + name: Tier 3 + needs: msrv + runs-on: ubuntu-latest strategy: matrix: - include: - - os: ubuntu-latest - - os: macos-latest - - os: windows-latest - - runs-on: ${{ matrix.os }} + target: + - powerpc64-ibm-aix steps: - uses: actions/checkout@v7 - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@master + uses: dtolnay/rust-toolchain@nightly + - uses: taiki-e/install-action@v2.87.11 with: - toolchain: 1.85 + tool: cross + - name: Run build + run: | + cross build -Zbuild-std --locked --all-features --target=${{ matrix.target }} + + msrv: + name: MSRV + runs-on: ubuntu-latest + env: + # Matches Tier 1 job targets + TARGETS: | + aarch64-unknown-linux-gnu + i686-unknown-linux-gnu + x86_64-unknown-linux-gnu + i686-pc-windows-gnu + i686-pc-windows-msvc + x86_64-pc-windows-gnu + x86_64-pc-windows-msvc + x86_64-apple-darwin + steps: + - uses: actions/checkout@v7 + - uses: taiki-e/install-action@v2.87.11 + with: + tool: | + cargo-hack + cargo-minimal-versions + fallback: none - name: Check MSRV - run: cargo check --locked --lib --all-features + run: | + cargo minimal-versions check \ + --workspace \ + --feature-powerset \ + --ignore-private \ + --rust-version \ + $(printf '%s\n' "$TARGETS" | xargs -n1 printf -- '--target %s ') diff --git a/Cargo.lock b/Cargo.lock index 7dcb661..598dad2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -92,7 +92,7 @@ dependencies = [ "similar-asserts", "version-sync", "windows-bindgen", - "windows-link 0.100.0", + "windows-link", ] [[package]] @@ -244,6 +244,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + [[package]] name = "libc" version = "0.2.189" @@ -326,6 +332,12 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + [[package]] name = "semver" version = "1.0.26" @@ -352,6 +364,18 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "serde_spanned" version = "0.6.8" @@ -517,47 +541,37 @@ dependencies = [ [[package]] name = "windows-bindgen" -version = "0.100.0" +version = "0.66.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6bb7c22ca81c6dc1554fd328c12697b4b0ad5c45081df2c3c9a3f89cc467da2" +checksum = "81b7ec123a4eadd44d1f44f76804316b477b2537abed9a2ab950b3c54afa1fcf" dependencies = [ - "proc-macro2", - "quote", - "windows-default", - "windows-metadata", + "serde", + "serde_json", + "windows-threading", ] -[[package]] -name = "windows-default" -version = "0.100.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4882bb065b03115aa8891d44d076bbe843d286d8bfd0b55caaa4b049141a712" - [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" -[[package]] -name = "windows-link" -version = "0.100.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b39de7c7fe78858b0144c50c3fc000bab3be17d5e9b85b1053871693c7f7415" - -[[package]] -name = "windows-metadata" -version = "0.100.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d3a758dc1da4ae61aa7f93afbb505d564c72dd6431e513ed581377857896a72" - [[package]] name = "windows-sys" version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ - "windows-link 0.2.1", + "windows-link", +] + +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 6f46ab2..b72f6fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/djc/hostname" readme = "README.md" license = "MIT" edition = "2021" -rust-version = "1.85" +rust-version = "1.71" [features] default = [] @@ -19,15 +19,15 @@ set = [] cfg-if = "1" [target.'cfg(any(unix, target_os = "redox"))'.dependencies] -libc = "0.2" +libc = "0.2.140" [target.'cfg(target_os = "windows")'.dependencies] -windows-link = "0.100" +windows-link = "0.2" [dev-dependencies] similar-asserts = { version = "2.0.0" } version-sync = "0.9" -windows-bindgen = "0.100" +windows-bindgen = "0.66" [package.metadata.docs.rs] features = ["set"] diff --git a/README.md b/README.md index 308bd5c..0126547 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Latest Version](https://img.shields.io/crates/v/hostname.svg)](https://crates.io/crates/hostname) [![Latest Version](https://docs.rs/hostname/badge.svg)](https://docs.rs/hostname) [![Build Status](https://github.com/djc/hostname/actions/workflows/ci.yml/badge.svg)](https://github.com/djc/hostname/actions) -![Minimum rustc Version](https://img.shields.io/badge/rustc-1.74+-green.svg) +![Minimum rustc Version](https://img.shields.io/badge/rustc-1.71+-green.svg) ![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg) ![crates.io](https://img.shields.io/crates/d/hostname) @@ -17,7 +17,7 @@ ## Rust version requirements -Since version `0.4.0` this crate requires Rust version `1.74` or greater. +Since version `0.4.3` this crate requires Rust version `1.71` or greater. This version is explicitly tested in CI and may be bumped in any major or minor release as needed.\ diff --git a/src/lib.rs b/src/lib.rs index cec7838..7ac652e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,6 @@ cfg_if! { mod nix; use crate::nix as sys; } else if #[cfg(target_os = "windows")] { - #[allow(dead_code, nonstandard_style, non_upper_case_globals, clippy::upper_case_acronyms)] mod windows; use crate::windows as sys; } else { diff --git a/src/nix.rs b/src/nix.rs index 0737ee0..568d8f6 100644 --- a/src/nix.rs +++ b/src/nix.rs @@ -45,10 +45,10 @@ fn wrap_buffer(mut bytes: Vec) -> OsString { #[cfg(feature = "set")] pub fn set(hostname: &OsStr) -> io::Result<()> { #[cfg(not(any( + target_vendor = "apple", + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", target_os = "solaris", target_os = "illumos" )))] @@ -56,10 +56,10 @@ pub fn set(hostname: &OsStr) -> io::Result<()> { type hostname_len_t = libc::size_t; #[cfg(any( + target_vendor = "apple", + target_os = "aix", target_os = "dragonfly", target_os = "freebsd", - target_os = "ios", - target_os = "macos", target_os = "solaris", target_os = "illumos" ))] @@ -69,7 +69,7 @@ pub fn set(hostname: &OsStr) -> io::Result<()> { #[allow(clippy::unnecessary_cast)] // Cast is needed for the `libc::c_int` type if hostname.len() > hostname_len_t::MAX as usize { - return Err(io::Error::other("hostname too long")); + return Err(io::Error::new(io::ErrorKind::Other, "hostname too long")); } let size = hostname.len() as hostname_len_t; diff --git a/src/windows/bindings.rs b/src/windows/bindings.rs index 4b8da22..058e5c5 100644 --- a/src/windows/bindings.rs +++ b/src/windows/bindings.rs @@ -1,7 +1,15 @@ +#![allow( + non_snake_case, + non_upper_case_globals, + non_camel_case_types, + dead_code, + clippy::all +)] + windows_link::link!("kernel32.dll" "system" fn GetComputerNameExW(nametype : COMPUTER_NAME_FORMAT, lpbuffer : PWSTR, nsize : *mut u32) -> BOOL); windows_link::link!("kernel32.dll" "system" fn SetComputerNameExW(nametype : COMPUTER_NAME_FORMAT, lpbuffer : PCWSTR) -> BOOL); pub type BOOL = i32; pub type COMPUTER_NAME_FORMAT = i32; -pub const ComputerNamePhysicalDnsHostname: COMPUTER_NAME_FORMAT = 5; +pub const ComputerNamePhysicalDnsHostname: COMPUTER_NAME_FORMAT = 5i32; pub type PCWSTR = *const u16; pub type PWSTR = *mut u16; diff --git a/tests/bindings.txt b/tests/bindings.txt new file mode 100644 index 0000000..cfaf66f --- /dev/null +++ b/tests/bindings.txt @@ -0,0 +1,6 @@ +--out src/windows/bindings.rs +--flat --sys --no-comment +--filter + ComputerNamePhysicalDnsHostname + GetComputerNameExW + SetComputerNameExW diff --git a/tests/codegen.rs b/tests/codegen.rs index e0ec8c7..c1a35a6 100644 --- a/tests/codegen.rs +++ b/tests/codegen.rs @@ -1,28 +1,22 @@ use std::fs; use std::process::Command; -use windows_bindgen::Bindgen; +use windows_bindgen::bindgen; #[test] fn gen_bindings() { let output = "src/windows/bindings.rs"; let existing = fs::read_to_string(output).unwrap(); - Bindgen::new() - .filter("ComputerNamePhysicalDnsHostname") - .filter("GetComputerNameExW") - .filter("SetComputerNameExW") - .output("src/windows/bindings.rs") - .flat() - .sys() - .dead_code() - .write(); - + bindgen(["--no-deps", "--etc", "tests/bindings.txt"]).unwrap(); let out = Command::new("rustfmt") .arg("--edition=2021") .arg(output) .output() .unwrap(); + + dbg!(String::from_utf8(out.stdout).unwrap()); + dbg!(String::from_utf8(out.stderr).unwrap()); assert!(out.status.success()); // Check the output is the same as before.