diff --git a/crates/containerd-shim-wasm/src/lib.rs b/crates/containerd-shim-wasm/src/lib.rs index ba3a2058f..84b78b09f 100644 --- a/crates/containerd-shim-wasm/src/lib.rs +++ b/crates/containerd-shim-wasm/src/lib.rs @@ -4,9 +4,9 @@ )] pub mod sandbox; - -mod macros; pub mod services; +#[cfg_attr(unix, path = "sys/unix.rs")] +#[cfg_attr(windows, path = "sys/windows.rs")] pub mod sys; #[cfg(all(feature = "libcontainer", not(target_os = "windows")))] diff --git a/crates/containerd-shim-wasm/src/macros.rs b/crates/containerd-shim-wasm/src/macros.rs deleted file mode 100644 index 74903abf0..000000000 --- a/crates/containerd-shim-wasm/src/macros.rs +++ /dev/null @@ -1,19 +0,0 @@ -#[macro_export] -macro_rules! cfg_windows { - ($($item:item)*) => { - $( - #[cfg(windows)] - $item - )* - } -} - -#[macro_export] -macro_rules! cfg_unix { - ($($item:item)*) => { - $( - #[cfg(unix)] - $item - )* - } -} diff --git a/crates/containerd-shim-wasm/src/sandbox/manager.rs b/crates/containerd-shim-wasm/src/sandbox/manager.rs index 10fd5a423..5f5097f9d 100644 --- a/crates/containerd-shim-wasm/src/sandbox/manager.rs +++ b/crates/containerd-shim-wasm/src/sandbox/manager.rs @@ -23,7 +23,7 @@ use super::error::Error; use super::instance::Instance; use super::{oci, sandbox}; use crate::services::sandbox_ttrpc::{Manager, ManagerClient}; -use crate::sys::networking::setup_namespaces; +use crate::sys::setup_namespaces; /// Sandbox wraps an Instance and is used with the `Service` to manage multiple instances. pub trait Sandbox: Task + Send + Sync { diff --git a/crates/containerd-shim-wasm/src/sandbox/shim.rs b/crates/containerd-shim-wasm/src/sandbox/shim.rs index b61c43f36..5713098a6 100644 --- a/crates/containerd-shim-wasm/src/sandbox/shim.rs +++ b/crates/containerd-shim-wasm/src/sandbox/shim.rs @@ -6,6 +6,8 @@ use std::collections::HashMap; use std::env::current_dir; use std::fs::{self, canonicalize, create_dir_all, DirBuilder, File, OpenOptions}; use std::ops::Not; +#[cfg(unix)] +use std::os::unix::fs::DirBuilderExt; use std::path::Path; use std::sync::mpsc::{channel, Receiver, Sender}; use std::sync::{Arc, Condvar, Mutex, RwLock}; @@ -14,6 +16,8 @@ use std::thread; use chrono::{DateTime, Utc}; use containerd_shim::error::Error as ShimError; use containerd_shim::event::Event; +#[cfg(unix)] +use containerd_shim::mount::mount_rootfs; use containerd_shim::protos::events::task::{TaskCreate, TaskDelete, TaskExit, TaskIO, TaskStart}; use containerd_shim::protos::protobuf::well_known_types::timestamp::Timestamp; use containerd_shim::protos::protobuf::{MessageDyn, MessageField}; @@ -23,23 +27,16 @@ use containerd_shim::publisher::RemotePublisher; use containerd_shim::util::{timestamp as new_timestamp, write_address, IntoOption}; use containerd_shim::{self as shim, api, warn, ExitSignal, TtrpcContext, TtrpcResult}; use log::{debug, error}; +#[cfg(unix)] +use nix::mount::{mount, MsFlags}; use oci_spec::runtime; use shim::api::{StatsRequest, StatsResponse}; +use shim::Flags; +use ttrpc::context::Context; use super::instance::{Instance, InstanceConfig, Nop, Wait}; use super::{oci, Error, SandboxService}; -use crate::cfg_unix; -use crate::sys::metrics::get_metrics; -use crate::sys::networking::setup_namespaces; - -cfg_unix! { - use containerd_shim::mount::mount_rootfs; - use nix::mount::{mount, MsFlags}; - use std::os::unix::fs::DirBuilderExt; -} - -use shim::Flags; -use ttrpc::context::Context; +use crate::sys::{get_metrics, setup_namespaces}; type InstanceDataStatus = (Mutex)>>, Condvar); diff --git a/crates/containerd-shim-wasm/src/sys/mod.rs b/crates/containerd-shim-wasm/src/sys/mod.rs deleted file mode 100644 index 147022203..000000000 --- a/crates/containerd-shim-wasm/src/sys/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -#[cfg(unix)] -mod unix; -#[cfg(windows)] -mod windows; - -pub mod metrics { - #[cfg(unix)] - pub use crate::sys::unix::get_metrics; - #[cfg(windows)] - pub use crate::sys::windows::get_metrics; -} - -pub mod networking { - #[cfg(unix)] - pub use crate::sys::unix::setup_namespaces; - #[cfg(windows)] - pub use crate::sys::windows::setup_namespaces; -} diff --git a/crates/containerd-shim-wasmedge/src/instance.rs b/crates/containerd-shim-wasmedge/src/instance.rs deleted file mode 100644 index 3bfd656b5..000000000 --- a/crates/containerd-shim-wasmedge/src/instance.rs +++ /dev/null @@ -1,11 +0,0 @@ -use containerd_shim_wasm::{cfg_unix, cfg_windows}; - -cfg_unix! { - pub mod instance_linux; - pub use instance_linux::Wasi; -} - -cfg_windows! { - pub mod instance_windows; - pub use instance_windows::Wasi; -} diff --git a/crates/containerd-shim-wasmedge/src/instance/instance_linux.rs b/crates/containerd-shim-wasmedge/src/instance/instance_linux.rs index 4b26d0a0c..c230b571f 100644 --- a/crates/containerd-shim-wasmedge/src/instance/instance_linux.rs +++ b/crates/containerd-shim-wasmedge/src/instance/instance_linux.rs @@ -369,4 +369,4 @@ mod rootdirtest { ); Ok(()) } -} \ No newline at end of file +} diff --git a/crates/containerd-shim-wasmedge/src/instance/instance_windows.rs b/crates/containerd-shim-wasmedge/src/instance/instance_windows.rs index 75c91506f..ce36b6146 100644 --- a/crates/containerd-shim-wasmedge/src/instance/instance_windows.rs +++ b/crates/containerd-shim-wasmedge/src/instance/instance_windows.rs @@ -1,10 +1,10 @@ use std::path::PathBuf; use std::process::ExitCode; -use containerd_shim_wasm::sandbox::{Instance, InstanceConfig}; +use containerd_shim_wasm::sandbox::error::Error; use containerd_shim_wasm::sandbox::instance::Wait; +use containerd_shim_wasm::sandbox::{Instance, InstanceConfig}; use wasmedge_sdk::Vm; -use containerd_shim_wasm::sandbox::error::Error; pub struct Wasi { id: String, @@ -41,4 +41,4 @@ impl Instance for Wasi { fn wait(&self, waiter: &Wait) -> std::result::Result<(), Error> { todo!() } -} \ No newline at end of file +} diff --git a/crates/containerd-shim-wasmedge/src/lib.rs b/crates/containerd-shim-wasmedge/src/lib.rs index 4247aa64c..5e92dcfb8 100644 --- a/crates/containerd-shim-wasmedge/src/lib.rs +++ b/crates/containerd-shim-wasmedge/src/lib.rs @@ -1,5 +1,7 @@ pub mod error; +#[cfg_attr(unix, path = "instance/instance_linux.rs")] +#[cfg_attr(windows, path = "instance/instance_windows.rs")] pub mod instance; pub mod oci_utils; diff --git a/crates/containerd-shim-wasmtime/src/instance.rs b/crates/containerd-shim-wasmtime/src/instance.rs deleted file mode 100644 index 3bfd656b5..000000000 --- a/crates/containerd-shim-wasmtime/src/instance.rs +++ /dev/null @@ -1,11 +0,0 @@ -use containerd_shim_wasm::{cfg_unix, cfg_windows}; - -cfg_unix! { - pub mod instance_linux; - pub use instance_linux::Wasi; -} - -cfg_windows! { - pub mod instance_windows; - pub use instance_windows::Wasi; -} diff --git a/crates/containerd-shim-wasmtime/src/instance/instance_windows.rs b/crates/containerd-shim-wasmtime/src/instance/instance_windows.rs index 04867deb2..ea54312ba 100644 --- a/crates/containerd-shim-wasmtime/src/instance/instance_windows.rs +++ b/crates/containerd-shim-wasmtime/src/instance/instance_windows.rs @@ -1,8 +1,8 @@ use std::path::PathBuf; -use containerd_shim_wasm::sandbox::{Instance, InstanceConfig}; -use containerd_shim_wasm::sandbox::instance::{Wait, ExitCode}; use containerd_shim_wasm::sandbox::error::Error; +use containerd_shim_wasm::sandbox::instance::{ExitCode, Wait}; +use containerd_shim_wasm::sandbox::{Instance, InstanceConfig}; pub struct Wasi { exit_code: ExitCode, @@ -40,4 +40,4 @@ impl Instance for Wasi { ) -> std::result::Result<(), Error> { todo!() } -} \ No newline at end of file +} diff --git a/crates/containerd-shim-wasmtime/src/lib.rs b/crates/containerd-shim-wasmtime/src/lib.rs index 6e9fec504..6e4ac2761 100644 --- a/crates/containerd-shim-wasmtime/src/lib.rs +++ b/crates/containerd-shim-wasmtime/src/lib.rs @@ -1,4 +1,6 @@ pub mod error; +#[cfg_attr(unix, path = "instance/instance_linux.rs")] +#[cfg_attr(windows, path = "instance/instance_windows.rs")] pub mod instance; pub mod oci_wasmtime;