From e79ccaee18d5db03d584321a665d6c9614c0803c Mon Sep 17 00:00:00 2001
From: David Hotham <david.hotham@blueyonder.co.uk>
Date: Sat, 21 Oct 2023 17:21:32 +0100
Subject: [PATCH] winapi -> windows-sys

---
 .github/dependabot.yml      | 10 ++++++
 .github/workflows/build.yml | 64 +++++++++++++++++++++++++++++++++++++
 .travis.yml                 | 15 ---------
 CHANGELOG.md                | 12 ++++---
 Cargo.toml                  |  4 +--
 src/lib.rs                  | 34 ++++++++++----------
 6 files changed, 102 insertions(+), 37 deletions(-)
 create mode 100644 .github/dependabot.yml
 create mode 100644 .github/workflows/build.yml
 delete mode 100644 .travis.yml

diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 0000000..77761f1
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,10 @@
+version: 2
+updates:
+  - package-ecosystem: cargo
+    directory: /
+    schedule:
+      interval: monthly
+  - package-ecosystem: github-actions
+    directory: /
+    schedule:
+      interval: monthly
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 0000000..562bb9c
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,64 @@
+name: CI
+
+on:
+  push:
+    branches: [main]
+  pull_request:
+    branches: [main]
+  schedule:
+    - cron: "0 3 1 * *"
+
+jobs:
+  test:
+    name: Test
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        build: [x86_64, x86_64-beta, x86_64-nightly, i686, macos, win64, win32]
+        include:
+          - build: x86_64
+            os: ubuntu-latest
+            rust: stable
+            target: x86_64-unknown-linux-gnu
+          - build: x86_64-beta
+            os: ubuntu-latest
+            rust: beta
+            target: x86_64-unknown-linux-gnu
+          - build: x86_64-nightly
+            os: ubuntu-latest
+            rust: nightly
+            target: x86_64-unknown-linux-gnu
+          - build: i686
+            os: ubuntu-latest
+            rust: stable
+            target: i686-unknown-linux-gnu
+          - build: macos
+            os: macos-latest
+            rust: stable
+            target: x86_64-apple-darwin
+          - build: win32
+            os: windows-latest
+            rust: stable
+            target: i686-pc-windows-msvc
+          - build: win64
+            os: windows-latest
+            rust: stable
+            target: x86_64-pc-windows-msvc
+    steps:
+      - uses: actions/checkout@v4
+      - name: Install Rust (rustup)
+        run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
+        shell: bash
+      - run: rustup target add ${{ matrix.target }}
+      - run: cargo fmt -- --check
+        if: matrix.build == 'x86_64'
+        name: Check formatting
+      - run: cargo build
+        name: Build
+      - run: cargo test
+        name: Run tests
+      - run: |
+          cargo update -Z minimal-versions
+          cargo build
+        if: matrix.rust == 'nightly'
+        name: Check minimal versions
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index baae126..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-language: rust
-os:
-- linux
-- osx
-rust:
-- nightly
-- beta
-- stable
-script:
-- cargo build
-- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo update -Z minimal-versions; fi
-- if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo build; fi
-branches:
-  only:
-    master
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f9b8b38..2f550e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,12 +1,16 @@
+## 3.0.0 (21 October 2023)
+
+- Switch from `winapi` to `windows-sys`
+
 ## 2.0.2 (7 Apr 2018)
 
-* Bump libc dependency again (fixes minimal-versions build on OSX)
+- Bump libc dependency again (fixes minimal-versions build on OSX)
 
 ## 2.0.1 (7 Apr 2018)
 
-* Bump libc dependency (fixes minimal-versions build)
+- Bump libc dependency (fixes minimal-versions build)
 
 ## 2.0.0 (4 Jan 2018)
 
-* update to winapi 0.3
-* start maintaining a CHANGELOG
+- update to winapi 0.3
+- start maintaining a CHANGELOG
diff --git a/Cargo.toml b/Cargo.toml
index ab3637a..c712eae 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "c-types"
 license = "MIT"
-version = "2.0.2"
+version = "3.0.0"
 authors = ["David Hotham"]
 description = """
 Re-exports of cross-platform types, gathered from libc and winapi
@@ -15,4 +15,4 @@ keywords = ["libc", "winapi"]
 libc = "0.2.21"
 
 [target.'cfg(windows)'.dependencies]
-winapi = { version = "0.3.3", features = ["winsock2", "ws2ipdef", "ws2tcpip"] }
+windows-sys = { version = "0.48.0", features = ["Win32_Networking_WinSock"] }
diff --git a/src/lib.rs b/src/lib.rs
index e6bc9e3..e0a4dd9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -32,34 +32,36 @@ mod unix {
     pub type sockaddr_in6 = libc::sockaddr_in6;
     pub type socklen_t = libc::socklen_t;
 
-    pub const AF_UNSPEC: i32 = libc::AF_UNSPEC;
-    pub const AF_INET: i32 = libc::AF_INET;
-    pub const AF_INET6: i32 = libc::AF_INET6;
+    pub type ADDRESS_FAMILY = libc::c_int;
+    pub const AF_UNSPEC: ADDRESS_FAMILY = libc::AF_UNSPEC;
+    pub const AF_INET: ADDRESS_FAMILY = libc::AF_INET;
+    pub const AF_INET6: ADDRESS_FAMILY = libc::AF_INET6;
 }
 
 #[cfg(windows)]
 mod windows {
     extern crate libc;
-    extern crate winapi;
+    extern crate windows_sys;
 
-    pub type fd_set = winapi::um::winsock2::fd_set;
-    pub type hostent = winapi::um::winsock2::hostent;
-    pub type in_addr = winapi::shared::inaddr::in_addr;
-    pub type in6_addr = winapi::shared::in6addr::in6_addr;
+    pub type fd_set = windows_sys::Win32::Networking::WinSock::FD_SET;
+    pub type hostent = windows_sys::Win32::Networking::WinSock::HOSTENT;
+    pub type in_addr = windows_sys::Win32::Networking::WinSock::IN_ADDR;
+    pub type in6_addr = windows_sys::Win32::Networking::WinSock::IN6_ADDR;
     #[repr(C)]
     pub struct iovec {
         pub iov_base: *mut libc::c_void,
         pub iov_len: libc::size_t,
     }
-    pub type sa_family_t = winapi::shared::ws2def::ADDRESS_FAMILY;
-    pub type sockaddr = winapi::shared::ws2def::SOCKADDR;
-    pub type sockaddr_in = winapi::shared::ws2def::SOCKADDR_IN;
-    pub type sockaddr_in6 = winapi::shared::ws2ipdef::SOCKADDR_IN6_LH;
-    pub type socklen_t = winapi::um::ws2tcpip::socklen_t;
+    pub type sa_family_t = windows_sys::Win32::Networking::WinSock::sa_family_t;
+    pub type sockaddr = windows_sys::Win32::Networking::WinSock::SOCKADDR;
+    pub type sockaddr_in = windows_sys::Win32::Networking::WinSock::SOCKADDR_IN;
+    pub type sockaddr_in6 = windows_sys::Win32::Networking::WinSock::SOCKADDR_IN6;
+    pub type socklen_t = windows_sys::Win32::Networking::WinSock::socklen_t;
 
-    pub const AF_UNSPEC: i32 = winapi::shared::ws2def::AF_UNSPEC;
-    pub const AF_INET: i32 = winapi::shared::ws2def::AF_INET;
-    pub const AF_INET6: i32 = winapi::shared::ws2def::AF_INET6;
+    pub type ADDRESS_FAMILY = windows_sys::Win32::Networking::WinSock::ADDRESS_FAMILY;
+    pub const AF_UNSPEC: ADDRESS_FAMILY = windows_sys::Win32::Networking::WinSock::AF_UNSPEC;
+    pub const AF_INET: ADDRESS_FAMILY = windows_sys::Win32::Networking::WinSock::AF_INET;
+    pub const AF_INET6: ADDRESS_FAMILY = windows_sys::Win32::Networking::WinSock::AF_INET6;
 }
 
 #[cfg(unix)]