feat: windows 64-bit and arm64 targets
it introduces two new windows targets:
- x86_64-pc-windows-msvc
- aarch64-pc-windows-msvc
Diff
.github/workflows/devel.yml | 20 +++++++-------
.github/workflows/release.yml | 20 +++++++-------
Cargo.lock | 36 +++++++++----------------
Cargo.toml | 7 +-----
README.md | 5 +--
src/server.rs | 23 +---------------
src/signals.rs | 64 +++++++++++---------------------------------
7 files changed, 57 insertions(+), 118 deletions(-)
@@ -32,8 +32,8 @@ jobs:
- linux-arm-gnueabihf
- macos
- macos-arm64
- windows-msvc
- windows-msvc-arm64
include:
- build: pinned
os: ubuntu-20.04
@@ -72,14 +72,14 @@ jobs:
os: macos-latest
rust: nightly
target: aarch64-apple-darwin
- build: windows-msvc
os: windows-2019
rust: nightly
target: x86_64-pc-windows-msvc
- build: windows-msvc-arm64
os: windows-2019
rust: nightly
target: aarch64-pc-windows-msvc
steps:
- name: Checkout repository
@@ -56,8 +56,8 @@ jobs:
- linux-arm-gnueabihf
- macos
- macos-arm64
- windows-msvc
- windows-msvc-arm64
include:
- build: linux-musl
os: ubuntu-20.04
@@ -87,14 +87,14 @@ jobs:
os: macos-latest
rust: nightly
target: aarch64-apple-darwin
- build: windows-msvc
os: windows-2019
rust: nightly
target: x86_64-pc-windows-msvc
- build: windows-msvc-arm64
os: windows-2019
rust: nightly
target: aarch64-pc-windows-msvc
steps:
- name: Checkout repository
@@ -172,6 +172,16 @@ dependencies = [
]
[[package]]
name = "ctrlc"
version = "3.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "232295399409a8b7ae41276757b5a1cc21032848d42bff2352261f958b3ca29a"
dependencies = [
"nix",
"winapi",
]
[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -565,15 +575,14 @@ dependencies = [
[[package]]
name = "nix"
version = "0.14.1"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce"
checksum = "fa9b4819da1bc61c0ea48b63b7bc8604064dd43013e7cc325df098d49cd7c18a"
dependencies = [
"bitflags",
"cc",
"cfg-if 0.1.10",
"cfg-if 1.0.0",
"libc",
"void",
]
[[package]]
@@ -814,16 +823,6 @@ dependencies = [
]
[[package]]
name = "signal"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f6ce83b159ab6984d2419f495134972b48754d13ff2e3f8c998339942b56ed9"
dependencies = [
"libc",
"nix",
]
[[package]]
name = "slab"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -858,6 +857,7 @@ dependencies = [
"anyhow",
"async-compression",
"bytes",
"ctrlc",
"futures",
"headers",
"http",
@@ -866,12 +866,10 @@ dependencies = [
"jemallocator",
"listenfd",
"mime_guess",
"nix",
"num_cpus",
"once_cell",
"percent-encoding",
"pin-project",
"signal",
"structopt",
"time",
"tokio",
@@ -1140,12 +1138,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
[[package]]
name = "want"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -46,12 +46,7 @@ tokio-rustls = { version = "0.22" }
humansize = "1.1"
time = "0.1"
listenfd = "0.3"
[target.'cfg(not(windows))'.dependencies.nix]
version = "0.14"
[target.'cfg(not(windows))'.dependencies.signal]
version = "0.7"
ctrlc = { version = "3.1", features = ["termination"] }
[target.'cfg(all(target_env = "musl", target_pointer_width = "64"))'.dependencies.jemallocator]
version = "0.3"
@@ -48,7 +48,7 @@ Below the current supported targets.
- x86_64-unknown-linux-musl (64-bit)
- aarch64-unknown-linux-musl (ARM64)
- aarch64-unknown-linux-gnu (ARM64)
- arm-unknown-linux-gnueabihf (ARM64)
- arm-unknown-linux-gnueabihf (ARM)
#### macOS
@@ -57,7 +57,8 @@ Below the current supported targets.
#### Windows
\* **Note:** Windows support is on the TODO list yet.
- x86_64-pc-windows-msvc (64-bit)
- aarch64-pc-windows-msvc (ARM64)
## Usage
@@ -8,7 +8,7 @@ use crate::handler::{RequestHandler, RequestHandlerOpts};
use crate::tls::{TlsAcceptor, TlsConfigBuilder};
use crate::Result;
use crate::{config::Config, service::RouterService};
use crate::{cors, error_page, helpers, logger};
use crate::{cors, error_page, helpers, logger, signals};
pub struct Server {
@@ -171,9 +171,7 @@ impl Server {
});
}
handle_signals();
Ok(())
signals::wait_for_ctrl_c()
}
}
@@ -182,20 +180,3 @@ impl Default for Server {
Self::new()
}
}
#[cfg(not(windows))]
fn handle_signals() {
use crate::signals;
signals::wait(|sig: signals::Signal| {
let code = signals::as_int(sig);
tracing::warn!("Signal {} caught. Server execution exited.", code);
std::process::exit(code)
});
}
#[cfg(windows)]
fn handle_signals() {
}
@@ -1,51 +1,21 @@
use nix::errno::Errno;
use nix::libc::c_int;
use nix::sys::signal::{SIGCHLD, SIGINT, SIGTERM};
use nix::sys::wait::WaitStatus::{Exited, Signaled, StillAlive};
use nix::sys::wait::{waitpid, WaitPidFlag};
use nix::Error;
use ctrlc;
use std::sync::mpsc::channel;
pub use signal::Signal;
use crate::{Context, Result};
pub fn wait<F>(func: F)
where
F: Fn(signal::Signal),
{
let sig_trap = signal::trap::Trap::trap(&[SIGTERM, SIGINT, SIGCHLD]);
for sig in sig_trap {
match sig {
SIGCHLD => {
loop {
match waitpid(None, Some(WaitPidFlag::WNOHANG)) {
Ok(Exited(pid, status)) => {
println!("{} exited with status {}", pid, status);
continue;
}
Ok(Signaled(pid, sig, _)) => {
println!("{} killed by {}", pid, sig as c_int);
continue;
}
Ok(StillAlive) => break,
Ok(status) => {
println!("Temporary status {:?}", status);
continue;
}
Err(Error::Sys(Errno::ECHILD)) => return,
Err(e) => {
panic!("Error {:?}", e);
}
}
}
}
sig => func(sig),
}
}
}
pub fn wait_for_ctrl_c() -> Result {
let (tx, rx) = channel();
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
.with_context(|| "Error setting Ctrl-C handler.".to_owned())?;
tracing::info!("Press Ctrl+C to shutdown server.");
rx.recv()
.with_context(|| "Could not receive signal from channel.".to_owned())?;
tracing::warn!("Ctrl+C signal caught, shutting down server execution.");
pub fn as_int(sig: signal::Signal) -> i32 {
sig as c_int
Ok(())
}