From b2050f39c616ec167825b1c778add7e5f6a5049a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Fri, 28 Mar 2025 13:52:41 +0800 Subject: [PATCH 1/7] feat: add cygwin support --- src/os/unix/consts.rs | 4 ++++ src/os/unix/mod.rs | 3 ++- tests/functions.rs | 4 ++++ tests/library_filename.rs | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/os/unix/consts.rs b/src/os/unix/consts.rs index 4f069e212..4ae00592d 100644 --- a/src/os/unix/consts.rs +++ b/src/os/unix/consts.rs @@ -88,6 +88,7 @@ mod posix { target_os = "redox", target_os = "nto", target_os = "hurd", + target_os = "cygwin", ))] { pub(super) const RTLD_LAZY: c_int = 1; } else { @@ -127,6 +128,7 @@ mod posix { target_os = "redox", target_os = "nto", target_os = "hurd", + target_os = "cygwin", ))] { pub(super) const RTLD_NOW: c_int = 2; } else if #[cfg(all(target_os = "android",target_pointer_width = "32"))] { @@ -150,6 +152,7 @@ mod posix { target_env = "uclibc", all(target_os = "linux", target_arch = "mips"), all(target_os = "linux", target_arch = "mips64"), + target_os = "cygwin", ))] { pub(super) const RTLD_GLOBAL: c_int = 4; } else if #[cfg(any( @@ -224,6 +227,7 @@ mod posix { target_os = "fuchsia", target_os = "redox", target_os = "hurd", + target_os = "cygwin", ))] { pub(super) const RTLD_LOCAL: c_int = 0; } else { diff --git a/src/os/unix/mod.rs b/src/os/unix/mod.rs index a575d9aba..0e42c50d9 100644 --- a/src/os/unix/mod.rs +++ b/src/os/unix/mod.rs @@ -278,7 +278,8 @@ impl Library { target_os = "solaris", target_os = "illumos", target_os = "redox", - target_os = "fuchsia" + target_os = "fuchsia", + target_os = "cygwin", ))] { self.get_singlethreaded(symbol) } else { diff --git a/tests/functions.rs b/tests/functions.rs index b9c9ac315..c94592e7a 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -191,6 +191,8 @@ fn test_static_ptr() { // the target. Especially since it is very unlikely to be fixed given the state of support its // support. #[cfg(not(all(target_arch = "x86", target_os = "windows", target_env = "gnu")))] +// Cygwin returns errors on `close`. +#[cfg(not(target_os = "cygwin"))] fn manual_close_many_times() { make_helpers(); let join_handles: Vec<_> = (0..16) @@ -224,6 +226,8 @@ fn library_this_get() { .get::(b"test_identity_u32") .is_err()); // Something obscure from libc... + // Cygwin behaves like Windows so ignore it. + #[cfg(not(target_os = "cygwin"))] assert!(this.get::(b"freopen").is_ok()); } } diff --git a/tests/library_filename.rs b/tests/library_filename.rs index efe51b865..4642ece08 100644 --- a/tests/library_filename.rs +++ b/tests/library_filename.rs @@ -2,7 +2,7 @@ extern crate libloading; use libloading::library_filename; use std::path::Path; -#[cfg(target_os = "windows")] +#[cfg(any(target_os = "windows", target_os = "cygwin"))] const EXPECTED: &str = "audioengine.dll"; #[cfg(target_os = "linux")] const EXPECTED: &str = "libaudioengine.so"; From b6cedfcfbe2c29869d9645669763ae597d70f9ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Sun, 30 Mar 2025 17:40:55 +0800 Subject: [PATCH 2/7] ci: add cygwin test on MSYS2 --- .github/workflows/libloading.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index 0f63b7c6d..78373e83f 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -65,6 +65,26 @@ jobs: env: TARGET: ${{ matrix.rust_target}} + msys2-test: + runs-on: windows-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v2 + - run: rustup install nightly --profile=minimal + - run: rustup default nightly + - uses: msys2/setup-msys2@v2 + with: + release: false + install: gcc + - run: mkdir .cargo + - run: echo "[target.x86_64-pc-cygwin]" | Out-File -FilePath .cargo/config.toml -Append + - run: echo 'linker = "x86_64-pc-msys-gcc.exe"' | Out-File -FilePath .cargo/config.toml -Append + - run: echo "INPUT(libmsys-2.0.a)" | Out-File -FilePath "C:\msys64\usr\lib\libcygwin.a" + - run: cargo test --target x86_64-pc-cygwin -Zbuild-std + env: + TARGET: x86_64-pc-windows-msvc + bare-cross-build: runs-on: ubuntu-latest strategy: From 5c4ca09bdc616a8ecb2e319d946c5e3dc6159dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Mon, 31 Mar 2025 01:06:05 +0800 Subject: [PATCH 3/7] ci: fix rust-src and use env vars --- .github/workflows/libloading.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index 78373e83f..254bb75b2 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -73,17 +73,16 @@ jobs: - uses: actions/checkout@v2 - run: rustup install nightly --profile=minimal - run: rustup default nightly + - run: rustup component add rust-src - uses: msys2/setup-msys2@v2 with: release: false install: gcc - - run: mkdir .cargo - - run: echo "[target.x86_64-pc-cygwin]" | Out-File -FilePath .cargo/config.toml -Append - - run: echo 'linker = "x86_64-pc-msys-gcc.exe"' | Out-File -FilePath .cargo/config.toml -Append - run: echo "INPUT(libmsys-2.0.a)" | Out-File -FilePath "C:\msys64\usr\lib\libcygwin.a" - run: cargo test --target x86_64-pc-cygwin -Zbuild-std env: TARGET: x86_64-pc-windows-msvc + CARGO_TARGET_X86_64_PC_CYGWIN_LINKER: x86_64-pc-msys-gcc.exe bare-cross-build: runs-on: ubuntu-latest From 9630ca160cf30629b5ebb7d846804535fc4d8538 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Mon, 31 Mar 2025 01:08:10 +0800 Subject: [PATCH 4/7] fix: add cygwin as unexpected cfg --- Cargo.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5192896cb..75e146265 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,4 +34,7 @@ all-features = true rustdoc-args = ["--cfg", "libloading_docs"] [lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(libloading_docs)'] } +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(libloading_docs)', + 'cfg(target_os, values("cygwin"))', +] } From 206e8776d7b9c5cfee61eb8c92725dbf094c48cb Mon Sep 17 00:00:00 2001 From: Berrysoft Date: Mon, 31 Mar 2025 11:23:23 +0800 Subject: [PATCH 5/7] fix: specify cygwin linker by absolute path --- .github/workflows/libloading.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index 254bb75b2..a36c57c38 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -82,7 +82,7 @@ jobs: - run: cargo test --target x86_64-pc-cygwin -Zbuild-std env: TARGET: x86_64-pc-windows-msvc - CARGO_TARGET_X86_64_PC_CYGWIN_LINKER: x86_64-pc-msys-gcc.exe + CARGO_TARGET_X86_64_PC_CYGWIN_LINKER: C:\msys64\usr\bin\x86_64-pc-msys-gcc.exe bare-cross-build: runs-on: ubuntu-latest From 0cf337edf93c35d365e0391660c207a0e539245f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Mon, 31 Mar 2025 20:48:25 +0800 Subject: [PATCH 6/7] ci: remove TARGET env for cygwin --- .github/workflows/libloading.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index a36c57c38..fa5e2b828 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -81,7 +81,6 @@ jobs: - run: echo "INPUT(libmsys-2.0.a)" | Out-File -FilePath "C:\msys64\usr\lib\libcygwin.a" - run: cargo test --target x86_64-pc-cygwin -Zbuild-std env: - TARGET: x86_64-pc-windows-msvc CARGO_TARGET_X86_64_PC_CYGWIN_LINKER: C:\msys64\usr\bin\x86_64-pc-msys-gcc.exe bare-cross-build: From 27698c72dd6d5053f40fcf2025b07e4e27412fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Tue, 1 Apr 2025 00:05:01 +0800 Subject: [PATCH 7/7] ci: add msys2 path to make gcc find the right ld --- .github/workflows/libloading.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/libloading.yml b/.github/workflows/libloading.yml index fa5e2b828..7cf5b3105 100644 --- a/.github/workflows/libloading.yml +++ b/.github/workflows/libloading.yml @@ -79,9 +79,11 @@ jobs: release: false install: gcc - run: echo "INPUT(libmsys-2.0.a)" | Out-File -FilePath "C:\msys64\usr\lib\libcygwin.a" - - run: cargo test --target x86_64-pc-cygwin -Zbuild-std + - run: | + $env:PATH = "C:\msys64\usr\bin\;$env:PATH" + cargo test --target x86_64-pc-cygwin -Zbuild-std env: - CARGO_TARGET_X86_64_PC_CYGWIN_LINKER: C:\msys64\usr\bin\x86_64-pc-msys-gcc.exe + CARGO_TARGET_X86_64_PC_CYGWIN_LINKER: x86_64-pc-msys-gcc.exe bare-cross-build: runs-on: ubuntu-latest