From b1014bf92baef120bacc34ef8178123b3225caea Mon Sep 17 00:00:00 2001
From: Hunter Goldstein <hunter.d.goldstein@gmail.com>
Date: Tue, 20 Jun 2017 15:16:53 -0400
Subject: [PATCH] Hide Tokio crates behind cfg gate for Redox (#317)

* Hide tokio behind gate for redox

* Move common shell logic to 'inner_main'

* Move tokio stuffs to cfg gate

* Move futures dependency to not(target_os = redox) gate
---
 Cargo.toml  |  4 +++-
 src/main.rs | 66 +++++++++++++++++++++++++++++++----------------------
 2 files changed, 42 insertions(+), 28 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index dddfa2e6..6566a2b6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,13 +20,15 @@ name = "ion"
 [dependencies]
 bitflags = "0.9.1"
 fnv = "1.0"
-futures = "0.1"
 glob = "0.2"
 liner = "0.2"
 permutate = "0.3"
 unicode-segmentation = "1.2"
 smallvec = "0.4"
 smallstring = "0.1"
+
+[target.'cfg(not(target_os = "redox"))'.dependencies]
+futures = "0.1"
 tokio-core = "0.1"
 tokio-signal = "0.1"
 
diff --git a/src/main.rs b/src/main.rs
index 4e2b527a..ac48dbf0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,13 +8,14 @@
 #[macro_use]
 extern crate bitflags;
 extern crate fnv;
-extern crate futures;
 extern crate glob;
 extern crate liner;
 extern crate smallvec;
 extern crate smallstring;
-extern crate tokio_core;
-extern crate tokio_signal;
+
+#[cfg(not(target_os = "redox"))] extern crate futures;
+#[cfg(not(target_os = "redox"))] extern crate tokio_core;
+#[cfg(not(target_os = "redox"))] extern crate tokio_signal;
 
 #[cfg(all(unix, not(target_os = "redox")))]
 extern crate users as users_unix;
@@ -30,36 +31,41 @@ use std::io::{stderr, Write, ErrorKind};
 use builtins::Builtin;
 use shell::Shell;
 
-use tokio_core::reactor::Core;
-use futures::{Future, Stream};
+#[cfg(not(target_os = "redox"))] use tokio_core::reactor::Core;
+#[cfg(not(target_os = "redox"))] use futures::{Future, Stream};
+
 use std::sync::mpsc;
 use std::thread;
 
+fn inner_main(sigint_rx : mpsc::Receiver<bool>) {
+   let builtins = Builtin::map();
+   let mut shell = Shell::new(&builtins, sigint_rx);
+   shell.evaluate_init_file();
+
+   if "1" == shell.variables.get_var_or_empty("HISTORY_FILE_ENABLED") {
+       shell.context.history.set_file_name(shell.variables.get_var("HISTORY_FILE"));
+       match shell.context.history.load_history() {
+           Ok(()) => {
+               // pass
+           }
+           Err(ref err) if err.kind() == ErrorKind::NotFound => {
+               let history_filename = shell.variables.get_var_or_empty("HISTORY_FILE");
+               let _ = writeln!(stderr(), "ion: failed to find history file {}: {}", history_filename, err);
+           },
+           Err(err) => {
+               let _ = writeln!(stderr(), "ion: failed to load history: {}", err);
+           }
+       }
+   }
+   shell.execute();
+}
+
+
+#[cfg(not(target_os = "redox"))]
 fn main() {
     let (sigint_tx, sigint_rx) = mpsc::channel();
 
-    thread::spawn(move || {
-        let builtins = Builtin::map();
-        let mut shell = Shell::new(&builtins, sigint_rx);
-        shell.evaluate_init_file();
-
-        if "1" == shell.variables.get_var_or_empty("HISTORY_FILE_ENABLED") {
-            shell.context.history.set_file_name(shell.variables.get_var("HISTORY_FILE"));
-            match shell.context.history.load_history() {
-                Ok(()) => {
-                    // pass
-                }
-                Err(ref err) if err.kind() == ErrorKind::NotFound => {
-                    let history_filename = shell.variables.get_var_or_empty("HISTORY_FILE");
-                    let _ = writeln!(stderr(), "ion: failed to find history file {}: {}", history_filename, err);
-                },
-                Err(err) => {
-                    let _ = writeln!(stderr(), "ion: failed to load history: {}", err);
-                }
-            }
-        }
-        shell.execute();
-    });
+    thread::spawn(move || inner_main(sigint_rx));
 
     let mut core = Core::new().unwrap();
     let handle = core.handle();
@@ -71,3 +77,9 @@ fn main() {
     });
     core.run(signal_handler).unwrap();
 }
+
+#[cfg(target_os = "redox")]
+fn main() {
+    let (_, sigint_rx) = mpsc::channel();
+    inner_main(sigint_rx);
+}
-- 
GitLab