From c65e7f3dc38758cd4a870eda0c456c6b73b13b82 Mon Sep 17 00:00:00 2001
From: Kenny Kerr <kenny@kennykerr.ca>
Date: Tue, 25 Jun 2024 14:56:54 -0500
Subject: [PATCH] block less non-windows usage

---
 .github/workflows/msrv-windows-core.yml       |  5 ++-
 crates/libs/strings/src/hstring.rs            | 38 +++++++++----------
 crates/libs/strings/src/lib.rs                |  1 -
 crates/tests/linux/Cargo.toml                 |  3 ++
 crates/tests/linux/tests/core.rs              | 16 ++++++++
 .../linux/tests/{hresult.rs => result.rs}     |  0
 6 files changed, 42 insertions(+), 21 deletions(-)
 create mode 100644 crates/tests/linux/tests/core.rs
 rename crates/tests/linux/tests/{hresult.rs => result.rs} (100%)

diff --git a/.github/workflows/msrv-windows-core.yml b/.github/workflows/msrv-windows-core.yml
index 6b5589f11c..b124af5e4a 100644
--- a/.github/workflows/msrv-windows-core.yml
+++ b/.github/workflows/msrv-windows-core.yml
@@ -16,7 +16,10 @@ jobs:
     strategy:
       matrix:
         rust: [1.70.0, stable, nightly]
-    runs-on: windows-latest
+        runs-on:
+          - windows-latest
+          - ubuntu-latest
+    runs-on: ${{ matrix.runs-on }}
     steps:
       - name: Checkout
         uses: actions/checkout@v4
diff --git a/crates/libs/strings/src/hstring.rs b/crates/libs/strings/src/hstring.rs
index d1c747f072..85135f7683 100644
--- a/crates/libs/strings/src/hstring.rs
+++ b/crates/libs/strings/src/hstring.rs
@@ -54,7 +54,7 @@ impl HSTRING {
     }
 
     /// Get the contents of this `HSTRING` as a OsString.
-    #[cfg(feature = "std")]
+    #[cfg(all(feature = "std", windows))]
     pub fn to_os_string(&self) -> std::ffi::OsString {
         std::os::windows::ffi::OsStringExt::from_wide(self.as_wide())
     }
@@ -159,14 +159,14 @@ impl From<&String> for HSTRING {
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl From<&std::path::Path> for HSTRING {
     fn from(value: &std::path::Path) -> Self {
         value.as_os_str().into()
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl From<&std::ffi::OsStr> for HSTRING {
     fn from(value: &std::ffi::OsStr) -> Self {
         unsafe {
@@ -179,14 +179,14 @@ impl From<&std::ffi::OsStr> for HSTRING {
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl From<std::ffi::OsString> for HSTRING {
     fn from(value: std::ffi::OsString) -> Self {
         value.as_os_str().into()
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl From<&std::ffi::OsString> for HSTRING {
     fn from(value: &std::ffi::OsString) -> Self {
         value.as_os_str().into()
@@ -291,28 +291,28 @@ impl PartialEq<&HSTRING> for String {
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<std::ffi::OsString> for HSTRING {
     fn eq(&self, other: &std::ffi::OsString) -> bool {
         *self == **other
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<std::ffi::OsString> for &HSTRING {
     fn eq(&self, other: &std::ffi::OsString) -> bool {
         **self == **other
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<&std::ffi::OsString> for HSTRING {
     fn eq(&self, other: &&std::ffi::OsString) -> bool {
         *self == ***other
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<std::ffi::OsStr> for HSTRING {
     fn eq(&self, other: &std::ffi::OsStr) -> bool {
         self.as_wide()
@@ -322,56 +322,56 @@ impl PartialEq<std::ffi::OsStr> for HSTRING {
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<std::ffi::OsStr> for &HSTRING {
     fn eq(&self, other: &std::ffi::OsStr) -> bool {
         **self == *other
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<&std::ffi::OsStr> for HSTRING {
     fn eq(&self, other: &&std::ffi::OsStr) -> bool {
         *self == **other
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<HSTRING> for std::ffi::OsStr {
     fn eq(&self, other: &HSTRING) -> bool {
         *other == *self
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<HSTRING> for &std::ffi::OsStr {
     fn eq(&self, other: &HSTRING) -> bool {
         *other == **self
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<&HSTRING> for std::ffi::OsStr {
     fn eq(&self, other: &&HSTRING) -> bool {
         **other == *self
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<HSTRING> for std::ffi::OsString {
     fn eq(&self, other: &HSTRING) -> bool {
         *other == **self
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<HSTRING> for &std::ffi::OsString {
     fn eq(&self, other: &HSTRING) -> bool {
         *other == ***self
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl PartialEq<&HSTRING> for std::ffi::OsString {
     fn eq(&self, other: &&HSTRING) -> bool {
         **other == **self
@@ -394,14 +394,14 @@ impl TryFrom<HSTRING> for String {
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl<'a> From<&'a HSTRING> for std::ffi::OsString {
     fn from(hstring: &HSTRING) -> Self {
         hstring.to_os_string()
     }
 }
 
-#[cfg(feature = "std")]
+#[cfg(all(feature = "std", windows))]
 impl From<HSTRING> for std::ffi::OsString {
     fn from(hstring: HSTRING) -> Self {
         Self::from(&hstring)
diff --git a/crates/libs/strings/src/lib.rs b/crates/libs/strings/src/lib.rs
index dfe52b5ae2..0f7bc8705e 100644
--- a/crates/libs/strings/src/lib.rs
+++ b/crates/libs/strings/src/lib.rs
@@ -2,7 +2,6 @@
 Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
 */
 
-#![cfg(windows)]
 #![allow(non_snake_case)]
 #![cfg_attr(
     windows_debugger_visualizer,
diff --git a/crates/tests/linux/Cargo.toml b/crates/tests/linux/Cargo.toml
index f0a97abf69..8285f3b1ab 100644
--- a/crates/tests/linux/Cargo.toml
+++ b/crates/tests/linux/Cargo.toml
@@ -10,3 +10,6 @@ doctest = false
 
 [dependencies.windows-result]
 path = "../../libs/result"
+
+[dependencies.windows-core]
+path = "../../libs/core"
diff --git a/crates/tests/linux/tests/core.rs b/crates/tests/linux/tests/core.rs
new file mode 100644
index 0000000000..681d917e33
--- /dev/null
+++ b/crates/tests/linux/tests/core.rs
@@ -0,0 +1,16 @@
+use windows_core::*;
+
+#[interface("d888acaa-fb67-46a4-bb35-87cb37db5830")]
+unsafe trait ITest: IUnknown {}
+
+#[implement(ITest)]
+struct Test;
+
+impl ITest_Impl for Test_Impl {}
+
+#[test]
+fn test() {
+    let object = ComObject::new(Test);
+    let unknown: IUnknown = object.to_interface();
+    let _test: ITest = unknown.cast().expect("QueryInterface for ITest");
+}
diff --git a/crates/tests/linux/tests/hresult.rs b/crates/tests/linux/tests/result.rs
similarity index 100%
rename from crates/tests/linux/tests/hresult.rs
rename to crates/tests/linux/tests/result.rs