From c7e1ed1af3e265dbaa056e2aa5d210dc7257aea2 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Sat, 16 Jun 2018 11:11:27 +0200 Subject: [PATCH] Fix windows compilation with --no-fork --no-fork is a stub on windows. --- Cargo.toml | 2 ++ src/main.rs | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4a481b8..22d7006 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,8 @@ regex = "0.2" lazy_static = "1.0" unicode-width = "0.1.4" unicode-segmentation = "1.2.0" + +[target.'cfg(unix)'.dependencies] unix-daemonize = "0.1" serde = "1.0" diff --git a/src/main.rs b/src/main.rs index b083c9d..61100e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ #![windows_subsystem = "windows"] +#[cfg(unix)] extern crate unix_daemonize; extern crate cairo; extern crate env_logger; @@ -64,6 +65,7 @@ mod file_browser; mod subscriptions; mod misc; +#[cfg(unix)] use unix_daemonize::{daemonize_redirect, ChdirMode}; use std::env; use std::io::Read; @@ -114,18 +116,20 @@ fn main() { .filter(|a| !a.starts_with(NO_FORK)) .collect(); - // fork to background by default - let want_fork = env::args() - .take_while(|a| *a != "--") - .skip(1) - .find(|a| a.starts_with(NO_FORK)) - .is_none(); + #[cfg(unix)] { + // fork to background by default + let want_fork = env::args() + .take_while(|a| *a != "--") + .skip(1) + .find(|a| a.starts_with(NO_FORK)) + .is_none(); - if want_fork { - daemonize_redirect(Some("/tmp/nvim-gtk_stdout.log"), - Some("/tmp/nvim-gtk_stderr.log"), - ChdirMode::NoChdir) - .unwrap(); + if want_fork { + daemonize_redirect(Some("/tmp/nvim-gtk_stdout.log"), + Some("/tmp/nvim-gtk_stderr.log"), + ChdirMode::NoChdir) + .unwrap(); + } } app.run(&argv);