From ebbea07ad8285573df2222cacff0eeac0f902481 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Sun, 6 Mar 2016 10:59:13 -0700
Subject: [PATCH] WIP: Fix cargo unable to link libstd with dependencies

---
 Makefile                       |  4 ++--
 crates/io/io.rs                | 19 +++++++++++++++++++
 crates/io/lib.rs               | 22 ++--------------------
 crates/io/mmio.rs              |  2 +-
 crates/io/pio.rs               |  2 +-
 crates/ion                     |  2 +-
 crates/system/syscall/redox.rs |  2 +-
 crates/system/syscall/unix.rs  |  2 +-
 rustc-i386.sh                  |  2 ++
 rustc-x86_64.sh                |  2 ++
 10 files changed, 32 insertions(+), 27 deletions(-)
 create mode 100644 crates/io/io.rs
 create mode 100755 rustc-i386.sh
 create mode 100755 rustc-x86_64.sh

diff --git a/Makefile b/Makefile
index f2cff3e..c70a492 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,8 @@ BUILD=build/$(ARCH)-unknown-redox/debug
 
 QEMU?=qemu-system-$(ARCH)
 
-CARGO=CARGO_TARGET_DIR=build cargo rustc
-CARGOFLAGS=--target=$(ARCH)-unknown-redox.json -- -L $(BUILD) \
+CARGO=CARGO_TARGET_DIR=build RUSTC="./rustc-$(ARCH).sh" cargo rustc
+CARGOFLAGS=--verbose --target=$(ARCH)-unknown-redox.json -- -L $(BUILD) \
 	-C no-prepopulate-passes -C no-stack-check -C opt-level=2 \
 	-Z no-landing-pads \
 	-A dead_code
diff --git a/crates/io/io.rs b/crates/io/io.rs
new file mode 100644
index 0000000..4150960
--- /dev/null
+++ b/crates/io/io.rs
@@ -0,0 +1,19 @@
+use core::cmp::PartialEq;
+use core::ops::{BitAnd, BitOr, Not};
+
+pub trait Io<T> {
+    fn read(&self) -> T;
+    fn write(&mut self, value: T);
+
+    fn readf(&self, flags: T) -> bool where T: BitAnd<Output = T> + PartialEq<T> + Copy {
+        (self.read() & flags) as T == flags
+    }
+
+    fn writef(&mut self, flags: T, value: bool) where T: BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
+        let tmp: T = match value {
+            true => self.read() | flags,
+            false => self.read() & !flags,
+        };
+        self.write(tmp);
+    }
+}
diff --git a/crates/io/lib.rs b/crates/io/lib.rs
index 82bc2da..c9e624a 100644
--- a/crates/io/lib.rs
+++ b/crates/io/lib.rs
@@ -4,28 +4,10 @@
 #![feature(core_intrinsics)]
 #![no_std]
 
-use core::cmp::PartialEq;
-use core::ops::{BitAnd, BitOr, Not};
-
+pub use self::io::*;
 pub use self::mmio::*;
 pub use self::pio::*;
 
+mod io;
 mod mmio;
 mod pio;
-
-pub trait Io<T> {
-    fn read(&self) -> T;
-    fn write(&mut self, value: T);
-
-    fn readf(&self, flags: T) -> bool where T: BitAnd<Output = T> + PartialEq<T> + Copy {
-        (self.read() & flags) as T == flags
-    }
-
-    fn writef(&mut self, flags: T, value: bool) where T: BitAnd<Output = T> + BitOr<Output = T> + Not<Output = T> {
-        let tmp: T = match value {
-            true => self.read() | flags,
-            false => self.read() & !flags,
-        };
-        self.write(tmp);
-    }
-}
diff --git a/crates/io/mmio.rs b/crates/io/mmio.rs
index 0ff7d9d..230911b 100644
--- a/crates/io/mmio.rs
+++ b/crates/io/mmio.rs
@@ -1,6 +1,6 @@
 use core::intrinsics::{volatile_load, volatile_store};
 
-use super::Io;
+use super::io::Io;
 
 #[repr(packed)]
 pub struct Mmio<T> {
diff --git a/crates/io/pio.rs b/crates/io/pio.rs
index ec88c9f..81bd3a2 100644
--- a/crates/io/pio.rs
+++ b/crates/io/pio.rs
@@ -1,6 +1,6 @@
 use core::marker::PhantomData;
 
-use super::Io;
+use super::io::Io;
 
 /// Generic PIO
 #[derive(Copy, Clone)]
diff --git a/crates/ion b/crates/ion
index f3fd709..861748f 160000
--- a/crates/ion
+++ b/crates/ion
@@ -1 +1 @@
-Subproject commit f3fd7098f4696a58f6cce671a41efd58fda03580
+Subproject commit 861748f6d53a708504a33ba6535214f3a2cf3e93
diff --git a/crates/system/syscall/redox.rs b/crates/system/syscall/redox.rs
index 63ffe55..fb980df 100644
--- a/crates/system/syscall/redox.rs
+++ b/crates/system/syscall/redox.rs
@@ -1,4 +1,4 @@
-use syscall::{syscall1, syscall2};
+use syscall::arch::{syscall1, syscall2};
 use error::Result;
 
 pub const SYS_DEBUG: usize = 0;
diff --git a/crates/system/syscall/unix.rs b/crates/system/syscall/unix.rs
index 49ffff1..5a4f178 100644
--- a/crates/system/syscall/unix.rs
+++ b/crates/system/syscall/unix.rs
@@ -1,4 +1,4 @@
-use syscall::{syscall0, syscall1, syscall2, syscall3};
+use syscall::arch::{syscall0, syscall1, syscall2, syscall3};
 use error::Result;
 
 pub const SYS_BRK: usize = 45;
diff --git a/rustc-i386.sh b/rustc-i386.sh
new file mode 100755
index 0000000..ff59150
--- /dev/null
+++ b/rustc-i386.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+rustc -L build/i386-unknown-redox/debug $*
diff --git a/rustc-x86_64.sh b/rustc-x86_64.sh
new file mode 100755
index 0000000..0abb64d
--- /dev/null
+++ b/rustc-x86_64.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+rustc -L build/x86_64-unknown-redox/debug $*
