mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
hosted: fix hosted builds
We can now run `cargo xtask run` and it will do the right thing. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
0ca7fe6f12
commit
dfd11f846d
8 changed files with 108 additions and 272 deletions
44
Cargo.lock
generated
44
Cargo.lock
generated
|
|
@ -274,7 +274,6 @@ dependencies = [
|
|||
name = "log-server"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"pancurses",
|
||||
"xous",
|
||||
]
|
||||
|
||||
|
|
@ -310,17 +309,6 @@ dependencies = [
|
|||
"xkbcommon-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ncurses"
|
||||
version = "5.99.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "15699bee2f37e9f8828c7b35b2bc70d13846db453f2d507713b758fabe536b82"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.17.0"
|
||||
|
|
@ -391,29 +379,6 @@ dependencies = [
|
|||
"sdl2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pancurses"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3058bc37c433096b2ac7afef1c5cdfae49ede0a4ffec3dfc1df1df0959d0ff0"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"ncurses",
|
||||
"pdcurses-sys",
|
||||
"winreg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pdcurses-sys"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "084dd22796ff60f1225d4eb6329f33afaf4c85419d51d440ab6b8c6f4529166b"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.18"
|
||||
|
|
@ -949,15 +914,6 @@ version = "0.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "winreg"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x11-dl"
|
||||
version = "2.18.5"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,5 @@ description = "Log output program"
|
|||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
|
||||
[target.'cfg(any(windows, unix))'.dependencies]
|
||||
#bracket-terminal = "0.8.1"
|
||||
pancurses = "*"
|
||||
#[target.'cfg(any(windows, unix))'.dependencies]
|
||||
#pancurses = "*"
|
||||
|
|
|
|||
|
|
@ -1,85 +1,19 @@
|
|||
#![cfg_attr(baremetal, no_std)]
|
||||
#![cfg_attr(baremetal, no_main)]
|
||||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
#[cfg(baremetal)]
|
||||
#[macro_use]
|
||||
mod debug;
|
||||
|
||||
mod log_string;
|
||||
mod start;
|
||||
|
||||
use core::fmt::Write;
|
||||
use log_string::LogString;
|
||||
|
||||
#[cfg(bracket_terminal)]
|
||||
mod implementation {
|
||||
use bracket_terminal::prelude::*;
|
||||
use core::fmt::{Error, Write};
|
||||
use std::sync::mpsc::{channel, Sender};
|
||||
use std::thread::{spawn, JoinHandle};
|
||||
|
||||
struct State {}
|
||||
|
||||
impl GameState for State {
|
||||
fn tick(&mut self, ctx: &mut BTerm) {
|
||||
ctx.print(1, 1, "Hello Bracket World");
|
||||
}
|
||||
}
|
||||
|
||||
enum ControlMessage {
|
||||
Text(String),
|
||||
Exit,
|
||||
}
|
||||
|
||||
pub struct Output {
|
||||
stream: Sender<ControlMessage>,
|
||||
context: Option<BTerm>,
|
||||
gs: Option<State>,
|
||||
}
|
||||
|
||||
pub fn init() -> Output {
|
||||
let (tx, rx) = channel();
|
||||
|
||||
let context = BTermBuilder::simple80x50()
|
||||
.with_title("Hello Minimal Bracket World")
|
||||
.build()
|
||||
.unwrap();
|
||||
let gs: State = State {};
|
||||
Output {
|
||||
stream: tx,
|
||||
context: Some(context),
|
||||
gs: Some(gs),
|
||||
}
|
||||
}
|
||||
|
||||
impl Output {
|
||||
pub fn run(&mut self) {
|
||||
main_loop(self.context.take().unwrap(), self.gs.take().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Output {
|
||||
fn drop(&mut self) {
|
||||
self.stream.send(ControlMessage::Exit).unwrap();
|
||||
// self.finish.take().unwrap().join().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for Output {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), Error> {
|
||||
// It would be nice if this worked with &str
|
||||
self.stream
|
||||
.send(ControlMessage::Text(s.to_owned()))
|
||||
.unwrap();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(baremetal))]
|
||||
#[cfg(not(target_os = "none"))]
|
||||
mod implementation {
|
||||
use core::fmt::{Error, Write};
|
||||
use pancurses::{endwin, initscr, Window};
|
||||
// use pancurses::{endwin, initscr, Window};
|
||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||
|
||||
enum ControlMessage {
|
||||
|
|
@ -88,20 +22,20 @@ mod implementation {
|
|||
}
|
||||
|
||||
pub struct Output {
|
||||
window: Option<Window>,
|
||||
// window: Option<Window>,
|
||||
tx: Sender<ControlMessage>,
|
||||
rx: Receiver<ControlMessage>,
|
||||
}
|
||||
|
||||
pub fn init() -> Output {
|
||||
let (tx, rx) = channel();
|
||||
let window = initscr();
|
||||
window.nodelay(true);
|
||||
// let window = initscr();
|
||||
// window.nodelay(true);
|
||||
|
||||
Output {
|
||||
tx,
|
||||
rx,
|
||||
window: Some(window),
|
||||
// window: Some(window),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,13 +46,14 @@ mod implementation {
|
|||
Ok(msg) => match msg {
|
||||
ControlMessage::Exit => break,
|
||||
ControlMessage::Text(s) => {
|
||||
self.window.as_ref().unwrap().printw(s);
|
||||
self.window.as_ref().unwrap().refresh();
|
||||
print!("{}", s);
|
||||
// self.window.as_ref().unwrap().printw(s);
|
||||
// self.window.as_ref().unwrap().refresh();
|
||||
}
|
||||
},
|
||||
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {
|
||||
// Calling `getch` refreshes the screen
|
||||
self.window.as_ref().unwrap().getch();
|
||||
// self.window.as_ref().unwrap().getch();
|
||||
}
|
||||
Err(e) => panic!("Error: {}", e),
|
||||
}
|
||||
|
|
@ -135,7 +70,7 @@ mod implementation {
|
|||
impl Drop for Output {
|
||||
fn drop(&mut self) {
|
||||
self.tx.send(ControlMessage::Exit).unwrap();
|
||||
endwin();
|
||||
// endwin();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +95,7 @@ mod implementation {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(baremetal)]
|
||||
#[cfg(target_os = "none")]
|
||||
mod implementation {
|
||||
use core::fmt::{Error, Write};
|
||||
|
||||
|
|
@ -217,15 +152,15 @@ mod implementation {
|
|||
}
|
||||
}
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
// use core::panic::PanicInfo;
|
||||
|
||||
#[panic_handler]
|
||||
fn handle_panic(arg: &PanicInfo) -> ! {
|
||||
println!("PANIC!");
|
||||
println!("Details: {:?}", arg);
|
||||
xous::syscall::wait_event();
|
||||
loop {}
|
||||
}
|
||||
// #[panic_handler]
|
||||
// fn handle_panic(arg: &PanicInfo) -> ! {
|
||||
// println!("PANIC!");
|
||||
// println!("Details: {:?}", arg);
|
||||
// xous::syscall::wait_event();
|
||||
// loop {}
|
||||
// }
|
||||
|
||||
fn handle_irq(irq_no: usize, arg: *mut usize) {
|
||||
print!("Handling IRQ {} (arg: {:08x}): ", irq_no, arg as usize);
|
||||
|
|
@ -314,8 +249,8 @@ fn reader_thread(mut output: implementation::OutputWriter) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(baremetal, no_mangle)]
|
||||
fn main() {
|
||||
#[xous::xous_main]
|
||||
fn some_main() -> ! {
|
||||
let mut output = implementation::init();
|
||||
let writer = output.get_writer();
|
||||
// xous::arch::ensure_connection().unwrap();
|
||||
|
|
@ -323,4 +258,5 @@ fn main() {
|
|||
xous::create_thread_simple(reader_thread, writer).unwrap();
|
||||
println!("Running the output");
|
||||
output.run();
|
||||
panic!("exited");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
/// Rust entry point (_start_rust)
|
||||
///
|
||||
/// Zeros bss section, initializes data section and calls main. This function
|
||||
/// never returns.
|
||||
#[link_section = ".init.rust"]
|
||||
#[export_name = "_start"]
|
||||
pub unsafe extern "C" fn start_rust() -> ! {
|
||||
extern "Rust" {
|
||||
// This symbol will be provided by the kernel
|
||||
fn main();
|
||||
}
|
||||
main();
|
||||
panic!("exited main");
|
||||
}
|
||||
|
||||
#[export_name = "abort"]
|
||||
pub extern "C" fn abort() -> ! {
|
||||
panic!("aborted");
|
||||
}
|
||||
|
|
@ -19,5 +19,5 @@ rustflags = [
|
|||
"-C", "force-frame-pointers=no",
|
||||
]
|
||||
|
||||
[build]
|
||||
target = "riscv32imac-unknown-none-elf"
|
||||
#[build]
|
||||
#target = "riscv32imac-unknown-none-elf"
|
||||
|
|
|
|||
|
|
@ -55,22 +55,6 @@ use proc_macro::TokenStream;
|
|||
pub fn xous_main(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let f = parse_macro_input!(input as ItemFn);
|
||||
|
||||
// let hosted =
|
||||
// cfg!(target_os = "linux") || cfg!(target_os = "windows") || cfg!(target_os = "macos");
|
||||
// let is_none = cfg!(target_os = "");
|
||||
|
||||
// return parse::Error::new(
|
||||
// f.span(),
|
||||
// format!(
|
||||
// "Target OS is none? {} - hosted? {} Unknown OS? {}",
|
||||
// is_none,
|
||||
// hosted,
|
||||
// cfg!(target_os = "unknown")
|
||||
// ),
|
||||
// )
|
||||
// .to_compile_error()
|
||||
// .into();
|
||||
|
||||
// check the function signature
|
||||
let valid_signature = f.sig.constness.is_none()
|
||||
&& f.sig.asyncness.is_none()
|
||||
|
|
@ -109,95 +93,17 @@ pub fn xous_main(args: TokenStream, input: TokenStream) -> TokenStream {
|
|||
let hash = random_ident();
|
||||
let stmts = f.block.stmts;
|
||||
|
||||
quote!(
|
||||
xous::maybe_main!();
|
||||
let r = quote!(
|
||||
#[export_name = "xous_entry"]
|
||||
#(#attrs)*
|
||||
pub #unsafety fn #hash() -> ! {
|
||||
#(#stmts)*
|
||||
}
|
||||
|
||||
)
|
||||
.into()
|
||||
// pub fn main() {
|
||||
// #hash()
|
||||
// }
|
||||
xous::maybe_main!();
|
||||
);
|
||||
r.into()
|
||||
}
|
||||
|
||||
// /// Attribute to mark which function will be called at the beginning of the reset handler.
|
||||
// ///
|
||||
// /// **IMPORTANT**: This attribute can appear at most *once* in the dependency graph. Also, if you
|
||||
// /// are using Rust 1.30 the attribute must be used on a reachable item (i.e. there must be no
|
||||
// /// private modules between the item and the root of the crate); if the item is in the root of the
|
||||
// /// crate you'll be fine. This reachability restriction doesn't apply to Rust 1.31 and newer
|
||||
// /// releases.
|
||||
// ///
|
||||
// /// The function must have the signature of `unsafe fn()`.
|
||||
// ///
|
||||
// /// The function passed will be called before static variables are initialized. Any access of static
|
||||
// /// variables will result in undefined behavior.
|
||||
// ///
|
||||
// /// # Examples
|
||||
// ///
|
||||
// /// ```
|
||||
// /// # use riscv_rt_macros::pre_init;
|
||||
// /// #[pre_init]
|
||||
// /// unsafe fn before_main() {
|
||||
// /// // do something here
|
||||
// /// }
|
||||
// ///
|
||||
// /// # fn main() {}
|
||||
// /// ```
|
||||
// #[proc_macro_attribute]
|
||||
// pub fn pre_init(args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
// let f = parse_macro_input!(input as ItemFn);
|
||||
|
||||
// // check the function signature
|
||||
// let valid_signature = f.sig.constness.is_none()
|
||||
// && f.sig.asyncness.is_none()
|
||||
// && f.vis == Visibility::Inherited
|
||||
// && f.sig.unsafety.is_some()
|
||||
// && f.sig.abi.is_none()
|
||||
// && f.sig.inputs.is_empty()
|
||||
// && f.sig.generics.params.is_empty()
|
||||
// && f.sig.generics.where_clause.is_none()
|
||||
// && f.sig.variadic.is_none()
|
||||
// && match f.sig.output {
|
||||
// ReturnType::Default => true,
|
||||
// ReturnType::Type(_, ref ty) => match **ty {
|
||||
// Type::Tuple(ref tuple) => tuple.elems.is_empty(),
|
||||
// _ => false,
|
||||
// },
|
||||
// };
|
||||
|
||||
// if !valid_signature {
|
||||
// return parse::Error::new(
|
||||
// f.span(),
|
||||
// "`#[pre_init]` function must have signature `unsafe fn()`",
|
||||
// )
|
||||
// .to_compile_error()
|
||||
// .into();
|
||||
// }
|
||||
|
||||
// if !args.is_empty() {
|
||||
// return parse::Error::new(Span::call_site(), "This attribute accepts no arguments")
|
||||
// .to_compile_error()
|
||||
// .into();
|
||||
// }
|
||||
|
||||
// // XXX should we blacklist other attributes?
|
||||
// let attrs = f.attrs;
|
||||
// let ident = f.sig.ident;
|
||||
// let block = f.block;
|
||||
|
||||
// quote!(
|
||||
// #[export_name = "__pre_init"]
|
||||
// #(#attrs)*
|
||||
// pub unsafe fn #ident() #block
|
||||
// )
|
||||
// .into()
|
||||
// }
|
||||
|
||||
// Creates a random identifier
|
||||
fn random_ident() -> Ident {
|
||||
let secs = SystemTime::now()
|
||||
|
|
@ -221,9 +127,9 @@ fn random_ident() -> Ident {
|
|||
&(0..16)
|
||||
.map(|i| {
|
||||
if i == 0 || rng.gen() {
|
||||
('a' as u8 + rng.gen::<u8>() % 25) as char
|
||||
(b'a' + rng.gen::<u8>() % 25) as char
|
||||
} else {
|
||||
('0' as u8 + rng.gen::<u8>() % 10) as char
|
||||
(b'0' + rng.gen::<u8>() % 10) as char
|
||||
}
|
||||
})
|
||||
.collect::<String>(),
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ macro_rules! maybe_main {
|
|||
fn xous_entry() -> !;
|
||||
}
|
||||
fn main() {
|
||||
xous::arch::ensure_connection().unwrap();
|
||||
unsafe { xous_entry() };
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
env,
|
||||
path::{Path, PathBuf, MAIN_SEPARATOR},
|
||||
process::Command,
|
||||
};
|
||||
|
||||
|
|
@ -34,6 +34,7 @@ fn try_main() -> Result<(), DynError> {
|
|||
let task = env::args().nth(1);
|
||||
match task.as_deref() {
|
||||
Some("renode-image") => image()?,
|
||||
Some("run") => run()?,
|
||||
_ => print_help(),
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -49,29 +50,86 @@ renode-image builds a test image for renode
|
|||
|
||||
fn image() -> Result<(), DynError> {
|
||||
let debug = false;
|
||||
// let _ = fs::remove_dir_all(&dist_dir());
|
||||
// fs::create_dir_all(&dist_dir())?;
|
||||
|
||||
let kernel = build_kernel(debug)?;
|
||||
let mut init = vec![];
|
||||
for pkg in &["log-server", "graphics-server"] {
|
||||
init.push(build(pkg, debug, None)?);
|
||||
init.push(build(pkg, debug, Some(TARGET), None)?);
|
||||
}
|
||||
build("loader", false, Some("loader".into()))?;
|
||||
build("loader", false, Some(TARGET), Some("loader".into()))?;
|
||||
|
||||
create_image(&kernel, &init, debug)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_kernel(debug: bool) -> Result<PathBuf, DynError> {
|
||||
build("kernel", debug, Some("kernel".into()))
|
||||
fn run() -> Result<(), DynError> {
|
||||
let debug = false;
|
||||
let stream = if debug { "debug" } else { "release" };
|
||||
let init = ["shell", "log-server", "graphics-server"];
|
||||
|
||||
// let mut init_paths = vec![];
|
||||
for pkg in &init {
|
||||
build(pkg, debug, None, None)?;
|
||||
}
|
||||
// println!("Built packages: {:?}", init_paths);
|
||||
|
||||
// Build and run the kernel
|
||||
let mut args = vec!["run"];
|
||||
if !debug {
|
||||
args.push("--release");
|
||||
}
|
||||
|
||||
args.push("--");
|
||||
|
||||
let mut paths = vec![];
|
||||
for i in &init {
|
||||
let tmp: PathBuf = Path::new(&format!(
|
||||
"..{}target{}{}{}{}",
|
||||
MAIN_SEPARATOR, MAIN_SEPARATOR, stream, MAIN_SEPARATOR, i
|
||||
))
|
||||
.to_owned();
|
||||
// .canonicalize()
|
||||
// .or(Err(BuildError::PathConversionError))?;
|
||||
paths.push(tmp);
|
||||
}
|
||||
for t in &paths {
|
||||
args.push(t.to_str().ok_or(BuildError::PathConversionError)?);
|
||||
}
|
||||
|
||||
let mut dir = project_root();
|
||||
dir.push("kernel");
|
||||
|
||||
let status = Command::new(cargo())
|
||||
.current_dir(dir)
|
||||
.args(&args)
|
||||
.status()?;
|
||||
if !status.success() {
|
||||
return Err("cargo build failed".into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build(project: &str, debug: bool, directory: Option<PathBuf>) -> Result<PathBuf, DynError> {
|
||||
fn build_kernel(debug: bool) -> Result<PathBuf, DynError> {
|
||||
build("kernel", debug, Some(TARGET), Some("kernel".into()))
|
||||
}
|
||||
|
||||
fn build(
|
||||
project: &str,
|
||||
debug: bool,
|
||||
target: Option<&str>,
|
||||
directory: Option<PathBuf>,
|
||||
) -> Result<PathBuf, DynError> {
|
||||
println!("Building {}...", project);
|
||||
let stream = if debug { "debug" } else { "release" };
|
||||
let mut args = vec!["build", "--target", TARGET, "--package", project];
|
||||
let mut args = vec!["build", "--package", project];
|
||||
let mut target_path = "".to_owned();
|
||||
if let Some(t) = target {
|
||||
args.push("--target");
|
||||
args.push(t);
|
||||
target_path = format!("{}/", t);
|
||||
}
|
||||
|
||||
if !debug {
|
||||
args.push("--release");
|
||||
}
|
||||
|
|
@ -92,14 +150,14 @@ fn build(project: &str, debug: bool, directory: Option<PathBuf>) -> Result<PathB
|
|||
|
||||
if let Some(base_dir) = &directory {
|
||||
Ok(project_root().join(&format!(
|
||||
"{}/target/{}/{}/{}",
|
||||
"{}/target/{}{}/{}",
|
||||
base_dir.to_str().ok_or(BuildError::PathConversionError)?,
|
||||
TARGET,
|
||||
target_path,
|
||||
stream,
|
||||
project
|
||||
)))
|
||||
} else {
|
||||
Ok(project_root().join(&format!("target/{}/{}/{}", TARGET, stream, project)))
|
||||
Ok(project_root().join(&format!("target/{}{}/{}", target_path, stream, project)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue