Skip to content
Permalink
Browse files

start of container orchestration

  • Loading branch information
syntacticsugarglider committed Nov 8, 2019
1 parent 5da2e84 commit a781c566b1cba6af4b710fdf0b58785904cf82ac
@@ -2,3 +2,5 @@
**/*.rs.bk
Cargo.lock
*.js
*.ts
*.wasm
@@ -5,13 +5,13 @@ authors = ["Izzy Swart <zenerboson@gmail.com>"]
edition = "2018"

[workspace]
members = [".", "./derive"]
members = [".", "./derive", "examples/core_test"]

[features]
cbor = ["serde_cbor"]
json = ["serde_json"]
bincode = ["serde_bincode"]
core = ["wasm-bindgen", "web-sys", "wasmer-runtime", "derive/core", "js-sys"]
core = ["wasm-bindgen", "web-sys", "wasmer-runtime", "derive/core", "js-sys", "wasm-bindgen-futures"]
default = ["cbor"]

[dependencies]
@@ -28,9 +28,10 @@ void = "1.0.2"
downcast-rs = "1.1.1"

[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = { version = "0.2.53", optional = true }
web-sys = { version = "0.3.30", optional = true }
js-sys = {version = "0.3.30", optional = true }
wasm-bindgen = { version = "0.2.54", optional = true }
web-sys = { version = "0.3.30", optional = true, features = ["console"] }
js-sys = { version = "0.3.30", optional = true }
wasm-bindgen-futures = { version = "0.4.4", optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
wasmer-runtime = { version = "0.9.0", optional = true }
@@ -39,7 +39,7 @@ pub fn build(block: TokenStream) -> TokenStream {
}
#[cfg(target_arch = "wasm32")]
#[no_mangle]
pub extern "C" fn initialize() {
pub extern "C" fn _EXPORT_initialize() {
let _export_initializer: fn() -> _ = || {
#block
};
@@ -0,0 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
@@ -0,0 +1,18 @@
[package]
name = "core_test"
version = "0.1.0"
authors = ["Izzy Swart <zenerboson@gmail.com>"]
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2.54"
vessels = { path = "../../", features = ["core"] }
futures-preview = { version = "=0.3.0-alpha.19", features = ["async-await"] }
js-sys = "0.3.31"

[dependencies.web-sys]
version = "0.3.4"
features = ["console"]
@@ -0,0 +1,27 @@
use vessels::{
channel::IdChannel,
core,
core::{
executor::Spawn,
orchestrator::containers::{web::WebContainers, Containers},
Executor,
},
format::{ApplyDecode, Cbor},
};
use wasm_bindgen::prelude::*;
use web_sys::console::log_1;

const WASM_DATA: &'static [u8] =
include_bytes!("../../../target/wasm32-unknown-unknown/debug/examples/test_vessel.wasm");

#[wasm_bindgen(start)]
pub fn main() {
let mut executor = core::<dyn Executor>().unwrap();
executor.spawn(async move {
let mut containers = WebContainers;
let module = containers.compile(WASM_DATA).await;
let instance = containers.instantiate(&module).await;
let data: String = instance.decode::<IdChannel, Cbor>().await.unwrap();
log_1(&format!("{}", data).into());
});
}
@@ -0,0 +1,5 @@
use vessels::export;

export! {
"test".to_string()
}
@@ -2,7 +2,15 @@
<html>

<body>
<script src="vessels.js"></script>
<script type="module">
import init from './core_test.js';

async function run() {
await init();
}

run();
</script>
</body>

</html>
@@ -145,7 +145,7 @@ pub struct Shim<K: Kind> {
}

impl<'a, K: Kind> IShim<'a, IdChannel, K> for Shim<K> {
fn complete<C: Stream<Item = Item> + Sink<Item> + Send + 'static>(
fn complete<C: Stream<Item = Item> + Sink<Item> + 'static>(
self,
input: C,
) -> BoxFuture<'static, Result<K, K::ConstructError>> {
@@ -36,7 +36,7 @@ pub trait Shim<'a, T: Target<'a, K>, K: Kind>:
Context<'a, Item = <T as Context<'a>>::Item>
{
fn complete<
C: Stream<Item = <T as Context<'a>>::Item> + Sink<<T as Context<'a>>::Item> + Send + 'static,
C: Stream<Item = <T as Context<'a>>::Item> + Sink<<T as Context<'a>>::Item> + 'static,
>(
self,
input: C,
@@ -1,28 +1,27 @@
use futures::{future::BoxFuture, Future};
use futures::{future::LocalBoxFuture, Future};

pub trait Executor: Send {
fn spawn_boxed(&mut self, fut: BoxFuture<'static, ()>);
pub trait Executor {
fn spawn_boxed(&mut self, fut: LocalBoxFuture<'static, ()>);
}

pub trait Spawn {
fn spawn<F: Send + 'static + Future<Output = ()>>(&mut self, future: F);
fn spawn<F: 'static + Future<Output = ()>>(&mut self, future: F);
}

impl Spawn for Box<dyn Executor> {
fn spawn<F: Send + 'static + Future<Output = ()>>(&mut self, future: F) {
fn spawn<F: 'static + Future<Output = ()>>(&mut self, future: F) {
self.spawn_boxed(Box::pin(future));
}
}

#[cfg(target_arch = "wasm32")]
mod web_sequential;

#[cfg(not(target_arch = "wasm32"))]
mod native;

pub(crate) fn new_executor() -> Result<Box<dyn Executor>, super::UnimplementedError> {
#[cfg(target_arch = "wasm32")]
return Ok(Box::new(web_sequential::Spawner::new()));
#[cfg(not(target_arch = "wasm32"))]
return Ok(Box::new(native::Spawner::new()));
return Err(super::UnimplementedError {
feature: "sequential future execution".to_owned(),
});
}

This file was deleted.

@@ -1,12 +1,12 @@
mod queue;
mod task;
use super::Executor;
use futures::future::BoxFuture;
use futures::future::LocalBoxFuture;

pub(crate) struct Spawner;

impl Executor for Spawner {
fn spawn_boxed(&mut self, future: BoxFuture<'static, ()>) {
fn spawn_boxed(&mut self, future: LocalBoxFuture<'static, ()>) {
task::Task::spawn(future)
}
}
@@ -7,6 +7,8 @@ use std::{
pub mod executor;
pub use executor::Executor;

pub mod orchestrator;

#[derive(Fail, Debug)]
#[fail(display = "{} is unimplemented on this target", feature)]
pub struct UnimplementedError {
@@ -0,0 +1,14 @@
use futures::{future::LocalBoxFuture, Sink, Stream};

#[cfg(target_arch = "wasm32")]
pub mod web;

pub trait Instance: Stream<Item = Vec<u8>> + Sink<Vec<u8>> {}

pub trait Containers {
type Module;
type Instance: Instance;

fn compile<T: AsRef<[u8]>>(&mut self, data: T) -> LocalBoxFuture<'static, Self::Module>;
fn instantiate(&mut self, module: &Self::Module) -> LocalBoxFuture<'static, Self::Instance>;
}

0 comments on commit a781c56

Please sign in to comment.
You can’t perform that action at this time.