From 2f50458585a080337664217e17351b57eab8ec10 Mon Sep 17 00:00:00 2001
From: John Hodge <tpg@mutabah.net>
Date: Sat, 22 Dec 2018 09:29:21 +0800
Subject: [PATCH] Makefiles - Nightly fix (libcompiler_builtins moved to
 crates.io)

---
 Kernel/Makefile                  | 12 ++----------
 Makefile                         | 14 ++++++++++++--
 Usermode/Makefile                | 10 +++++++++-
 Usermode/liballoc_system/heap.rs | 12 ++++++------
 Usermode/libstd/src/lib.rs       |  1 +
 Usermode/libstd_rt/lib.rs        | 15 +++++----------
 Usermode/libsyscalls/lib.rs      |  6 +++---
 Usermode/libwtk/input/button.rs  |  6 ------
 Usermode/libwtk/lib.rs           |  2 +-
 common.mk                        | 15 +++++++++++++--
 10 files changed, 52 insertions(+), 41 deletions(-)

diff --git a/Kernel/Makefile b/Kernel/Makefile
index 9c3beab8..7d96fdd0 100644
--- a/Kernel/Makefile
+++ b/Kernel/Makefile
@@ -146,15 +146,6 @@ doc/$(ARCH)/kernel/index.html: Core/main.rs $(OBJDIR)libkernel.rlib
 doc/$(ARCH)/core/index.html: ../libcore/lib.rs $(OBJDIR)libcore.rlib
 
 
-ifeq ($(RUSTC_DATE),)
- RUSTUP_VER := nightly
- LIBCORE_URL := https://static.rust-lang.org/dist/rustc-nightly-src.tar.gz
-else
- RUSTUP_VER := nightly-$(RUSTC_DATE)
- LIBCORE_URL := https://static.rust-lang.org/dist/$(RUSTC_DATE)/rustc-nightly-src.tar.gz
-endif
-RUSTUP_SRC_DIR = $(firstword $(wildcard ../.prefix/toolchains/nightly-*/lib/rustlib/src/rust/src))/
-
 # ===
 # Toolchain maintainence
 # - Downloads rustc and libcore
@@ -165,7 +156,8 @@ UPDATE:
 	curl https://static.rust-lang.org/rustup/rustup-init.sh -sSf | RUSTUP_HOME=$(abspath ../.prefix) CARGO_HOME=$(abspath ../.prefix) sh -s -- --default-toolchain none --no-modify-path -y
 	$(call fn_rustcmd,rustup) update $(RUSTUP_VER)
 	$(call fn_rustcmd,rustup) default $(RUSTUP_VER)
-	$(call fn_rustcmd,rustup) component add rust-src
+	#$(call fn_rustcmd,rustup) component add rust-src
+	curl $(LIBCORE_URL)
 	test -f ../.prefix/bin/xargo || $(CARGO) install xargo
 
 ../libcore/lib.rs: ../libcore_nofp.patch $(RUSTUP_SRC_DIR)libcore/lib.rs
diff --git a/Makefile b/Makefile
index d891c770..900ba3c5 100644
--- a/Makefile
+++ b/Makefile
@@ -22,5 +22,15 @@ clean:
 
 UPDATE:
 	@echo ">>> Updating rustc and libcore"
-	@make -C Kernel/ UPDATE --no-print-directory
-	@make -C Kernel/ ../libcore/lib.rs --no-print-directory
+	#@make -C Kernel/ UPDATE --no-print-directory
+	#@make -C Kernel/ ../libcore/lib.rs --no-print-directory
+	#
+	@mkdir -p ../.prefix
+	curl https://static.rust-lang.org/rustup/rustup-init.sh -sSf | RUSTUP_HOME=$(abspath ../.prefix) CARGO_HOME=$(abspath ../.prefix) sh -s -- --default-toolchain none --no-modify-path -y
+	$(call fn_rustcmd,rustup) update $(RUSTUP_VER)
+	$(call fn_rustcmd,rustup) default $(RUSTUP_VER)
+	#$(call fn_rustcmd,rustup) component add rust-src
+	curl $(RUSTC_SRC_URL) -o rustc-nightly-src.tar.gz
+	tar -xf rustc-nightly-src.tar.gz --wildcards rustc-nightly-src/src/lib\* rustc-nightly-src/src/stdsimd rustc-nightly-src/vendor/compiler_builtins
+	rm -rf rustc-nightly-src/src/libcompiler_builtins; mv rustc-nightly-src/vendor/compiler_builtins rustc-nightly-src/src/libcompiler_builtins
+	test -f .prefix/bin/xargo || $(CARGO) install xargo
diff --git a/Usermode/Makefile b/Usermode/Makefile
index 59f92215..17f94bf6 100644
--- a/Usermode/Makefile
+++ b/Usermode/Makefile
@@ -29,7 +29,8 @@ TARGET_SPEC := target-$(ARCH).json
 RUST_COMMON_FLAGS := --target=$(TARGET_SPEC) --cfg 'arch="$(ARCH)"' --cfg nightly
 RUST_COMMON_FLAGS += -L $(LIBDIR)
 
-RUSTUP_SRC_DIR = $(firstword $(wildcard ../.prefix/toolchains/nightly-*/lib/rustlib/src/rust/src))/
+XARGO := RUST_TARGET_PATH=$(dir $(abspath $(TARGET_SPEC))) $(XARGO)
+XARGO_FLAGS := --target target-$(ARCH)
 
 RUSTFLAGS := $(RUST_COMMON_FLAGS)
 RUSTFLAGS += -O
@@ -79,6 +80,7 @@ LOADER_DEPS := $(patsubst %,$(LIBDIR)lib%.rlib,$(call fn_getdeps,loader/src/main
 # Most binary targets have simple templates, but loader and libcore are special
 # loader: Requires an assembly stub
 # > Linking is done in two steps so that --gc-sections works
+#$(BINDIR)loader: loader/link.ld $(OBJDIR)loader/start.ao $(OBJDIR)loader/src/main.o
 $(BINDIR)loader: loader/link.ld $(OBJDIR)loader/start.ao $(OBJDIR)loader/src/main.o $(LOADER_DEPS)
 	@mkdir -p $(dir $@)
 	@echo [LD] $@
@@ -87,6 +89,12 @@ $(BINDIR)loader: loader/link.ld $(OBJDIR)loader/start.ao $(OBJDIR)loader/src/mai
 	$V$(OBJCOPY) $(OBJDIR)loader.elf -O binary $@
 	$V$(OBJDUMP) -CS $(OBJDIR)loader.elf > $(OBJDIR)loader.dsm
 $(OBJDIR)loader/src/main.o: $(LOADER_DEPS)
+#$(OBJDIR)loader/src/main.o:
+#	$(XARGO) build $(XARGO_FLAGS) --manifest-path loader/Cargo.toml
+
+.PHONY: xargo
+xargo:
+	$(XARGO) build $(XARGO_FLAGS)
 
 # Low-level loader dummy dynamic library
 # - Used to tell ld that `loader`'s exported symbols actually exist
diff --git a/Usermode/liballoc_system/heap.rs b/Usermode/liballoc_system/heap.rs
index 6d0093e6..c1fc7239 100644
--- a/Usermode/liballoc_system/heap.rs
+++ b/Usermode/liballoc_system/heap.rs
@@ -4,12 +4,12 @@
 use sync::Mutex;
 use core::mem::{align_of,size_of};
 
-#[cfg(arch="amd64")] const HEAP_LIMITS: (usize,usize) = (0x1000_0000_0000, 0x7000_0000_0000);
-#[cfg(arch="amd64")] const PAGE_SIZE: usize = 0x1000;
-#[cfg(arch="armv7")] const HEAP_LIMITS: (usize,usize) = (0x1000_0000, 0x7000_0000);
-#[cfg(arch="armv7")] const PAGE_SIZE: usize = 0x2000;
-#[cfg(arch="armv8")] const HEAP_LIMITS: (usize,usize) = (0x1000_0000, 0x7000_0000);
-#[cfg(arch="armv8")] const PAGE_SIZE: usize = 0x4000;
+#[cfg(target_arch="x86_64")] const HEAP_LIMITS: (usize,usize) = (0x1000_0000_0000, 0x7000_0000_0000);
+#[cfg(target_arch="x86_64")] const PAGE_SIZE: usize = 0x1000;
+#[cfg(target_arch="arm")] const HEAP_LIMITS: (usize,usize) = (0x1000_0000, 0x7000_0000);
+#[cfg(target_arch="arm")] const PAGE_SIZE: usize = 0x2000;
+#[cfg(target_arch="aarch64")] const HEAP_LIMITS: (usize,usize) = (0x1000_0000, 0x7000_0000);
+#[cfg(target_arch="aarch64")] const PAGE_SIZE: usize = 0x4000;
 
 
 pub const EMPTY: *mut u8 = 1 as *mut u8;
diff --git a/Usermode/libstd/src/lib.rs b/Usermode/libstd/src/lib.rs
index 100790a3..e6817824 100644
--- a/Usermode/libstd/src/lib.rs
+++ b/Usermode/libstd/src/lib.rs
@@ -4,6 +4,7 @@
 // A clone of rust's libstd customised to work correctly on Tifflin
 #![crate_type="rlib"]
 #![crate_name="std"]
+//#![feature(staged_api)]	// stability
 #![feature(lang_items)]	// Allow definition of lang_items
 #![feature(linkage)]	// Used for low-level runtime
 #![feature(core_intrinsics)]
diff --git a/Usermode/libstd_rt/lib.rs b/Usermode/libstd_rt/lib.rs
index efec02f9..f051e41c 100644
--- a/Usermode/libstd_rt/lib.rs
+++ b/Usermode/libstd_rt/lib.rs
@@ -17,9 +17,9 @@ mod std {
 	pub use core::fmt;
 }
 
-#[cfg(arch="armv7")]
+#[cfg(target_arch="arm")]
 enum Void {}
-#[cfg(arch="armv7")]
+#[cfg(target_arch="arm")]
 mod memory {
 	pub mod virt {
 		pub fn is_reserved<T>(p: *const T) -> bool {
@@ -36,14 +36,9 @@ mod memory {
 	}
 }
 
-#[cfg(arch="amd64")]
-#[path="arch-x86_64.rs"]
-mod arch;
-#[cfg(arch="armv7")]
-#[path="arch-armv7.rs"]
-mod arch;
-#[cfg(arch="armv8")]
-#[path="arch-armv8.rs"]
+#[cfg_attr(target_arch="x86_64", path="arch-x86_64.rs")]
+#[cfg_attr(target_arch="arm", path="arch-armv7.rs")]
+#[cfg_attr(target_arch="aarch64", path="arch-armv8.rs")]
 mod arch;
 
 fn begin_panic_fmt(msg: &::core::fmt::Arguments, file_line: (&str, u32)) -> ! {
diff --git a/Usermode/libsyscalls/lib.rs b/Usermode/libsyscalls/lib.rs
index 63e911ff..f5c801d1 100644
--- a/Usermode/libsyscalls/lib.rs
+++ b/Usermode/libsyscalls/lib.rs
@@ -71,11 +71,11 @@ mod values;
 
 pub enum Void {}
 
-#[cfg(arch="amd64")] #[path="raw-amd64.rs"]
+#[cfg(target_arch="x86_64")] #[path="raw-amd64.rs"]
 mod raw;
-#[cfg(arch="armv7")] #[path="raw-armv7.rs"]
+#[cfg(target_arch="arm")] #[path="raw-armv7.rs"]
 mod raw;
-#[cfg(arch="armv8")] #[path="raw-armv8.rs"]
+#[cfg(target_arch="aarch64")] #[path="raw-armv8.rs"]
 mod raw;
 
 #[macro_use]
diff --git a/Usermode/libwtk/input/button.rs b/Usermode/libwtk/input/button.rs
index 9b925180..ac4d3a9a 100644
--- a/Usermode/libwtk/input/button.rs
+++ b/Usermode/libwtk/input/button.rs
@@ -19,14 +19,11 @@ where
 	state: RefCell<State>,
 }
 
-#[cfg(nightly)]
 pub type ButtonBcb<'a, T> = Button<T, BoxCb<'a, T>>;
 
-#[cfg(nightly)]
 /// Wrapper around a Box<Fn> that allows a `Button` to be stored in a struct
 pub struct BoxCb<'a, T: 'a + ::Element>(Box<Fn(&ButtonInner<T>, &mut ::window::WindowTrait)+'a>);
 
-#[cfg(nightly)]
 impl<'a, 'b1, 'b2, 'b3, T> ::std::ops::Fn<(&'b1 ButtonInner<T>, &'b2 mut (::window::WindowTrait<'b3> + 'b2))> for BoxCb<'a, T>
 where
 	T: 'a + ::Element
@@ -35,7 +32,6 @@ where
 		self.0.call(args)
 	}
 }
-#[cfg(nightly)]
 impl<'a, 'b1, 'b2, 'b3, T> ::std::ops::FnMut<(&'b1 ButtonInner<T>, &'b2 mut (::window::WindowTrait<'b3> + 'b2))> for BoxCb<'a, T>
 where
 	T: 'a + ::Element
@@ -44,7 +40,6 @@ where
 		self.call(args)
 	}
 }
-#[cfg(nightly)]
 impl<'a, 'b1, 'b2, 'b3, T> ::std::ops::FnOnce<(&'b1 ButtonInner<T>, &'b2 mut (::window::WindowTrait<'b3> + 'b2))> for BoxCb<'a, T>
 where
 	T: 'a + ::Element
@@ -83,7 +78,6 @@ impl<'a, T> Button<T, BoxCb<'a, T>>
 where
 	T: ::Element,
 {
-	#[cfg(nightly)]
 	pub fn new_boxfn<F2>(ele: T, cb: F2) -> Self
 	where
 		F2: 'a + Fn(&ButtonInner<T>, &mut ::window::WindowTrait)
diff --git a/Usermode/libwtk/lib.rs b/Usermode/libwtk/lib.rs
index 51af0a51..05d7a72f 100644
--- a/Usermode/libwtk/lib.rs
+++ b/Usermode/libwtk/lib.rs
@@ -3,7 +3,7 @@
 //
 //! Tifflin window toolkit
 #![feature(const_fn)]
-#![cfg_attr(nightly, feature(unboxed_closures,fn_traits))]
+#![feature(unboxed_closures,fn_traits)]
 
 extern crate async;
 extern crate byteorder;
diff --git a/common.mk b/common.mk
index 6a6f015d..b12df468 100644
--- a/common.mk
+++ b/common.mk
@@ -14,6 +14,15 @@ else
   $(error Unknown architecture $(ARCH) in common.mk)
 endif
 
+
+ifeq ($(RUSTC_DATE),)
+ RUSTUP_VER := nightly
+ RUSTC_SRC_URL := https://static.rust-lang.org/dist/rustc-nightly-src.tar.gz
+else
+ RUSTUP_VER := nightly-$(RUSTC_DATE)
+ RUSTC_SRC_URL := https://static.rust-lang.org/dist/$(RUSTC_DATE)/rustc-nightly-src.tar.gz
+endif
+
 CC := $(TRIPLE)-gcc
 LD := $(TRIPLE)-ld
 AS := $(TRIPLE)-as
@@ -31,7 +40,9 @@ fn_rustcmd = RUSTUP_HOME=$(abspath $(PREFIX)) CARGO_HOME=$(abspath $(PREFIX)) $(
 RUSTC := $(call fn_rustcmd,rustc)
 RUSTDOC := $(call fn_rustcmd,rustdoc)
 CARGO := $(call fn_rustcmd,cargo)
-XARGO := $(call fn_rustcmd,xargo)
+XARGO := XARGO_HOME=$(abspath $(PREFIX)xargo) $(call fn_rustcmd,xargo)
 
-RUSTUP_SRC_DIR = $(firstword $(wildcard $(PREFIX)toolchains/nightly-*/lib/rustlib/src/rust/src))/
+#RUSTUP_SRC_DIR = $(firstword $(wildcard $(PREFIX)toolchains/nightly-*/lib/rustlib/src/rust/src))/
+RUSTUP_SRC_DIR := $(abspath $(ROOTDIR)/rustc-nightly-src/src)/
+$(warning $(RUSTUP_SRC_DIR))
 
-- 
GitLab