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

support for windows #26

Merged
merged 5 commits into from
Jan 28, 2024
Merged

Conversation

threadedstream
Copy link
Contributor

I just thought that it wouldn't hurt to add support for windows systems.

src/lib.rs Outdated
#[path = "windows.rs"]
mod sys;

#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows", target_family = "wasm")))]
Copy link
Owner

Choose a reason for hiding this comment

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

As this grows more complicated, can the cfg_if crate be used to avoid a blowup of conditions here?

src/lib.rs Outdated
#[macro_use]
extern crate once_cell;
#[cfg(target_os = "windows")]
extern crate windows;
Copy link
Owner

Choose a reason for hiding this comment

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

I think neither of these should be necessary with Rust 2018

src/windows.rs Outdated

#[cfg(feature = "global")]
static LOCK: Lazy<windows::Win32::Foundation::HANDLE> = unsafe {
Lazy::new(|| {
Copy link
Owner

Choose a reason for hiding this comment

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

Given how low-level this crate is I think it would be best to not use an external crate to perform this initialization and instead internally use locking/synchronization as necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing is that I actually tried to initialize the lock without relying on external crate, but rust compiler didn't allow me to proceed displaying the following error message: calls in statics are limited to constant functions, tuple structs and tuple variants. So, I was advised to lazy-initialize the lock with the help of this crate. I'd be glad if you suggest an alternative

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry I don't know how best to fix that, but regardless I don't think that using an external crate is appropriate in this case for a lock around the allocator.

Choose a reason for hiding this comment

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

I think the best way to do this is to set the lock to Handle(0) at first. Then, in the lock functions, check if its equal to that and create the mutex if it is.

@@ -20,6 +20,22 @@ jobs:
- run: RUSTFLAGS='--cfg test_lots' cargo test --release
- run: RUSTFLAGS='--cfg test_lots' cargo test --release --features debug

windows-test:
name: Test-windows
runs-on: windows-latest
Copy link
Owner

Choose a reason for hiding this comment

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

Can this be added to the matrix above instead of duplicating the CI config?

alexcrichton added a commit that referenced this pull request Jan 28, 2024
@alexcrichton alexcrichton merged commit b36cdae into alexcrichton:main Jan 28, 2024
@alexcrichton
Copy link
Owner

I rebased this in #35 and handled some comments of mine, thanks for the PR!

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.

3 participants