Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update run_on_wasabi.sh #3

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -36,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" }
52 changes: 39 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions net/wasabi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![no_std]

#[cfg_attr(target_os = "linux", no_main)]
use noli::prelude::*;

pub mod http;
35 changes: 7 additions & 28 deletions run_on_wasabi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down Expand Up @@ -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
$OS_PATH/scripts/run_with_app.sh ./target/x86_64-unknown-none/release/$APP_NAME
3 changes: 2 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -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"
8 changes: 5 additions & 3 deletions src/saba_wasabi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

extern crate alloc;

#[cfg_attr(target_os = "linux", no_main)]
use noli::prelude::*;
entry_point!(main);

use crate::alloc::string::ToString;
use alloc::format;
use alloc::rc::Rc;
Expand All @@ -17,7 +21,7 @@ use saba_core::http::HttpResponse;
use saba_core::url::HtmlUrl;
use ui_wasabi::app::WasabiUI;

fn handle_url(url: String) -> Result<HttpResponse, Error> {
fn handle_url(url: String) -> core::result::Result<HttpResponse, Error> {
// parse url
let parsed_url = match HtmlUrl::new(url.to_string()).parse() {
Ok(url) => url,
Expand Down Expand Up @@ -97,5 +101,3 @@ fn main() -> u64 {

0
}

entry_point!(main);
3 changes: 1 addition & 2 deletions ui/wasabi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
1 change: 1 addition & 0 deletions ui/wasabi/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions ui/wasabi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![no_std]

#[cfg_attr(target_os = "linux", no_main)]
use noli::prelude::*;

extern crate alloc;

pub mod app;
Expand Down
Loading