Skip to content

Commit 526aff1

Browse files
Berrysoftjosephlr
andauthored
Add cygwin support (#626)
Need rust-lang/rust#137621 to test. --------- Co-authored-by: Joe Richey <[email protected]>
1 parent b160ef6 commit 526aff1

File tree

6 files changed

+11
-2
lines changed

6 files changed

+11
-2
lines changed

.github/workflows/build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ jobs:
9494
x86_64-wrs-vxworks,
9595
x86_64-unknown-dragonfly,
9696
x86_64-unknown-haiku,
97+
# TODO: once libc support for cygwin is released
98+
# https://github.com/rust-lang/libc/pull/4308
99+
# x86_64-pc-cygwin,
97100
]
98101
steps:
99102
- uses: actions/checkout@v4

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `.cargo/config.toml` example in the crate-level docs [#591]
1313
- `getrandom_test_linux_without_fallback` configuration flag to test that file fallback
1414
is not triggered in the `linux_android_with_fallback` backend [#605]
15+
- Cygwin support [#626]
1516

1617
### Changed
1718
- Remove `windows-targets` dependency and use [`raw-dylib`] directly [#627]
@@ -37,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3738
[#605]: https://github.com/rust-random/getrandom/pull/605
3839
[#610]: https://github.com/rust-random/getrandom/pull/610
3940
[#614]: https://github.com/rust-random/getrandom/pull/614
41+
[#626]: https://github.com/rust-random/getrandom/pull/626
4042
[#627]: https://github.com/rust-random/getrandom/pull/627
4143
[`raw-dylib`]: https://doc.rust-lang.org/reference/items/external-blocks.html?highlight=link#dylib-versus-raw-dylib
4244

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ r-efi = { version = "5.1", default-features = false }
4747
libc = { version = "0.2.154", default-features = false }
4848

4949
# getrandom
50-
[target.'cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "hurd", target_os = "illumos", all(target_os = "horizon", target_arch = "arm")))'.dependencies]
50+
[target.'cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "hurd", target_os = "illumos", target_os = "cygwin", all(target_os = "horizon", target_arch = "arm")))'.dependencies]
5151
libc = { version = "0.2.154", default-features = false }
5252

5353
# netbsd
@@ -87,6 +87,7 @@ check-cfg = [
8787
'cfg(getrandom_test_linux_fallback)',
8888
'cfg(getrandom_test_linux_without_fallback)',
8989
'cfg(getrandom_test_netbsd_fallback)',
90+
'cfg(target_os, values("cygwin"))', # TODO(MSRV 1.86): Remove this.
9091
]
9192

9293
[package.metadata.docs.rs]

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ fn get_random_u128() -> Result<u128, getrandom::Error> {
6969
| PS Vita | `*-vita-*` | [`getentropy`][19]
7070
| QNX Neutrino | `*‑nto-qnx*` | [`/dev/urandom`][14] (identical to `/dev/random`)
7171
| AIX | `*-ibm-aix` | [`/dev/urandom`][15]
72+
| Cygwin | `*-cygwin` | [`getrandom`][20] (based on [`RtlGenRandom`])
7273

7374
Pull Requests that add support for new targets to `getrandom` are always welcome.
7475

@@ -351,6 +352,7 @@ dual licensed as above, without any additional terms or conditions.
351352
[17]: https://www.gnu.org/software/libc/manual/html_mono/libc.html#index-getrandom
352353
[18]: https://github.com/rust3ds/shim-3ds/commit/b01d2568836dea2a65d05d662f8e5f805c64389d
353354
[19]: https://github.com/vitasdk/newlib/blob/2d869fe47aaf02b8e52d04e9a2b79d5b210fd016/newlib/libc/sys/vita/getentropy.c
355+
[20]: https://github.com/cygwin/cygwin/blob/main/winsup/cygwin/libc/getentropy.cc
354356

355357
[`ProcessPrng`]: https://learn.microsoft.com/en-us/windows/win32/seccng/processprng
356358
[`RtlGenRandom`]: https://learn.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom

src/backends.rs

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ cfg_if! {
104104
target_os = "freebsd",
105105
target_os = "hurd",
106106
target_os = "illumos",
107+
target_os = "cygwin",
107108
// Check for target_arch = "arm" to only include the 3DS. Does not
108109
// include the Nintendo Switch (which is target_arch = "aarch64").
109110
all(target_os = "horizon", target_arch = "arm"),

src/util_libc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::Error;
22
use core::mem::MaybeUninit;
33

44
cfg_if! {
5-
if #[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "android"))] {
5+
if #[cfg(any(target_os = "netbsd", target_os = "openbsd", target_os = "android", target_os = "cygwin"))] {
66
use libc::__errno as errno_location;
77
} else if #[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "hurd", target_os = "redox", target_os = "dragonfly"))] {
88
use libc::__errno_location as errno_location;

0 commit comments

Comments
 (0)