Skip to content

Commit fe1ad24

Browse files
author
katelyn martin
committed
reintroduce witx::phases (partial revert WebAssembly#398)
Per this discussion from WebAssembly#434: > It looks like the crate was last published at > [7ec4b1a](WebAssembly@7ec4b1a) > ([diff from > `main`](WebAssembly/WASI@ef8c1a5...main)), > and if we'd like to make an 0.9.1 release (ideally just a bugfix > release), I think there's another breaking change we merged in the > meantime, notably the deletion of `tools/witx/src/phases.rs`, which I > think happened as WebAssembly#398. I think we may need to revert that as well > before publishing 0.9.1? - [@alexcrichton](WebAssembly#434 (comment)) This reintroduces 'witx::phases', so that we do not include any breaking changes in what ought to be a pure bug release.
1 parent 931c62a commit fe1ad24

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

tools/witx/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ mod io;
1010
mod layout;
1111
/// Witx syntax parsing from SExprs
1212
pub mod parser;
13+
/// Paths to witx documents for various proposal phases
14+
pub mod phases;
1315
/// Calculate required polyfill between interfaces
1416
pub mod polyfill;
1517
/// Render ast to text

tools/witx/src/phases.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use anyhow::{bail, Result};
2+
use std::env;
3+
use std::path::{Path, PathBuf};
4+
5+
pub fn docs_path(phase_paths: &[PathBuf]) -> PathBuf {
6+
phase_paths
7+
.get(0)
8+
.expect("at least one path")
9+
.parent()
10+
.expect("drop file")
11+
.join("../docs.md")
12+
}
13+
14+
pub fn snapshot() -> Result<Vec<PathBuf>> {
15+
let root = repo_root()?;
16+
let snapshot = root.join("phases/snapshot/witx");
17+
let paths = vec![snapshot.join("wasi_snapshot_preview1.witx")];
18+
ensure_exists(&paths)?;
19+
Ok(paths)
20+
}
21+
22+
pub fn ephemeral() -> Result<Vec<PathBuf>> {
23+
let root = repo_root()?;
24+
let ephemeral = root.join("phases/ephemeral/witx");
25+
let paths = vec![
26+
ephemeral.join("wasi_ephemeral_args.witx"),
27+
ephemeral.join("wasi_ephemeral_clock.witx"),
28+
ephemeral.join("wasi_ephemeral_environ.witx"),
29+
ephemeral.join("wasi_ephemeral_fd.witx"),
30+
ephemeral.join("wasi_ephemeral_path.witx"),
31+
ephemeral.join("wasi_ephemeral_poll.witx"),
32+
ephemeral.join("wasi_ephemeral_proc.witx"),
33+
ephemeral.join("wasi_ephemeral_random.witx"),
34+
ephemeral.join("wasi_ephemeral_sched.witx"),
35+
ephemeral.join("wasi_ephemeral_sock.witx"),
36+
];
37+
ensure_exists(&paths)?;
38+
Ok(paths)
39+
}
40+
41+
pub mod old {
42+
use super::*;
43+
pub fn snapshot_0() -> Result<Vec<PathBuf>> {
44+
let root = repo_root()?;
45+
let snapshot_0 = root.join("phases/old/snapshot_0/witx");
46+
let paths = vec![snapshot_0.join("wasi_unstable.witx")];
47+
ensure_exists(&paths)?;
48+
Ok(paths)
49+
}
50+
}
51+
52+
fn repo_root() -> Result<PathBuf> {
53+
let repo_root = if let Ok(e) = env::var("WASI_REPO") {
54+
PathBuf::from(e)
55+
} else {
56+
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..")
57+
};
58+
if repo_root.exists() {
59+
Ok(repo_root)
60+
} else {
61+
bail!("could not find WASI repo root - try setting WASI_REPO env variable")
62+
}
63+
}
64+
65+
fn ensure_exists(paths: &[PathBuf]) -> Result<()> {
66+
for p in paths.iter() {
67+
if !p.exists() {
68+
bail!(
69+
"{} does not exist - is WASI_REPO set to repository root?",
70+
Path::display(p)
71+
)
72+
}
73+
}
74+
Ok(())
75+
}

0 commit comments

Comments
 (0)