about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-06-12 17:44:38 +0200
committerGitHub <noreply@github.com>2023-06-12 17:44:38 +0200
commit9c4cff424e0fce039aacf3524d6e753c67dec13b (patch)
tree563f23cf9d2d22b9a7ee7a24f90c8ddcdd5f572d
parent8475a88d67db7b341fd26ac5d9210988c659a37d (diff)
parentdf08f56b089927fd5552b208d4c0a6cd3b8f12b0 (diff)
Rollup merge of #112527 - bdbai:fix/winarm32, r=ChrisDenton
Add windows_sys type definitions for ARM32 manually

`windows_sys` bindings do not include platform-specific type definitions for ARM 32 architecture, so it breaks `thumbv7a-pc-windows-msvc` and `thumbv7a-uwp-windows-msvc` targets. This PR tries to add them back by manually inserting them together with the generated ones.

`WSADATA` is copied from the generated definition for `x86`. `CONTEXT` is copied from the definition before `windows_sys` is introduced (which is just an empty enum): https://github.com/rust-lang/rust/blob/4a18324a4df6bc98bec0b54d35908d7a9cdc7c32/library/std/src/sys/windows/c.rs#L802.

Fixes #112265.
-rw-r--r--library/std/src/sys/windows/c/windows_sys.rs20
-rw-r--r--src/tools/generate-windows-sys/src/arm_shim.rs20
-rw-r--r--src/tools/generate-windows-sys/src/main.rs4
3 files changed, 44 insertions, 0 deletions
diff --git a/library/std/src/sys/windows/c/windows_sys.rs b/library/std/src/sys/windows/c/windows_sys.rs
index 8c8b006a1d3..a4294f336fe 100644
--- a/library/std/src/sys/windows/c/windows_sys.rs
+++ b/library/std/src/sys/windows/c/windows_sys.rs
@@ -4275,3 +4275,23 @@ impl ::core::clone::Clone for XSAVE_FORMAT {
         *self
     }
 }
+// Begin of ARM32 shim
+// The raw content of this file should be processed by `generate-windows-sys`
+// to be merged with the generated binding. It is not supposed to be used as
+// a normal Rust module.
+cfg_if::cfg_if! {
+if #[cfg(target_arch = "arm")] {
+#[repr(C)]
+pub struct WSADATA {
+    pub wVersion: u16,
+    pub wHighVersion: u16,
+    pub szDescription: [u8; 257],
+    pub szSystemStatus: [u8; 129],
+    pub iMaxSockets: u16,
+    pub iMaxUdpDg: u16,
+    pub lpVendorInfo: PSTR,
+}
+pub enum CONTEXT {}
+}
+}
+// End of ARM32 shim
diff --git a/src/tools/generate-windows-sys/src/arm_shim.rs b/src/tools/generate-windows-sys/src/arm_shim.rs
new file mode 100644
index 00000000000..17c2ccb223c
--- /dev/null
+++ b/src/tools/generate-windows-sys/src/arm_shim.rs
@@ -0,0 +1,20 @@
+// Begin of ARM32 shim
+// The raw content of this file should be processed by `generate-windows-sys`
+// to be merged with the generated binding. It is not supposed to be used as
+// a normal Rust module.
+cfg_if::cfg_if! {
+if #[cfg(target_arch = "arm")] {
+#[repr(C)]
+pub struct WSADATA {
+    pub wVersion: u16,
+    pub wHighVersion: u16,
+    pub szDescription: [u8; 257],
+    pub szSystemStatus: [u8; 129],
+    pub iMaxSockets: u16,
+    pub iMaxUdpDg: u16,
+    pub lpVendorInfo: PSTR,
+}
+pub enum CONTEXT {}
+}
+}
+// End of ARM32 shim
diff --git a/src/tools/generate-windows-sys/src/main.rs b/src/tools/generate-windows-sys/src/main.rs
index 91d981462e8..65e480715ee 100644
--- a/src/tools/generate-windows-sys/src/main.rs
+++ b/src/tools/generate-windows-sys/src/main.rs
@@ -11,6 +11,9 @@ const PRELUDE: &str = r#"// This file is autogenerated.
 // ignore-tidy-filelength
 "#;
 
+/// This is a shim for the ARM (32-bit) architecture, which is no longer supported by windows-rs.
+const ARM_SHIM: &str = include_str!("arm_shim.rs");
+
 fn main() -> io::Result<()> {
     let mut path: PathBuf =
         std::env::args_os().nth(1).expect("a path to the rust repository is required").into();
@@ -32,6 +35,7 @@ fn main() -> io::Result<()> {
     let mut f = std::fs::File::create(&path)?;
     f.write_all(PRELUDE.as_bytes())?;
     f.write_all(bindings.as_bytes())?;
+    f.write_all(ARM_SHIM.as_bytes())?;
 
     Ok(())
 }