Skip to content

Commit

Permalink
Merge #2368 #2369
Browse files Browse the repository at this point in the history
2368: chore(wasi) Remove the deprecated code r=Hywan a=Hywan

# Description

This PR removes deprecated code from the `wasi` crate. With the 2.x coming soon, we no longer need this to maintain this code :-).

I don't know what to do with:

```rust
pub enum Kind {
    File {
        /// The path on the host system where the file is located
        /// This is deprecated and will be removed soon
        path: PathBuf,
```

in `state/mod.rs`. Any clue @MarkMcCaskey?

2369: chore(cli) Remove the `--backend` deprecated option r=Hywan a=Hywan

# Description

This PR removes the deprecated `--backend` option. With the 2.x coming, we no longer need to maintain this compatibility.


Co-authored-by: Ivan Enderlin <[email protected]>
  • Loading branch information
bors[bot] and Hywan authored May 31, 2021
3 parents 29c99fe + 4f0a325 + 87175eb commit 19cea55
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 161 deletions.
32 changes: 4 additions & 28 deletions lib/cli/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//! commands.
use crate::common::WasmFeatures;
use anyhow::{Error, Result};
use anyhow::Result;
use clap::Clap;
use std::path::PathBuf;
use std::str::FromStr;
use std::string::ToString;
#[allow(unused_imports)]
use std::sync::Arc;
Expand Down Expand Up @@ -36,15 +35,15 @@ pub struct StoreOptions {
/// The compiler options
pub struct CompilerOptions {
/// Use Singlepass compiler.
#[clap(long, conflicts_with_all = &["cranelift", "llvm", "backend"])]
#[clap(long, conflicts_with_all = &["cranelift", "llvm"])]
singlepass: bool,

/// Use Cranelift compiler.
#[clap(long, conflicts_with_all = &["singlepass", "llvm", "backend"])]
#[clap(long, conflicts_with_all = &["singlepass", "llvm"])]
cranelift: bool,

/// Use LLVM compiler.
#[clap(long, conflicts_with_all = &["singlepass", "cranelift", "backend"])]
#[clap(long, conflicts_with_all = &["singlepass", "cranelift"])]
llvm: bool,

/// Enable compiler internal verification.
Expand All @@ -55,10 +54,6 @@ pub struct CompilerOptions {
#[clap(long, parse(from_os_str))]
llvm_debug_dir: Option<PathBuf>,

/// The deprecated backend flag - Please do not use
#[clap(long = "backend", hidden = true, conflicts_with_all = &["singlepass", "cranelift", "llvm"])]
backend: Option<String>,

#[clap(flatten)]
features: WasmFeatures,
}
Expand All @@ -72,12 +67,6 @@ impl CompilerOptions {
Ok(CompilerType::LLVM)
} else if self.singlepass {
Ok(CompilerType::Singlepass)
} else if let Some(backend) = self.backend.clone() {
warning!(
"the `--backend={0}` flag is deprecated, please use `--{0}` instead",
backend
);
CompilerType::from_str(&backend)
} else {
// Auto mode, we choose the best compiler for that platform
cfg_if::cfg_if! {
Expand Down Expand Up @@ -344,19 +333,6 @@ impl ToString for CompilerType {
}
}

impl FromStr for CompilerType {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
match s {
"singlepass" => Ok(Self::Singlepass),
"cranelift" => Ok(Self::Cranelift),
"llvm" => Ok(Self::LLVM),
"headless" => Ok(Self::Headless),
backend => bail!("The `{}` compiler does not exist.", backend),
}
}
}

/// The engine used for the store
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum EngineType {
Expand Down
7 changes: 0 additions & 7 deletions lib/wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,6 @@ impl WasiEnv {
self.state.lock().unwrap()
}

// TODO: delete this method before 1.0.0 release
#[doc(hidden)]
#[deprecated(since = "1.0.0-beta1", note = "Please use the `state` method instead")]
pub fn state_mut(&mut self) -> MutexGuard<WasiState> {
self.state.lock().unwrap()
}

/// Get a reference to the memory
pub fn memory(&self) -> &Memory {
self.memory_ref()
Expand Down
2 changes: 0 additions & 2 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@ impl WasiStateBuilder {

// self.preopens are checked in [`PreopenDirBuilder::build`]

// this deprecation warning only applies to external callers
#[allow(deprecated)]
let mut wasi_fs = WasiFs::new_with_preopen(&self.preopens)
.map_err(WasiStateCreationError::WasiFsCreationError)?;
// set up the file system, overriding base files and calling the setup function
Expand Down
125 changes: 1 addition & 124 deletions lib/wasi/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub struct InodeVal {
#[derive(Debug, Serialize, Deserialize)]
pub enum Kind {
File {
/// the open file, if it's open
/// The open file, if it's open
handle: Option<Box<dyn WasiFile>>,
/// The path on the host system where the file is located
/// This is deprecated and will be removed soon
Expand Down Expand Up @@ -166,129 +166,6 @@ pub struct WasiFs {
}

impl WasiFs {
/// Internal function for constructing a [`WasiFs`]. Please use
/// [`WasiState::new`].
#[deprecated(
since = "0.14.0",
note = "This method will change or be made private in the future. Please use `WasiState::new` and the builder API instead."
)]
pub fn new(
preopened_dirs: &[PathBuf],
mapped_dirs: &[(String, PathBuf)],
) -> Result<Self, String> {
let (mut wasi_fs, root_inode) = Self::new_init()?;

debug!("wasi::fs::preopen_dirs");
for dir in preopened_dirs {
debug!("Attempting to preopen {}", &dir.to_string_lossy());
// TODO: think about this
let default_rights = ALL_RIGHTS;
let cur_dir_metadata = dir.metadata().map_err(|e| {
format!(
"Could not get metadata for file {:?}: {}",
dir,
e.to_string()
)
})?;
let kind = if cur_dir_metadata.is_dir() {
Kind::Dir {
parent: Some(root_inode),
path: dir.clone(),
entries: Default::default(),
}
} else {
return Err(format!(
"WASI only supports pre-opened directories right now; found \"{}\"",
&dir.to_string_lossy()
));
};
// TODO: handle nested pats in `file`
let inode = wasi_fs
.create_inode(kind, true, dir.to_string_lossy().into_owned())
.map_err(|e| {
format!(
"Failed to create inode for preopened dir: WASI error code: {}",
e
)
})?;
let fd = wasi_fs
.create_fd(
default_rights,
default_rights,
0,
Fd::READ | Fd::WRITE,
inode,
)
.map_err(|e| format!("Could not open fd for file {:?}: {}", dir, e))?;
if let Kind::Root { entries } = &mut wasi_fs.inodes[root_inode].kind {
let result = entries.insert(dir.to_string_lossy().into_owned(), inode);
if result.is_some() {
return Err(format!(
"Error: found collision in preopened directory names, `{}`",
dir.to_string_lossy()
));
}
}
wasi_fs.preopen_fds.push(fd);
}
debug!("wasi::fs::mapped_dirs");
for (alias, real_dir) in mapped_dirs {
debug!("Attempting to open {:?} at {}", real_dir, alias);
// TODO: think about this
let default_rights = ALL_RIGHTS;
let cur_dir_metadata = real_dir.metadata().map_err(|e| {
format!(
"Could not get metadata for file {:?}: {}",
&real_dir,
e.to_string()
)
})?;
let kind = if cur_dir_metadata.is_dir() {
Kind::Dir {
parent: Some(root_inode),
path: real_dir.clone(),
entries: Default::default(),
}
} else {
return Err(format!(
"WASI only supports pre-opened directories right now; found \"{:?}\"",
&real_dir,
));
};
// TODO: handle nested pats in `file`
let inode = wasi_fs
.create_inode(kind, true, alias.clone())
.map_err(|e| {
format!(
"Failed to create inode for preopened dir: WASI error code: {}",
e
)
})?;
let fd = wasi_fs
.create_fd(
default_rights,
default_rights,
0,
Fd::READ | Fd::WRITE,
inode,
)
.map_err(|e| format!("Could not open fd for file {:?}: {}", &real_dir, e))?;
if let Kind::Root { entries } = &mut wasi_fs.inodes[root_inode].kind {
let result = entries.insert(alias.clone(), inode);
if result.is_some() {
return Err(format!(
"Error: found collision in preopened directory aliases, `{}`",
alias,
));
}
}
wasi_fs.preopen_fds.push(fd);
}

debug!("wasi::fs::end");
Ok(wasi_fs)
}

/// Created for the builder API. like `new` but with more information
pub(crate) fn new_with_preopen(preopens: &[PreopenedDir]) -> Result<Self, String> {
let (mut wasi_fs, root_inode) = Self::new_init()?;
Expand Down

0 comments on commit 19cea55

Please sign in to comment.