Skip to content

Commit d4678db

Browse files
authored
Merge pull request #684 from lann/remove-module-io-from-files
Remove unused ModuleIoRedirects::new_from_files
2 parents 10fb784 + 4d8af0c commit d4678db

File tree

9 files changed

+18
-148
lines changed

9 files changed

+18
-148
lines changed

crates/config/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Resolver {
123123
}
124124

125125
/// A config key.
126-
#[derive(Debug, PartialEq)]
126+
#[derive(Debug, PartialEq, Eq)]
127127
pub struct Key<'a>(&'a str);
128128

129129
impl<'a> Key<'a> {

crates/config/src/tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ impl std::fmt::Debug for Slot {
193193
}
194194
}
195195

196-
#[derive(Debug, Deserialize, PartialEq)]
196+
#[derive(Debug, Deserialize, PartialEq, Eq)]
197197
pub struct RawSection(pub HashMap<String, RawSlot>);
198198

199-
#[derive(Debug, Default, PartialEq, Deserialize, Serialize)]
199+
#[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
200200
#[serde(default)]
201201
pub struct RawSlot {
202202
pub default: Option<String>,

crates/engine/src/io.rs

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
use cap_std::fs::File as CapFile;
21
use std::{
32
collections::HashSet,
43
fmt::Debug,
5-
fs::{File, OpenOptions},
64
io::{LineWriter, Write},
7-
path::PathBuf,
85
sync::{Arc, RwLock, RwLockReadGuard},
96
};
107

118
use wasi_common::{
129
pipe::{ReadPipe, WritePipe},
1310
WasiFile,
1411
};
15-
use wasmtime_wasi::sync::file::File as WasmtimeFile;
1612

1713
/// Prepares a WASI pipe which writes to a memory buffer, optionally
1814
/// copying to the specified output stream.
@@ -65,78 +61,6 @@ pub trait OutputBuffers {
6561
fn stderr(&self) -> &[u8];
6662
}
6763

68-
/// Wrapper around File with a convenient PathBuf for cloning
69-
pub struct PipeFile(pub File, pub PathBuf);
70-
71-
impl PipeFile {
72-
/// Constructs an instance from a file, and the PathBuf to that file.
73-
pub fn new(file: File, path: PathBuf) -> Self {
74-
Self(file, path)
75-
}
76-
}
77-
78-
impl std::fmt::Debug for PipeFile {
79-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80-
f.debug_struct("PipeFile")
81-
.field("File", &self.0)
82-
.field("PathBuf", &self.1)
83-
.finish()
84-
}
85-
}
86-
87-
impl Clone for PipeFile {
88-
fn clone(&self) -> Self {
89-
let f = OpenOptions::new()
90-
.read(true)
91-
.write(true)
92-
.open(&self.1)
93-
.unwrap();
94-
Self(f, self.1.clone())
95-
}
96-
}
97-
98-
/// CustomIoPipes that can be passed to `ExecutionContextConfiguration`
99-
/// to direct out and err
100-
#[derive(Clone, Debug, Default)]
101-
pub struct CustomLogPipes {
102-
/// in pipe (file and pathbuf)
103-
pub stdin_pipe: Option<PipeFile>,
104-
/// out pipe (file and pathbuf)
105-
pub stdout_pipe: Option<PipeFile>,
106-
/// err pipe (file and pathbuf)
107-
pub stderr_pipe: Option<PipeFile>,
108-
}
109-
110-
impl CustomLogPipes {
111-
/// Constructs an instance from a set of PipeFile objects.
112-
pub fn new(
113-
stdin_pipe: Option<PipeFile>,
114-
stdout_pipe: Option<PipeFile>,
115-
stderr_pipe: Option<PipeFile>,
116-
) -> Self {
117-
Self {
118-
stdin_pipe,
119-
stdout_pipe,
120-
stderr_pipe,
121-
}
122-
}
123-
}
124-
125-
/// Types of ModuleIoRedirects
126-
#[derive(Clone, Debug)]
127-
pub enum ModuleIoRedirectsTypes {
128-
/// This will signal the executor to use `capture_io_to_memory_default()`
129-
Default,
130-
/// This will signal the executor to use `capture_io_to_memory_files()`
131-
FromFiles(CustomLogPipes),
132-
}
133-
134-
impl Default for ModuleIoRedirectsTypes {
135-
fn default() -> Self {
136-
Self::Default
137-
}
138-
}
139-
14064
/// A set of redirected standard I/O streams with which
14165
/// a Wasm module is to be run.
14266
pub struct ModuleIoRedirects {
@@ -170,37 +94,6 @@ impl ModuleIoRedirects {
17094
read_handles: rrh,
17195
}
17296
}
173-
174-
/// Constructs the ModuleIoRedirects, and RedirectReadHandles instances from `File`s directly
175-
pub fn new_from_files(
176-
stdin_file: Option<File>,
177-
stdout_file: Option<File>,
178-
stderr_file: Option<File>,
179-
) -> Self {
180-
let rrh = RedirectReadHandles::new(true);
181-
182-
let in_stdpipe: Box<dyn WasiFile> = match stdin_file {
183-
Some(inf) => Box::new(WasmtimeFile::from_cap_std(CapFile::from_std(inf))),
184-
None => Box::new(ReadPipe::from(vec![])),
185-
};
186-
let out_stdpipe: Box<dyn WasiFile> = match stdout_file {
187-
Some(ouf) => Box::new(WasmtimeFile::from_cap_std(CapFile::from_std(ouf))),
188-
None => Box::new(WritePipe::from_shared(rrh.stdout.clone())),
189-
};
190-
let err_stdpipe: Box<dyn WasiFile> = match stderr_file {
191-
Some(erf) => Box::new(WasmtimeFile::from_cap_std(CapFile::from_std(erf))),
192-
None => Box::new(WritePipe::from_shared(rrh.stderr.clone())),
193-
};
194-
195-
Self {
196-
pipes: RedirectPipes {
197-
stdin: in_stdpipe,
198-
stdout: out_stdpipe,
199-
stderr: err_stdpipe,
200-
},
201-
read_handles: rrh,
202-
}
203-
}
20497
}
20598

20699
/// Pipes from `ModuleIoRedirects`

crates/engine/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{collections::HashMap, io::Write, path::PathBuf, sync::Arc};
1111

1212
use anyhow::{bail, Context, Result};
1313
use host_component::{HostComponent, HostComponents, HostComponentsState};
14-
use io::{FollowComponents, ModuleIoRedirectsTypes, OutputBuffers, RedirectPipes};
14+
use io::{FollowComponents, OutputBuffers, RedirectPipes};
1515
use spin_config::{host_component::ComponentConfig, Resolver};
1616
use spin_manifest::{CoreComponent, DirectoryMount, ModuleSource};
1717
use tokio::{
@@ -38,8 +38,6 @@ pub struct ExecutionContextConfiguration {
3838
pub follow_components: FollowComponents,
3939
/// Application configuration resolver.
4040
pub config_resolver: Option<Arc<Resolver>>,
41-
/// The type of io redirects for the module (default, or files)
42-
pub module_io_redirects: ModuleIoRedirectsTypes,
4341
}
4442

4543
/// Top-level runtime context data to be passed to a component.

crates/http/src/spin.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use anyhow::Result;
66
use async_trait::async_trait;
77
use http::Uri;
88
use hyper::{Body, Request, Response};
9-
use spin_engine::io::{ModuleIoRedirects, ModuleIoRedirectsTypes};
9+
use spin_engine::io::ModuleIoRedirects;
1010
use std::{net::SocketAddr, str, str::FromStr};
1111
use tokio::task::spawn_blocking;
1212
use tracing::log;
@@ -32,17 +32,7 @@ impl HttpExecutor for SpinHttpExecutor {
3232
component
3333
);
3434

35-
let mior = if let ModuleIoRedirectsTypes::FromFiles(clp) =
36-
engine.config.module_io_redirects.clone()
37-
{
38-
ModuleIoRedirects::new_from_files(
39-
clp.stdin_pipe.map(|inp| inp.0),
40-
clp.stdout_pipe.map(|oup| oup.0),
41-
clp.stderr_pipe.map(|erp| erp.0),
42-
)
43-
} else {
44-
ModuleIoRedirects::new(follow)
45-
};
35+
let mior = ModuleIoRedirects::new(follow);
4636

4737
let (store, instance) =
4838
engine.prepare_component(component, None, Some(mior.pipes), None, None)?;

crates/loader/src/local/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub struct RawWasmConfig {
107107

108108
/// An entry in the `files` list mapping a source path to an absolute
109109
/// mount path in the guest.
110-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
110+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
111111
#[serde(deny_unknown_fields, rename_all = "snake_case")]
112112
pub struct RawDirectoryPlacement {
113113
/// The source to mount.
@@ -118,7 +118,7 @@ pub struct RawDirectoryPlacement {
118118

119119
/// A specification for a file or set of files to mount in the
120120
/// Wasm module.
121-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
121+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
122122
#[serde(deny_unknown_fields, rename_all = "snake_case", untagged)]
123123
pub enum RawFileMount {
124124
/// Mount a specified directory at a specified location.
@@ -141,7 +141,7 @@ pub enum RawModuleSource {
141141
/// TODO
142142
/// The component and its entrypoint should be pulled from Bindle.
143143
/// This assumes access to the Bindle server.
144-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
144+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
145145
#[serde(deny_unknown_fields, rename_all = "snake_case")]
146146
pub struct FileComponentBindleSource {
147147
/// Reference to the bindle (name/version)

crates/manifest/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct CoreComponent {
8484
}
8585

8686
/// The location from which an application was loaded.
87-
#[derive(Clone, Debug, PartialEq)]
87+
#[derive(Clone, Debug, PartialEq, Eq)]
8888
pub enum ApplicationOrigin {
8989
/// The application was loaded from the specified file.
9090
File(PathBuf),
@@ -98,7 +98,7 @@ pub enum ApplicationOrigin {
9898
}
9999

100100
/// The trigger type.
101-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
101+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
102102
#[serde(deny_unknown_fields, rename_all = "camelCase", tag = "type")]
103103
pub enum ApplicationTrigger {
104104
/// HTTP trigger type.
@@ -108,7 +108,7 @@ pub enum ApplicationTrigger {
108108
}
109109

110110
/// HTTP trigger configuration.
111-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
111+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
112112
pub struct HttpTriggerConfiguration {
113113
/// Base path for the HTTP application.
114114
pub base: String,
@@ -132,7 +132,7 @@ impl TryFrom<ApplicationTrigger> for HttpTriggerConfiguration {
132132
}
133133

134134
/// Redis trigger configuration.
135-
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
135+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
136136
pub struct RedisTriggerConfiguration {
137137
/// Address of Redis server.
138138
pub address: String,
@@ -217,7 +217,7 @@ impl Default for HttpConfig {
217217
/// or the Wagi CGI interface.
218218
///
219219
/// If an executor is not specified, the inferred default is `HttpExecutor::Spin`.
220-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
220+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
221221
#[serde(deny_unknown_fields, rename_all = "camelCase", tag = "type")]
222222
pub enum HttpExecutor {
223223
/// The component implements the Spin HTTP interface.
@@ -233,7 +233,7 @@ impl Default for HttpExecutor {
233233
}
234234

235235
/// Wagi specific configuration for the http executor.
236-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
236+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
237237
#[serde(default, deny_unknown_fields, rename_all = "camelCase")]
238238
pub struct WagiConfig {
239239
/// The name of the entrypoint.
@@ -275,7 +275,7 @@ pub struct RedisConfig {
275275
/// The executor for the Redis component.
276276
///
277277
/// If an executor is not specified, the inferred default is `RedisExecutor::Spin`.
278-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
278+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
279279
#[serde(deny_unknown_fields, rename_all = "camelCase", tag = "type")]
280280
pub enum RedisExecutor {
281281
/// The component implements the Spin Redis interface.

crates/redis/src/spin.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{spin_redis::SpinRedis, ExecutionContext, RedisExecutor, RuntimeContext};
22
use anyhow::Result;
33
use async_trait::async_trait;
4-
use spin_engine::io::{ModuleIoRedirects, ModuleIoRedirectsTypes};
4+
use spin_engine::io::ModuleIoRedirects;
55
use tokio::task::spawn_blocking;
66
use wasmtime::{Instance, Store};
77

@@ -23,17 +23,7 @@ impl RedisExecutor for SpinRedisExecutor {
2323
component
2424
);
2525

26-
let mior = if let ModuleIoRedirectsTypes::FromFiles(clp) =
27-
engine.config.module_io_redirects.clone()
28-
{
29-
ModuleIoRedirects::new_from_files(
30-
clp.stdin_pipe.map(|inp| inp.0),
31-
clp.stdout_pipe.map(|oup| oup.0),
32-
clp.stderr_pipe.map(|erp| erp.0),
33-
)
34-
} else {
35-
ModuleIoRedirects::new(follow)
36-
};
26+
let mior = ModuleIoRedirects::new(follow);
3727

3828
let (store, instance) =
3929
engine.prepare_component(component, None, Some(mior.pipes), None, None)?;

crates/trigger/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ impl<Executor: TriggerExecutor> TriggerExecutorBuilder<Executor> {
9393
log_dir: self.log_dir,
9494
follow_components: self.follow_components,
9595
config_resolver: app.config_resolver,
96-
module_io_redirects: Default::default(),
9796
};
9897
let engine = Engine::new(self.wasmtime_config)?;
9998
let mut ctx_builder = Builder::with_engine(ctx_config, engine)?;

0 commit comments

Comments
 (0)