Implement OSDK functionalities and opt-in OSDK for asterinas

This commit is contained in:
Zhang Junyang
2024-02-21 16:58:40 +08:00
committed by Tate, Hongliang Tian
parent bc9bce9dea
commit f97d0f1260
103 changed files with 1663 additions and 1295 deletions

View File

@ -5,8 +5,6 @@
use core::ops::Mul;
use ktest::if_cfg_ktest;
/// A `Coeff` is used to do a fraction multiplication operation with an unsigned integer.
/// It can achieve accurate and efficient calculation and avoid numeric overflow at the same time.
///
@ -127,7 +125,7 @@ impl Mul<u32> for Coeff {
}
}
#[if_cfg_ktest]
#[cfg(ktest)]
mod test {
use ktest::ktest;

View File

@ -1,2 +1,2 @@
[workspace]
members = ["foo", "bar"]
members = ["foo1", "bar1"]

View File

@ -1,10 +1,10 @@
[components]
foo = { name = "foo" }
bar = { name = "bar" }
foo1 = { name = "foo1" }
bar1 = { name = "bar1" }
[whitelist]
[whitelist.foo.foo_add]
bar = true
[whitelist.foo1.foo_add]
bar1 = true
[whitelist.foo.FOO_ITEM]
bar = true
[whitelist.foo1.FOO_ITEM]
bar1 = true

View File

@ -1,5 +0,0 @@
pub static BAR: &'static usize = &foo::FOO_ITEM;
pub fn add(left: usize, right: usize) -> usize {
foo::foo_add(left, right)
}

View File

@ -1,9 +1,9 @@
[package]
name = "bar"
name = "bar1"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
foo = {path = "../foo"}
foo1 = {path = "../foo1"}

View File

@ -0,0 +1,5 @@
pub static BAR: &'static usize = &foo1::FOO_ITEM;
pub fn add(left: usize, right: usize) -> usize {
foo1::foo_add(left, right)
}

View File

@ -11,7 +11,7 @@ mod test_utils;
fn trait_method() {
let stderr = run_cargo_component_cmd!();
assert!(stderr.contains("access controlled entry point is disallowed"));
assert!(stderr.contains("access foo::Foo::method in bar"));
assert!(stderr.contains("access foo::FooTrait::trait_associate_fn in bar"));
assert!(stderr.contains("access foo::FooTrait::trait_method in bar"));
assert!(stderr.contains("access foo2::Foo::method in bar2"));
assert!(stderr.contains("access foo2::FooTrait::trait_associate_fn in bar2"));
assert!(stderr.contains("access foo2::FooTrait::trait_method in bar2"));
}

View File

@ -1,2 +1,2 @@
[workspace]
members = ["foo", "bar"]
members = ["foo2", "bar2"]

View File

@ -1,19 +1,19 @@
[components]
foo = { name = "foo" }
bar = { name = "bar" }
foo2 = { name = "foo2" }
bar2 = { name = "bar2" }
[whitelist]
[whitelist.foo.FooTrait.trait_method]
bar = false
[whitelist.foo2.FooTrait.trait_method]
bar2 = false
[whitelist.foo.FooTrait.trait_associate_fn]
bar = false
[whitelist.foo2.FooTrait.trait_associate_fn]
bar2 = false
[whitelist.foo.Foo.method]
bar = false
[whitelist.foo2.Foo.method]
bar2 = false
[whitelist.foo.ObjectSafeTrait.get]
bar = true
[whitelist.foo2.ObjectSafeTrait.get]
bar2 = true
[whitelist.foo.Foo.associate_fn]
bar = true
[whitelist.foo2.Foo.associate_fn]
bar2 = true

View File

@ -1,9 +1,9 @@
[package]
name = "bar"
name = "bar2"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
foo = {path = "../foo"}
foo2 = {path = "../foo2"}

View File

@ -1,4 +1,4 @@
use foo::{ObjectSafeTrait, Foo, FooTrait};
use foo2::{ObjectSafeTrait, Foo, FooTrait};
pub fn method() {
let foo_struct = Foo::associate_fn();

View File

@ -12,6 +12,6 @@ mod test_utils;
fn violate_policy() {
let stderr = run_cargo_component_cmd!();
assert!(stderr.contains("access controlled entry point is disallowed"));
assert!(stderr.contains("access foo::foo_add in bar"));
assert!(stderr.contains("access foo::FOO_ITEM in bar"));
assert!(stderr.contains("access foo3::foo_add in bar3"));
assert!(stderr.contains("access foo3::FOO_ITEM in bar3"));
}

View File

@ -1,2 +1,2 @@
[workspace]
members = ["foo", "bar"]
members = ["foo3", "bar3"]

View File

@ -1,5 +1,5 @@
[components]
foo = { name = "foo" }
bar = { name = "bar" }
foo3 = { name = "foo3" }
bar3 = { name = "bar3" }
[whitelist]

View File

@ -1,5 +0,0 @@
pub static BAR: &'static usize = &foo::FOO_ITEM;
pub fn add(left: usize, right: usize) -> usize {
foo::foo_add(left, right)
}

View File

@ -1,9 +1,9 @@
[package]
name = "bar"
name = "bar3"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
foo = {path = "../foo"}
foo3 = {path = "../foo3"}

View File

@ -0,0 +1,5 @@
pub static BAR: &'static usize = &foo3::FOO_ITEM;
pub fn add(left: usize, right: usize) -> usize {
foo3::foo_add(left, right)
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use std::{collections::HashMap, fs::File, io::Read, ops::Add, process::Command, str::FromStr};
use std::{collections::HashMap, fs::File, io::Read, ops::Add, path::PathBuf, process::Command, str::FromStr};
use json::JsonValue;
use proc_macro2::{Group, TokenStream};
@ -11,6 +11,7 @@ use crate::COMPONENT_FILE_NAME;
#[derive(Debug)]
pub struct ComponentInfo {
name: String,
/// The absolute path to the component
path: String,
priority: u16,
}
@ -87,13 +88,14 @@ pub fn component_generate() -> Vec<ComponentInfo> {
};
let component_info = ComponentInfo {
name: package["name"].as_str().unwrap().to_string(),
path: path.to_owned(),
path: PathBuf::from(&workspace_root).join(path).to_str().unwrap().to_string(),
priority: *mapping
.get(&package["name"].as_str().unwrap().to_string())
.unwrap(),
};
components_info.push(component_info)
}
components_info
}