Skip to content
This repository was archived by the owner on Jan 15, 2024. It is now read-only.

Build project on windows #315

Merged
merged 6 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Windows build

on:
push:
branches:
- main
- release-*
pull_request:
branches:
- main
- release-*
workflow_dispatch:

jobs:
build:
runs-on: windows-2022
steps:
- name: Configure Git
run: |
git config --global url."https://ancient123:${{ secrets.ORG_GITHUB_PAT }}@github.com/".insteadOf git://github.com/
git config --global url."https://ancient123:${{ secrets.ORG_GITHUB_PAT }}@github.com/".insteadOf ssh://[email protected]/

- name: Checkout Repository
uses: actions/checkout@v3

- uses: Swatinem/rust-cache@v1
name: Enable Rust Caching

- name: Check
run: cargo check --workspace --all-targets
4 changes: 3 additions & 1 deletion address-book/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ rand = "0.8.5"
rand_chacha = "0.3.1"
serde = { version = "1.0", features = ["derive"] }
signal-hook = "0.3.13"
signal-hook-async-std = "0.2.2"
surf = "2.3.2"
tempdir = "0.3.7"
tide = "0.16.0"
Expand All @@ -41,5 +40,8 @@ tracing-futures = "0.2"
tracing-log = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[target.'cfg(not(windows))'.dependencies]
signal-hook-async-std = "0.2.2"

[dev-dependencies]
portpicker = "0.1"
1 change: 1 addition & 0 deletions address-book/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use tide::{
StatusCode,
};

#[cfg(not(windows))]
pub mod signal;

pub const DEFAULT_PORT: u16 = 50078u16;
Expand Down
35 changes: 24 additions & 11 deletions address-book/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

use address_book::{address_book_port, address_book_store_path, init_web_server, FileStore};
use std::fs;

use address_book::{
address_book_port, address_book_store_path, init_web_server, signal::handle_signals, FileStore,
};
use signal_hook::consts::{SIGINT, SIGTERM};
use signal_hook_async_std::Signals;

#[async_std::main]
async fn main() -> Result<(), std::io::Error> {
let signals = Signals::new(&[SIGINT, SIGTERM]).expect("Failed to create signals.");
let handle = signals.handle();
let signals_task = async_std::task::spawn(handle_signals(signals));
let cleanup_signals = register_interrupt_signals();

tracing_subscriber::fmt()
.compact()
Expand All @@ -36,8 +29,28 @@ async fn main() -> Result<(), std::io::Error> {
})
.await?;

handle.close();
signals_task.await;
cleanup_signals.await;

Ok(())
}

#[cfg(windows)]
async fn register_interrupt_signals() {
// Signals aren't properly supported on windows so we'll just exit
}

#[cfg(not(windows))]
fn register_interrupt_signals() -> impl std::future::Future<Output = ()> {
use address_book::signal::handle_signals;
use signal_hook::consts::{SIGINT, SIGTERM};
use signal_hook_async_std::Signals;

let signals = Signals::new(&[SIGINT, SIGTERM]).expect("Failed to create signals.");
let handle = signals.handle();
let signals_task = async_std::task::spawn(handle_signals(signals));

async move {
handle.close();
signals_task.await;
}
}