mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 06:45:32 +00:00
add getting WASI state for repl
This commit is contained in:
parent
7e1e94ecc3
commit
daa25d1021
@ -44,19 +44,19 @@ jobs:
|
|||||||
- checkout
|
- checkout
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- examples01-{{ checksum "examples/ipfs_node/wasm/ipfs_node/Cargo.toml" }}-{{ checksum "examples/ipfs_node/wasm/ipfs_rpc/Cargo.toml" }}-{{ checksum "examples/ipfs_node/Cargo.toml" }}
|
- examples01-{{ checksum "examples/ipfs_node/effector/Cargo.toml" }}-{{ checksum "examples/ipfs_node/pure/Cargo.toml" }}
|
||||||
- run: |
|
- run: |
|
||||||
rustup toolchain install nightly
|
rustup toolchain install nightly
|
||||||
rustup component add rustfmt
|
rustup component add rustfmt
|
||||||
rustup component add clippy
|
rustup component add clippy
|
||||||
cargo install cargo-wasi
|
cargo install cargo-wasi
|
||||||
|
|
||||||
cd examples/ipfs_node/wasm/ipfs_node
|
cd examples/ipfs_node/effector
|
||||||
cargo fmt --all -- --check --color always
|
cargo fmt --all -- --check --color always
|
||||||
cargo wasi build
|
cargo wasi build
|
||||||
cargo clippy -v --target wasm32-wasi
|
cargo clippy -v --target wasm32-wasi
|
||||||
|
|
||||||
cd ../ipfs_rpc
|
cd ../pure
|
||||||
cargo fmt --all -- --check --color always
|
cargo fmt --all -- --check --color always
|
||||||
cargo wasi build
|
cargo wasi build
|
||||||
cargo clippy -v --target wasm32-wasi
|
cargo clippy -v --target wasm32-wasi
|
||||||
|
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -457,6 +457,7 @@ dependencies = [
|
|||||||
"rustyline",
|
"rustyline",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"uuid",
|
"uuid",
|
||||||
|
"wasmer-wasi-fl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -508,6 +509,7 @@ dependencies = [
|
|||||||
"log",
|
"log",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"toml",
|
"toml",
|
||||||
|
"wasmer-wasi-fl",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -106,6 +106,20 @@ impl FCE {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn module_wasi_state<S: AsRef<str>>(
|
||||||
|
&mut self,
|
||||||
|
module_name: S,
|
||||||
|
) -> Result<&wasmer_wasi::state::WasiState> {
|
||||||
|
self.module_wasi_state_(module_name.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn module_wasi_state_(&mut self, module_name: &str) -> Result<&wasmer_wasi::state::WasiState> {
|
||||||
|
match self.modules.get_mut(module_name) {
|
||||||
|
Some(module) => Ok(module.get_wasi_state()),
|
||||||
|
None => Err(FCEError::NoSuchModule(module_name.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Return function signatures of all loaded info FCE modules with their names.
|
/// Return function signatures of all loaded info FCE modules with their names.
|
||||||
pub fn interface(&self) -> impl Iterator<Item = (&str, Vec<FCEFunctionSignature<'_>>)> {
|
pub fn interface(&self) -> impl Iterator<Item = (&str, Vec<FCEFunctionSignature<'_>>)> {
|
||||||
self.modules.iter().map(|(module_name, module)| {
|
self.modules.iter().map(|(module_name, module)| {
|
||||||
|
@ -154,6 +154,10 @@ impl FCEModule {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn get_wasi_state(&mut self) -> &wasmer_wasi::state::WasiState {
|
||||||
|
unsafe { wasmer_wasi::state::get_wasi_state(self.wasmer_instance.context_mut()) }
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: change the cloning Callable behaviour after changes of Wasmer API
|
// TODO: change the cloning Callable behaviour after changes of Wasmer API
|
||||||
pub(super) fn get_callable(&self, function_name: &str) -> Result<Arc<Callable>> {
|
pub(super) fn get_callable(&self, function_name: &str) -> Result<Arc<Callable>> {
|
||||||
match self.exports_funcs.get(function_name) {
|
match self.exports_funcs.get(function_name) {
|
||||||
|
@ -7,9 +7,10 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
fluence-faas = { path = "../fluence-faas" }
|
fluence-faas = { path = "../fluence-faas" }
|
||||||
|
|
||||||
toml = "0.5.6"
|
|
||||||
serde_json = "1.0.53"
|
|
||||||
log = "0.4.8"
|
log = "0.4.8"
|
||||||
|
serde_json = "1.0.53"
|
||||||
|
toml = "0.5.6"
|
||||||
|
wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.0" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
raw-module-api = ["fluence-faas/raw-module-api"]
|
raw-module-api = ["fluence-faas/raw-module-api"]
|
||||||
|
@ -197,4 +197,11 @@ impl AppService {
|
|||||||
pub fn unload_module<S: AsRef<str>>(&mut self, module_name: S) -> Result<()> {
|
pub fn unload_module<S: AsRef<str>>(&mut self, module_name: S) -> Result<()> {
|
||||||
self.faas.unload_module(module_name).map_err(Into::into)
|
self.faas.unload_module(module_name).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_wasi_state<S: AsRef<str>>(
|
||||||
|
&mut self,
|
||||||
|
module_name: S,
|
||||||
|
) -> Result<&wasmer_wasi::state::WasiState> {
|
||||||
|
self.faas.module_wasi_state(module_name).map_err(Into::into)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,4 +253,11 @@ impl FluenceFaaS {
|
|||||||
pub fn unload_module<S: AsRef<str>>(&mut self, module_name: S) -> Result<()> {
|
pub fn unload_module<S: AsRef<str>>(&mut self, module_name: S) -> Result<()> {
|
||||||
self.fce.unload_module(module_name).map_err(Into::into)
|
self.fce.unload_module(module_name).map_err(Into::into)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn module_wasi_state<S: AsRef<str>>(
|
||||||
|
&mut self,
|
||||||
|
module_name: S,
|
||||||
|
) -> Result<&wasmer_wasi::state::WasiState> {
|
||||||
|
self.fce.module_wasi_state(module_name).map_err(Into::into)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ fluence-app-service = { path = "../../fluence-app-service", features = ["raw-mod
|
|||||||
anyhow = "1.0.31"
|
anyhow = "1.0.31"
|
||||||
clap = "2.33.1"
|
clap = "2.33.1"
|
||||||
serde_json = "1.0.57"
|
serde_json = "1.0.57"
|
||||||
|
wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.0"}
|
||||||
|
|
||||||
rustyline = "6.1.2"
|
rustyline = "6.1.2"
|
||||||
rustop = "1.1.0"
|
rustop = "1.1.0"
|
||||||
|
@ -119,6 +119,20 @@ fn main() -> Result<(), anyhow::Error> {
|
|||||||
};
|
};
|
||||||
println!("{}", result);
|
println!("{}", result);
|
||||||
}
|
}
|
||||||
|
Some("envs") => {
|
||||||
|
next_argument!(module_name, args, "Module name should be specified");
|
||||||
|
match app_service.get_wasi_state(module_name) {
|
||||||
|
Ok(wasi_state) => print_envs(wasi_state),
|
||||||
|
Err(e) => println!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Some("fs") => {
|
||||||
|
next_argument!(module_name, args, "Module name should be specified");
|
||||||
|
match app_service.get_wasi_state(module_name) {
|
||||||
|
Ok(wasi_state) => print_fs_state(wasi_state),
|
||||||
|
Err(e) => println!("{}", e),
|
||||||
|
};
|
||||||
|
}
|
||||||
Some("interface") => {
|
Some("interface") => {
|
||||||
let interface = app_service.get_interface();
|
let interface = app_service.get_interface();
|
||||||
println!("application service interface:\n{}", interface);
|
println!("application service interface:\n{}", interface);
|
||||||
@ -131,6 +145,8 @@ fn main() -> Result<(), anyhow::Error> {
|
|||||||
unload <module_name> - to unload Wasm module from AppService\n\
|
unload <module_name> - to unload Wasm module from AppService\n\
|
||||||
call <module_name> <func_name> [args] - to call function with func_name of module with module_name\n\
|
call <module_name> <func_name> [args] - to call function with func_name of module with module_name\n\
|
||||||
interface - to print public interface of current AppService\n\
|
interface - to print public interface of current AppService\n\
|
||||||
|
envs <module_name> - to print environment variables of module with module_name\n\
|
||||||
|
fs <module_name> - to print filesystem state of module with module_name\n\
|
||||||
h/help - to print this message\n\
|
h/help - to print this message\n\
|
||||||
e/exit/q/quit - to exit"
|
e/exit/q/quit - to exit"
|
||||||
);
|
);
|
||||||
@ -172,3 +188,41 @@ fn create_service_from_config<S: Into<String>>(
|
|||||||
|
|
||||||
Ok(app_service)
|
Ok(app_service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_envs(wasi_state: &wasmer_wasi::state::WasiState) {
|
||||||
|
let envs = &wasi_state.envs;
|
||||||
|
|
||||||
|
println!("Environment variables:");
|
||||||
|
for env in envs.iter() {
|
||||||
|
match String::from_utf8(env.clone()) {
|
||||||
|
Ok(string) => println!("{}", string),
|
||||||
|
Err(_) => println!("{:?}", env),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_fs_state(wasi_state: &wasmer_wasi::state::WasiState) {
|
||||||
|
let wasi_fs = &wasi_state.fs;
|
||||||
|
|
||||||
|
println!("preopened file descriptors:\n{:?}\n", wasi_fs.preopen_fds);
|
||||||
|
|
||||||
|
println!("name map:");
|
||||||
|
for (name, inode) in &wasi_fs.name_map {
|
||||||
|
println!("{} - {:?}", name, inode);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("\nfile descriptors map:");
|
||||||
|
for (id, fd) in &wasi_fs.fd_map {
|
||||||
|
println!("{} - {:?}", id, fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("\norphan file descriptors:");
|
||||||
|
for (fd, inode) in &wasi_fs.orphan_fds {
|
||||||
|
println!("{:?} - {:?}", fd, inode);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("\ninodes:");
|
||||||
|
for (id, inode) in wasi_fs.inodes.iter().enumerate() {
|
||||||
|
println!("{}: {:?}", id, inode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user