Skip to content

Commit

Permalink
it builds again
Browse files Browse the repository at this point in the history
Signed-off-by: James Sturtevant <[email protected]>
  • Loading branch information
jsturtevant committed Aug 16, 2023
1 parent 9589c8b commit e075b6c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 65 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ ifeq ($(TARGET),release)
RELEASE_FLAG = --release
endif

FEATURES := libcontainer
FEATURES := --features libcontainer
WARNINGS := -D warnings
ifeq ($(OS), Windows_NT)
# need to turn off static/standalone for wasm-edge
FEATURES = --no-default-features
# turn of warnings until windows is fully supported
# turn of warnings until windows is fully supported #49
WARNINGS =
endif

Expand All @@ -26,7 +26,7 @@ KIND_CLUSTER_NAME ?= containerd-wasm
.PHONY: build
build:
cargo build -p containerd-shim-wasm --features generate_bindings $(RELEASE_FLAG)
cargo build -p containerd-shim-wasm --features $(FEATURES) libcontainer $(RELEASE_FLAG)
cargo build -p containerd-shim-wasm $(FEATURES) $(RELEASE_FLAG)
cargo build $(FEATURES) $(RELEASE_FLAG)

.PHONY: check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(unix)]
use crate::sandbox::oci;
use libcontainer::workload::default::DefaultExecutor;
use libcontainer::workload::{Executor, ExecutorError};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(unix)]
//! Abstractions for running/managing a wasm/wasi instance that uses youki's libcontainer library.
use anyhow::Context;
Expand Down
2 changes: 2 additions & 0 deletions crates/containerd-shim-wasm/src/libcontainer_instance/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(unix)]

pub mod container_executor;
pub mod instance;

Expand Down
2 changes: 0 additions & 2 deletions crates/containerd-shim-wasm/src/sandbox/instance_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::{
path::{Path, PathBuf},
};

use cap_std::fs::File;

/// Return the root path for the instance.
///
/// The root path is the path to the directory containing the container's state.
Expand Down
78 changes: 37 additions & 41 deletions crates/containerd-shim-wasmedge/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@

use anyhow::Result;
use containerd_shim_wasm::libcontainer_instance::LibcontainerInstance;
use containerd_shim_wasm::libcontainer_instance::LinuxContainerExecutor;
use containerd_shim_wasm::sandbox::error::Error;
use containerd_shim_wasm::sandbox::instance::ExitCode;
use containerd_shim_wasm::sandbox::instance_utils::maybe_open_stdio;
use containerd_shim_wasm::sandbox::{EngineGetter, InstanceConfig};
use nix::unistd::close;

use serde::{Deserialize, Serialize};
use std::fs::File;
use std::io::prelude::*;
use std::io::ErrorKind;
use std::os::fd::IntoRawFd;
use std::sync::{Arc, Condvar, Mutex};
use std::sync::{Arc, Condvar, Mutex};
use std::thread;

use anyhow::Context;
use anyhow::{anyhow, Result};
use chrono::{DateTime, Utc};
use containerd_shim_wasm::cfg_unix;
use containerd_shim_wasm::sandbox::error::Error;
use containerd_shim_wasm::sandbox::instance::Wait;
use containerd_shim_wasm::sandbox::instance_utils::{
get_instance_root, instance_exists, maybe_open_stdio,
Expand All @@ -29,7 +20,6 @@ use containerd_shim_wasm::sandbox::{EngineGetter, Instance, InstanceConfig};

use log::{debug, error};

use serde::{Deserialize, Serialize};
use wasmedge_sdk::{
config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions},
plugin::PluginManager,
Expand All @@ -39,6 +29,8 @@ use wasmedge_sdk::{
cfg_unix! {
use libcontainer::container::builder::ContainerBuilder;
use libcontainer::container::{Container, ContainerStatus};
use containerd_shim_wasm::libcontainer_instance::LibcontainerInstance;
use containerd_shim_wasm::libcontainer_instance::LinuxContainerExecutor;
use libcontainer::signal::Signal;
use libcontainer::syscall::syscall::create_syscall;

Expand All @@ -50,19 +42,17 @@ cfg_unix! {
use nix::sys::wait::{waitid, Id as WaitID, WaitPidFlag, WaitStatus};
use nix::unistd::close;
use std::os::fd::IntoRawFd;
use libcontainer::container::builder::ContainerBuilder;
use libcontainer::container::Container;
use libcontainer::syscall::syscall::create_syscall;
use crate::executor::WasmEdgeExecutor;
}

use std::{
fs,
path::{Path, PathBuf},
};

use libcontainer::container::builder::ContainerBuilder;
use libcontainer::container::Container;
use libcontainer::syscall::syscall::create_syscall;

use crate::executor::WasmEdgeExecutor;

static DEFAULT_CONTAINER_ROOT_DIR: &str = "/run/containerd/wasmedge";

pub struct Wasi {
Expand Down Expand Up @@ -102,6 +92,32 @@ fn determine_rootdir<P: AsRef<Path>>(bundle: P, namespace: String) -> Result<Pat
.join(namespace))
}

#[cfg(windows)]
impl Instance for Wasi {
type E = Vm;

fn new(id: String, cfg: Option<&InstanceConfig<Self::E>>) -> Self {
todo!()
}

fn start(&self) -> std::result::Result<u32, Error> {
todo!()
}

fn kill(&self, signal: u32) -> std::result::Result<(), Error> {
todo!()
}

fn delete(&self) -> std::result::Result<(), Error> {
todo!()
}

fn wait(&self, waiter: &Wait) -> std::result::Result<(), Error> {
todo!()
}
}

#[cfg(unix)]
impl LibcontainerInstance for Wasi {
type E = Vm;

Expand Down Expand Up @@ -196,8 +212,7 @@ impl EngineGetter for Wasi {
mod wasitest {
use std::borrow::Cow;
use std::fs::{create_dir, read_to_string, File, OpenOptions};
use std::os::unix::io::RawFd;
use std::os::unix::prelude::OpenOptionsExt;

use std::sync::mpsc::channel;
use std::time::Duration;

Expand All @@ -206,14 +221,15 @@ mod wasitest {
use containerd_shim_wasm::sandbox::instance::Wait;
use containerd_shim_wasm::sandbox::testutil::{has_cap_sys_admin, run_test_with_sudo};
use containerd_shim_wasm::sandbox::Instance;
use libc::{dup2, SIGKILL, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
use oci_spec::runtime::{ProcessBuilder, RootBuilder, SpecBuilder};
use tempfile::{tempdir, TempDir};

cfg_unix!(
use libc::{dup2, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
use std::os::unix::prelude::OpenOptionsExt;
use std::os::fd::RawFd;
use std::os::unix::io::RawFd;
use std::os::unix::prelude::OpenOptionsExt;
);

use serial_test::serial;
Expand All @@ -229,33 +245,13 @@ mod wasitest {
#[cfg(windows)]
const SIGKILL: u32 = 9;

pub fn reset_stdio() {
#[cfg(unix)]
{
unsafe {
if STDIN_FD.is_some() {
dup2(STDIN_FD.unwrap(), STDIN_FILENO);
}
if STDOUT_FD.is_some() {
dup2(STDOUT_FD.unwrap(), STDOUT_FILENO);
}
if STDERR_FD.is_some() {
dup2(STDERR_FD.unwrap(), STDERR_FILENO);
}
}
}
}

use wasmedge_sdk::{
config::{CommonConfigOptions, ConfigBuilder},
wat2wasm,
};

static mut STDIN_FD: Option<RawFd> = None;
static mut STDOUT_FD: Option<RawFd> = None;
static mut STDERR_FD: Option<RawFd> = None;

fn reset_stdio() {
#[cfg(unix)]
unsafe {
if let Some(stdin) = STDIN_FD {
let _ = dup2(stdin, STDIN_FILENO);
Expand Down
53 changes: 34 additions & 19 deletions crates/containerd-shim-wasmtime/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use anyhow::Result;
use libcontainer::container::builder::ContainerBuilder;
use libcontainer::container::Container;
use nix::unistd::close;
use serde::{Deserialize, Serialize};
use std::fs::File;

Expand All @@ -13,6 +10,7 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, Condvar, Mutex};

cfg_unix! {
use containerd_shim_wasm::libcontainer_instance::{LibcontainerInstance, LinuxContainerExecutor};
use libcontainer::container::builder::ContainerBuilder;
use libcontainer::container::{Container, ContainerStatus};
use libcontainer::syscall::syscall::create_syscall;
Expand All @@ -25,21 +23,17 @@ cfg_unix! {
};
use crate::executor::WasmtimeExecutor;
use std::os::fd::IntoRawFd;

}

use anyhow::Context;
use containerd_shim_wasm::libcontainer_instance::{LibcontainerInstance, LinuxContainerExecutor};
use containerd_shim_wasm::sandbox::error::Error;
use containerd_shim_wasm::sandbox::instance::ExitCode;
use containerd_shim_wasm::sandbox::instance_utils::maybe_open_stdio;
use containerd_shim_wasm::sandbox::{EngineGetter, InstanceConfig};
use libcontainer::syscall::syscall::create_syscall;
use std::os::fd::IntoRawFd;
use containerd_shim_wasm::sandbox::{EngineGetter, Instance, InstanceConfig};

use wasmtime::Engine;

use crate::executor::WasmtimeExecutor;

static DEFAULT_CONTAINER_ROOT_DIR: &str = "/run/containerd/wasmtime";

pub struct Wasi {
Expand Down Expand Up @@ -83,6 +77,35 @@ fn determine_rootdir<P: AsRef<Path>>(bundle: P, namespace: String) -> Result<Pat
Ok(path)
}

#[cfg(windows)]
impl Instance for Wasi {
type E = wasmtime::Engine;

fn new(id: String, cfg: Option<&InstanceConfig<Self::E>>) -> Self {
todo!()
}

fn start(&self) -> std::result::Result<u32, Error> {
todo!()
}

fn kill(&self, signal: u32) -> std::result::Result<(), Error> {
todo!()
}

fn delete(&self) -> std::result::Result<(), Error> {
todo!()
}

fn wait(
&self,
waiter: &containerd_shim_wasm::sandbox::instance::Wait,
) -> std::result::Result<(), Error> {
todo!()
}
}

#[cfg(unix)]
impl LibcontainerInstance for Wasi {
type E = wasmtime::Engine;

Expand Down Expand Up @@ -166,8 +189,6 @@ mod wasitest {
use std::borrow::Cow;
use std::fs::{create_dir, read_to_string, File, OpenOptions};
use std::io::prelude::*;
use std::os::fd::RawFd;
use std::os::unix::prelude::OpenOptionsExt;
use std::sync::mpsc::channel;
use std::time::Duration;

Expand All @@ -176,9 +197,6 @@ mod wasitest {
use containerd_shim_wasm::sandbox::instance::Wait;
use containerd_shim_wasm::sandbox::testutil::{has_cap_sys_admin, run_test_with_sudo};
use containerd_shim_wasm::sandbox::Instance;
use libc::SIGKILL;
use libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
use nix::unistd::dup2;
use oci_spec::runtime::{ProcessBuilder, RootBuilder, SpecBuilder};
use tempfile::{tempdir, TempDir};

Expand All @@ -200,11 +218,8 @@ mod wasitest {

use super::*;

static mut STDIN_FD: Option<RawFd> = None;
static mut STDOUT_FD: Option<RawFd> = None;
static mut STDERR_FD: Option<RawFd> = None;

fn reset_stdio() {
#[cfg(unix)]
unsafe {
if let Some(stdin) = STDIN_FD {
let _ = dup2(stdin, STDIN_FILENO);
Expand Down Expand Up @@ -343,7 +358,7 @@ mod wasitest {
#[cfg(unix)]
f.mode(0o755);
let mut f = f.open(wasm_path)?;
f.write_all(WASI_HELLO_WAT)?;
f.write_all(&wasmbytes)?;

let stdout = File::create(dir.path().join("stdout"))?;
drop(stdout);
Expand Down

0 comments on commit e075b6c

Please sign in to comment.