-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Xila-Project/Feature/WASM
Feature/wasm
- Loading branch information
Showing
74 changed files
with
2,220 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#![allow(non_snake_case)] | ||
use std::{env, process::Command}; | ||
|
||
fn main() -> Result<(), ()> { | ||
println!("cargo:rerun-if-changed=Tests/WASM_test/src/main.rs"); | ||
println!("cargo:rerun-if-changed=Tests/WASM_test/Cargo.toml"); | ||
|
||
// TODO : Add a check for test mode | ||
|
||
if env::var("RUSTUP_TOOLCHAIN").unwrap().contains("esp") { | ||
println!("cargo:warning=Build of WASM tests are disabled for esp toolchain."); | ||
return Ok(()); | ||
} | ||
|
||
let output = Command::new("cargo") | ||
.args(["build", "--release"]) | ||
.current_dir("Tests/WASM_test") | ||
.output() | ||
.unwrap(); | ||
|
||
if !output.status.success() { | ||
println! {"cargo:warning=stderr: {}", String::from_utf8_lossy(&output.stderr)}; | ||
println! {"cargo:warning=status: {}", output.status}; | ||
return Err(()); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "Bindings" | ||
version = "0.1.0" | ||
edition = "2021" | ||
build = "Build.rs" | ||
|
||
[dependencies] | ||
File_system = { path = "../File_system" } | ||
Virtual_machine = { path = "../Virtual_machine" } | ||
Binding_tool = { path = "../../../Binding_tool", features = ["Native"] } | ||
Shared = { path = "../Shared" } | ||
|
||
[[test]] | ||
name = "File_system_bindings_tests" | ||
path = "Tests/File_system.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![allow(non_snake_case)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(non_upper_case_globals)] | ||
|
||
use Bindings::File_system_bindings; | ||
use File_system::{Drivers::Native::File_system_type, Prelude::File_system_traits}; | ||
use Virtual_machine::{Data_type, Instantiate_test_environment, WasmValue}; | ||
|
||
#[test] | ||
fn Integration_test() { | ||
let Binary_buffer = include_bytes!( | ||
"../../../target/wasm32-unknown-unknown/release/File_system_bindings_WASM_test.wasm" | ||
); | ||
|
||
let mut Native_file_system = File_system_type::New(); | ||
|
||
Native_file_system.Initialize().unwrap(); | ||
|
||
let User_data = Data_type::New(&Native_file_system); | ||
|
||
let (_Runtime, _Module, Instance) = | ||
Instantiate_test_environment(Binary_buffer, File_system_bindings {}, &User_data); | ||
|
||
assert_eq!(Instance.Call_main(&vec![]).unwrap(), WasmValue::I32(0)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[build] | ||
target = "wasm32-unknown-unknown" | ||
rustflags = [ | ||
"-C", "link-arg=--initial-memory=65536", | ||
"-C", "link-arg=-zstack-size=8192", | ||
"-C", "link-arg=--export=__heap_base", | ||
"-C", "link-arg=--export=__data_end", | ||
"-C", "link-arg=--strip-all", | ||
"-C", "lto=yes", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "File_system_bindings_WASM_test" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
Binding_tool = { path = "../../../../../Binding_tool", features = ["WASM"] } | ||
wee_alloc = "0.4.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#![allow(non_snake_case)] | ||
|
||
use Binding_tool::Bind_function_WASM; | ||
|
||
#[Bind_function_WASM] | ||
fn Open_file(Path: &str, Mode: u32, File_identifier: &mut u16) -> u32 {} | ||
|
||
#[Bind_function_WASM] | ||
fn Read_file(File_identifier: u16, Buffer: &mut [u8], Read_size: &mut u32) -> u32 {} | ||
|
||
extern crate wee_alloc; | ||
|
||
// Use `wee_alloc` as the global allocator saving kilobytes of code size | ||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
fn main() -> Result<(), ()> { | ||
let mut File_identifier = 1; | ||
|
||
let Result = Open_file("test.txt", 1, &mut File_identifier); | ||
|
||
if Result != 0 { | ||
return Err(()); | ||
} | ||
|
||
let mut Buffer = [0; 1024]; | ||
|
||
let mut Read_size = 0; | ||
|
||
let Result = Read_file(File_identifier, &mut Buffer, &mut Read_size); | ||
|
||
if Result != 0 { | ||
return Err(()); | ||
} | ||
|
||
let String = String::from_utf8_lossy(&Buffer[..Read_size as usize]); | ||
|
||
if String != "Hello World!" { | ||
return Err(()); | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello World! |
Oops, something went wrong.