Skip to content

Restore compatibility with windows-sys 0.52#238

Closed
hanna-kruppe wants to merge 2 commits into
rust-cli:mainfrom
hanna-kruppe:windows-sys-0.52
Closed

Restore compatibility with windows-sys 0.52#238
hanna-kruppe wants to merge 2 commits into
rust-cli:mainfrom
hanna-kruppe:windows-sys-0.52

Conversation

@hanna-kruppe
Copy link
Copy Markdown
Contributor

windows-sys 0.59 has been out for half a year, but a good chunk of the ecosystem hasn't fully moved off 0.52 yet. In fact, crates.io still reports slightly higher daily download numbers for 0.52 than for 0.59 up to this day. This often leads to larger workspaces pulling in both versions. Some libraries that can easily remain compatible with both versions are mitigating this by relaxing their version requirements, making it easier to stay exclusively on 0.52 until all transitive dependencies are compatible with 0.59.

It turns out that anstyle-{query,wincon} can also be made compatible with both versions, see first commit for the details.

The second commit fixes accumulated clippy warnings in windows-specific code. I guess the clippy job in CI only runs on Linux and people rarely touch this code?

Similarly, I think the compatibility with windows-sys 0.52 won't be tested in CI because the minimal-versions job only runs on Linux. I did test it manually.

windows-sys 0.59 changed `HANDLE` from `isize` to `*mut c_void`. This
only matters in two places that check for null. Doing that check in
terms of std's `RawHandle` before converting to the windows-sys type
makes the code compatible with either version.
Comment on lines -12 to +18
INITIAL
.get_or_init(|| get_colors_(&std::io::stdout()))
.clone()
.map_err(Into::into)
(*INITIAL.get_or_init(|| get_colors_(&std::io::stdout()))).map_err(Into::into)
}

/// Cached [`get_colors`] call for [`std::io::stderr`]
pub fn stderr_initial_colors() -> StdioColorResult {
static INITIAL: std::sync::OnceLock<StdioColorInnerResult> = std::sync::OnceLock::new();
INITIAL
.get_or_init(|| get_colors_(&std::io::stderr()))
.clone()
.map_err(Into::into)
(*INITIAL.get_or_init(|| get_colors_(&std::io::stderr()))).map_err(Into::into)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied the suggestion for clippy::clone_on_copy but I was not sure what to do about the other warning about OnceLock being too new for the MSRV:

warning: current MSRV (Minimum Supported Rust Version) is `1.66.0` but this item is stable since `1.70.0`
  --> crates\anstyle-wincon\src\windows.rs:13:10
   |
13 |         .get_or_init(|| get_colors_(&std::io::stdout()))
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
   = note: `#[warn(clippy::incompatible_msrv)]` on by default

@epage
Copy link
Copy Markdown
Collaborator

epage commented Jan 13, 2025

I've pulled the clippy changes out into #239.

As for the main change, I would like to hold off for now. Multi-major versions add risks and with this being a less well tested platform, deals with unsafe, and is for an API I'm less familiar with, I'm uncomfortable doing this at this point. So far I only do this for git2 in some of my packages and the motivation there is stronger due to links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants