From 1e34f3411f3929bac854d021877d07b083edea00 Mon Sep 17 00:00:00 2001 From: Asami Doi Date: Mon, 9 Sep 2024 22:17:46 +0200 Subject: [PATCH 1/4] tmp --- Cargo.toml | 3 +++ Makefile | 52 ++++++++++++++++++++++++++++++++++++------------ run_on_wasabi.sh | 35 +++++++------------------------- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 291f853..3e63612 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,9 @@ version = "0.1.0" edition = "2021" default-run = "saba" +[workspace] +members = [ "net/wasabi", "ui/wasabi" ] + [features] default = ["wasabi"] cui = ["dep:net_std", "dep:ui_cui"] diff --git a/Makefile b/Makefile index 4615036..49d3efc 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,50 @@ -# This is used for Wasabi OS TARGET=x86_64-unknown-none -ROOT=$(shell readlink -f ../..)/generated +NAME=$(shell echo "${PWD##*/}") +ROOT=./generated RUSTFLAGS=\ -C link-args=-e \ -C link-args=entry \ -C link-args=-z \ -C link-args=execstack -CARGO=RUSTFLAGS='${RUSTFLAGS}' cargo -FEATURES=--features=wasabi +CARGO=RUSTFLAGS='$(RUSTFLAGS)' cargo +BIN_PATH_DEBUG=$(shell cargo metadata --format-version 1 | jq -r .target_directory)/debug/$(NAME) +APP_BUILD_ARG=-v --target x86_64-unknown-none --release .PHONY : build -build : build_saba build_httpclient +build : + $(CARGO) build $(APP_BUILD_ARG) -build_saba : setup - $(CARGO) build $(FEATURES) --bin=saba --target=$(TARGET) - $(CARGO) install $(FEATURES) --bin=saba --target=$(TARGET) --force --root $(ROOT) --path . +.PHONY : test +test : + cargo build + cargo test -build_httpclient : setup - $(CARGO) build $(FEATURES) --bin=httpclient --target=$(TARGET) - $(CARGO) install $(FEATURES) --bin=httpclient --target=$(TARGET) --force --root $(ROOT) --path . - -setup : +.PHONY : clippy +clippy : rustup target add $(TARGET) + cargo clippy --all-features --target=$(TARGET) -- -D warnings + cargo clippy --all-features -- -D warnings + +.PHONY : objdump +objdump : + cargo install cargo-binutils + rustup component add llvm-tools-preview + $(CARGO) objdump -- -d + +.PHONY : nm +nm : + cargo install cargo-binutils + rustup component add llvm-tools-preview + $(CARGO) nm + +.PHONY : readelf +readelf : build + readelf -l $(BIN_PATH_DEBUG) + +.PHONY : hexdump +hexdump : build + hexdump -C $(BIN_PATH_DEBUG) + +.PHONY : run +run : + make -C ../../ run diff --git a/run_on_wasabi.sh b/run_on_wasabi.sh index 41e196b..564029a 100755 --- a/run_on_wasabi.sh +++ b/run_on_wasabi.sh @@ -5,6 +5,7 @@ TARGET_PATH=$PWD"/build" OS_PATH=$TARGET_PATH"/wasabi" APP_NAME="saba" APP_PATH=$OS_PATH"/app/"$APP_NAME +MAKEFILE_PATH=$HOME_PATH"/Makefile" # execute `mkdir build/` if it doesn't exist if [ -d $TARGET_PATH ] @@ -36,33 +37,11 @@ fi # go back to the application top directory cd $HOME_PATH -# create $APP_PATH in Wasabi OS if it doesn't exist -if [ -d $APP_PATH ] -then - echo $APP_PATH" exists" -else - echo $APP_PATH" doesn't exist" - mkdir $APP_PATH -fi - -# copy an application except `target`, `.git` and `build` directories to Wasabi -echo "copying the project to wasabi OS..." -cp -R `ls -A ./ | grep -v "target" | grep -v ".git" | grep -v "build"` $APP_PATH - -cd $OS_PATH - -# update Cargo.toml to add $APP_NAME package -# this is very hacky and not stable -mv Cargo.toml Cargo.toml.original -if [ $(grep -c "app/$APP_NAME" Cargo.toml.original) -eq 1 ] -then - echo "$APP_PATH already exists in Cargo.toml" - mv Cargo.toml.original Cargo.toml -else - sed "s/^members = \[/members = \[\n \"app\/$APP_NAME\",/" Cargo.toml.original >| Cargo.toml +# download Makefile if it doesn't exist +if [ ! -f $MAKEFILE_PATH ]; then + echo "downloading Makefile..." + wget https://raw.githubusercontent.com/hikalium/wasabi/main/external_app_template/Makefile fi -rm Cargo.toml.original -make run - -cd $HOME_PATH +make build +make $OS_PATH/scripts/run_with_app.sh ./target/x86_64-unknown-none/release/$APP_NAME From 6edd18d3817f1ddcd8b5f719bb893ea37c366cea Mon Sep 17 00:00:00 2001 From: Asami Doi Date: Tue, 10 Sep 2024 21:22:30 +0200 Subject: [PATCH 2/4] add cfg_attr(not(target_os = linux), no_main --- Cargo.toml | 2 +- net/wasabi/src/lib.rs | 2 ++ rust-toolchain.toml | 3 ++- src/saba_wasabi.rs | 5 ++++- ui/wasabi/Cargo.toml | 3 +-- ui/wasabi/src/lib.rs | 2 ++ 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e63612..0bc67d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,4 +39,4 @@ ui_cui = { path = "./ui/cui", optional = true } # Dependencies used for browser on WasabiOS net_wasabi = { path = "./net/wasabi", optional = true } ui_wasabi = { path = "./ui/wasabi", optional = true } -noli = { git = "https://github.com/hikalium/wasabi.git", optional = true } +noli = { git = "https://github.com/hikalium/wasabi.git", optional = true, version = "0.1.0" } diff --git a/net/wasabi/src/lib.rs b/net/wasabi/src/lib.rs index f0690af..e6c3dc6 100644 --- a/net/wasabi/src/lib.rs +++ b/net/wasabi/src/lib.rs @@ -1,3 +1,5 @@ #![no_std] +#![cfg_attr(not(target_os = "linux"), no_main)] +use noli::prelude::*; pub mod http; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 3db88b4..cb2dc26 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,6 @@ [toolchain] channel = "nightly-2024-01-01" -components = [ "rustfmt", "rust-src" ] +components = [ "rustfmt"] +# https://doc.rust-lang.org/nightly/rustc/platform-support.html targets = [ "x86_64-unknown-linux-gnu"] profile = "default" diff --git a/src/saba_wasabi.rs b/src/saba_wasabi.rs index 3f88e1a..5f97782 100644 --- a/src/saba_wasabi.rs +++ b/src/saba_wasabi.rs @@ -3,6 +3,10 @@ extern crate alloc; +#![cfg_attr(not(target_os = "linux"), no_main)] +use noli::prelude::*; +entry_point!(main); + use crate::alloc::string::ToString; use alloc::format; use alloc::rc::Rc; @@ -98,4 +102,3 @@ fn main() -> u64 { 0 } -entry_point!(main); diff --git a/ui/wasabi/Cargo.toml b/ui/wasabi/Cargo.toml index 84dc64a..f6f42e3 100644 --- a/ui/wasabi/Cargo.toml +++ b/ui/wasabi/Cargo.toml @@ -8,5 +8,4 @@ edition = "2021" tinybmp = "0.5.0" embedded-graphics = "0.8.1" saba_core = { path = "../../core" } -noli = { git = "https://github.com/hikalium/wasabi.git" } -#noli = { path = "../../../../noli" } +noli = { git = "https://github.com/hikalium/wasabi.git", version = "0.1.0" } diff --git a/ui/wasabi/src/lib.rs b/ui/wasabi/src/lib.rs index 7801eb8..dd11aee 100644 --- a/ui/wasabi/src/lib.rs +++ b/ui/wasabi/src/lib.rs @@ -1,4 +1,6 @@ #![no_std] +#![cfg_attr(not(target_os = "linux"), no_main)] +use noli::prelude::*; extern crate alloc; From bdba940925000873518b3c9b6a6d25aad349c29c Mon Sep 17 00:00:00 2001 From: Asami Doi Date: Fri, 13 Sep 2024 18:06:56 +0200 Subject: [PATCH 3/4] update cfg_attr --- net/wasabi/src/lib.rs | 3 ++- ui/wasabi/src/lib.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/net/wasabi/src/lib.rs b/net/wasabi/src/lib.rs index e6c3dc6..cbd9c7a 100644 --- a/net/wasabi/src/lib.rs +++ b/net/wasabi/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] -#![cfg_attr(not(target_os = "linux"), no_main)] + +#[cfg_attr(target_os = "linux", no_main)] use noli::prelude::*; pub mod http; diff --git a/ui/wasabi/src/lib.rs b/ui/wasabi/src/lib.rs index dd11aee..df6c67d 100644 --- a/ui/wasabi/src/lib.rs +++ b/ui/wasabi/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] -#![cfg_attr(not(target_os = "linux"), no_main)] + +#[cfg_attr(target_os = "linux", no_main)] use noli::prelude::*; extern crate alloc; From 0656060059d6c7f7c847bbe4377800537378056b Mon Sep 17 00:00:00 2001 From: Asami Doi Date: Fri, 13 Sep 2024 18:13:00 +0200 Subject: [PATCH 4/4] fixup --- run_on_wasabi.sh | 2 +- src/saba_wasabi.rs | 5 ++--- ui/wasabi/src/app.rs | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/run_on_wasabi.sh b/run_on_wasabi.sh index 564029a..2b9255d 100755 --- a/run_on_wasabi.sh +++ b/run_on_wasabi.sh @@ -44,4 +44,4 @@ if [ ! -f $MAKEFILE_PATH ]; then fi make build -make $OS_PATH/scripts/run_with_app.sh ./target/x86_64-unknown-none/release/$APP_NAME +$OS_PATH/scripts/run_with_app.sh ./target/x86_64-unknown-none/release/$APP_NAME diff --git a/src/saba_wasabi.rs b/src/saba_wasabi.rs index 5f97782..ccac0cd 100644 --- a/src/saba_wasabi.rs +++ b/src/saba_wasabi.rs @@ -3,7 +3,7 @@ extern crate alloc; -#![cfg_attr(not(target_os = "linux"), no_main)] +#[cfg_attr(target_os = "linux", no_main)] use noli::prelude::*; entry_point!(main); @@ -21,7 +21,7 @@ use saba_core::http::HttpResponse; use saba_core::url::HtmlUrl; use ui_wasabi::app::WasabiUI; -fn handle_url(url: String) -> Result { +fn handle_url(url: String) -> core::result::Result { // parse url let parsed_url = match HtmlUrl::new(url.to_string()).parse() { Ok(url) => url, @@ -101,4 +101,3 @@ fn main() -> u64 { 0 } - diff --git a/ui/wasabi/src/app.rs b/ui/wasabi/src/app.rs index 5d1f38d..2a5bf0b 100644 --- a/ui/wasabi/src/app.rs +++ b/ui/wasabi/src/app.rs @@ -6,6 +6,7 @@ use alloc::string::ToString; use core::cell::RefCell; use core::include_bytes; use embedded_graphics::{image::Image, pixelcolor::Rgb888, prelude::*}; +use noli::_print; use noli::error::Result as OsResult; use noli::prelude::SystemApi; use noli::print;