Skip to content
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

Restore compatibility with windows-sys 0.52 #238

Closed
wants to merge 2 commits into from

Conversation

hanna-kruppe
Copy link
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
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
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.

@epage epage closed this Jan 13, 2025
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