From 7de41c4ddd8657ff18435c7a37af96e95c76f3d3 Mon Sep 17 00:00:00 2001
From: Shell Chen <me@sorz.org>
Date: Wed, 10 Jan 2024 17:48:47 +0800
Subject: [PATCH] Fix Windows build & GitHub workflows

---
 .github/workflows/build-package.yml | 22 ++++++++++++++--------
 src/web/mod.rs                      | 13 +++++++++++--
 2 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/.github/workflows/build-package.yml b/.github/workflows/build-package.yml
index ea258c4..9eef3d6 100644
--- a/.github/workflows/build-package.yml
+++ b/.github/workflows/build-package.yml
@@ -3,12 +3,12 @@ name: build-package
 on:
   push:
     tags:
-      - '*'
+      - 'v*'
 
 jobs:
   release:
     name: Release - ${{ matrix.platform.release_for }}
-    if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/tags/test-release'
+    if: startsWith(github.ref, 'refs/tags/v')
     strategy:
       fail-fast: false
       matrix:
@@ -37,11 +37,14 @@ jobs:
             suffix: linux_armv7_gnueabihf.bin
             toolchain: stable
 
-          - release_for: Android-aarch64
-            os: ubuntu-latest
-            target: aarch64-linux-android
-            suffix: linux_aarch64_android.bin
-            toolchain: stable
+          # Disabled until corss release a new version
+          # https://github.com/cross-rs/cross/issues/1222
+          #
+          #- release_for: Android-aarch64
+          #  os: ubuntu-latest
+          #  target: aarch64-linux-android
+          #  suffix: linux_aarch64_android.bin
+          #  toolchain: stable
 
     runs-on: ${{ matrix.platform.os }}
     steps:
@@ -49,6 +52,9 @@ jobs:
         uses: actions/checkout@v4
       - name: Setup cache
         uses: Swatinem/rust-cache@v2
+      - name: Install musl-tools
+        if: contains(matrix.platform.target, 'linux-musl')
+        run: sudo apt install musl-tools
       - name: Build
         uses: houseabsolute/actions-rust-cross@v0
         with:
@@ -60,7 +66,7 @@ jobs:
       - name: Packaging for Debian
         if: matrix.platform.target == 'x86_64-unknown-linux-gnu'
         run: |
-          cargo install deb
+          cargo install cargo-deb
           cargo deb --target=${{ matrix.platform.target }} --no-build
       - name: Packaging binary
         run: |
diff --git a/src/web/mod.rs b/src/web/mod.rs
index 4b09cfc..e7926af 100644
--- a/src/web/mod.rs
+++ b/src/web/mod.rs
@@ -23,10 +23,12 @@ use std::{
     sync::Arc,
     time::{Duration, Instant},
 };
+#[cfg(unix)]
+use tokio::net::{UnixListener, UnixStream};
 use tokio::{
     self,
     io::{AsyncRead, AsyncWrite},
-    net::{TcpListener, TcpStream, UnixListener, UnixStream},
+    net::{TcpListener, TcpStream},
 };
 use tracing::{info, instrument, warn};
 
@@ -224,6 +226,7 @@ fn response(req: &Request<Incoming>, start_time: Instant, monitor: Monitor) -> B
 #[derive(Debug, Clone)]
 enum ListenAddr {
     TcpSocket(SocketAddr),
+    #[cfg(unix)]
     UnixPath(SharedStr),
 }
 
@@ -247,6 +250,7 @@ impl Accept<TcpStream> for TcpListener {
     }
 }
 
+#[cfg(unix)]
 impl Accept<UnixStream> for UnixListener {
     async fn accept(&self) -> io::Result<UnixStream> {
         let (client, _) = self.accept().await?;
@@ -273,7 +277,12 @@ impl WebServer {
                 .context("Not valid TCP socket address for web server")?;
             ListenAddr::TcpSocket(addr)
         } else {
-            ListenAddr::UnixPath(bind_addr)
+            #[cfg(unix)]
+            {
+                ListenAddr::UnixPath(bind_addr)
+            }
+            #[cfg(not(unix))]
+            anyhow::bail!("No UNIX domain socket support on this system")
         };
         Ok(Self { monitor, bind_addr })
     }