Skip to content
Draft
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
67 changes: 51 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
os:
- ubuntu-latest
- macOS-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v7
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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 ')
66 changes: 40 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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.\
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/nix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ fn wrap_buffer(mut bytes: Vec<u8>) -> 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"
)))]
#[allow(non_camel_case_types)]
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"
))]
Expand All @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion src/windows/bindings.rs
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions tests/bindings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--out src/windows/bindings.rs
--flat --sys --no-comment
--filter
ComputerNamePhysicalDnsHostname
GetComputerNameExW
SetComputerNameExW
16 changes: 5 additions & 11 deletions tests/codegen.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading