rust templates: Squash and merge into master

Includes the following commits:
  Base rust template changes
  cantrip-os-rootserver: fixup stale comments

Change-Id: I4088597e45d5b55dfa4a8831715a393e494960ce
diff --git a/cantrip-os-rootserver/Cargo.toml b/cantrip-os-rootserver/Cargo.toml
index ffef78a..1c55d25 100644
--- a/cantrip-os-rootserver/Cargo.toml
+++ b/cantrip-os-rootserver/Cargo.toml
@@ -45,6 +45,6 @@
 
 [dependencies]
 cfg-if = "1.0"
-cstr_core = { version = "0.2.3", default-features = false }
+core2 = { version = "0.3", default-features = false }
 log = { version = "0.4", features = ["release_max_level_info"] }
 static_assertions = "1.1"
diff --git a/cantrip-os-rootserver/src/main.rs b/cantrip-os-rootserver/src/main.rs
index 171cc9d..c2ce159 100644
--- a/cantrip-os-rootserver/src/main.rs
+++ b/cantrip-os-rootserver/src/main.rs
@@ -42,14 +42,13 @@
 
 use cantrip_os_common::allocator;
 use cantrip_os_common::capdl;
-use cantrip_os_common::logger::CantripLogger;
 use cantrip_os_common::model;
 use cantrip_os_common::sel4_sys;
 use cfg_if::cfg_if;
 use core::mem::size_of;
+use core2::io::{Cursor, Write};
 use core::ptr;
-use log::LevelFilter;
-use log::{info, trace};
+use log::*;
 
 use capdl::CDL_Core;
 use capdl::CDL_Model;
@@ -207,28 +206,38 @@
     }
 }
 
-// Message output is sent through the cantrip-os-logger which calls logger_log
-// to deliver data to the console. We use seL4_DebugPutChar to write to the
-// console which only works if DEBUG_PRINTING is enabled in the kernel.
-// Note this differs from capdl-loader-app which uses the zf_log &
-// sel4platformsupport packages.
-#[no_mangle]
-#[allow(unused_variables)]
-pub fn logger_log(_level: u8, msg: *const cstr_core::c_char) {
-    #[cfg(feature = "CONFIG_PRINTING")]
-    unsafe {
-        for c in cstr_core::CStr::from_ptr(msg).to_bytes() {
-            let _ = sel4_sys::seL4_DebugPutChar(*c);
+// Console output is sent through the log crate. We use seL4_DebugPutChar
+// to write to the console which only works if DEBUG_PRINTING is enabled
+// in the kernel. Note this differs from capdl-loader-app which uses
+// sel4platformsupport to write to the console/uart.
+struct CapdlLogger;
+impl log::Log for CapdlLogger  {
+    fn enabled(&self, _metadata: &Metadata) -> bool { true }
+    fn flush(&self) {}
+    fn log(&self, record: &Record) {
+        let mut buf = [0u8; 1024];
+        let mut cur =  Cursor::new(&mut buf[..]);
+        write!(&mut cur, "{}:{}", record.target(), record.args()).unwrap_or_else(|_| {
+            cur.set_position((1024 - 3) as u64);
+            cur.write(b"...").expect("write");
+        });
+        let pos = cur.position() as usize;
+
+        #[cfg(feature = "CONFIG_PRINTING")]
+        unsafe {
+            for c in &buf[..pos] {
+                let _ = sel4_sys::seL4_DebugPutChar(*c);
+            }
+            let _ = sel4_sys::seL4_DebugPutChar(b'\n');
         }
-        let _ = sel4_sys::seL4_DebugPutChar(b'\n');
     }
 }
 
 #[no_mangle]
 pub fn main() {
     // Setup logger.
-    static CANTRIP_LOGGER: CantripLogger = CantripLogger;
-    log::set_logger(&CANTRIP_LOGGER).unwrap();
+    static CAPDL_LOGGER: CapdlLogger = CapdlLogger;
+    log::set_logger(&CAPDL_LOGGER).unwrap();
     log::set_max_level(INIT_LOG_LEVEL);
 
     // Setup memory allocation from a fixed heap. For the configurations