Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/witx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ mod io;
mod layout;
/// Witx syntax parsing from SExprs
pub mod parser;
/// Paths to witx documents for various proposal phases
pub mod phases;
/// Calculate required polyfill between interfaces
pub mod polyfill;
/// Render ast to text
Expand Down
75 changes: 75 additions & 0 deletions tools/witx/src/phases.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use anyhow::{bail, Result};
use std::env;
use std::path::{Path, PathBuf};

pub fn docs_path(phase_paths: &[PathBuf]) -> PathBuf {
phase_paths
.get(0)
.expect("at least one path")
.parent()
.expect("drop file")
.join("../docs.md")
}

pub fn snapshot() -> Result<Vec<PathBuf>> {
let root = repo_root()?;
let snapshot = root.join("phases/snapshot/witx");
let paths = vec![snapshot.join("wasi_snapshot_preview1.witx")];
ensure_exists(&paths)?;
Ok(paths)
}

pub fn ephemeral() -> Result<Vec<PathBuf>> {
let root = repo_root()?;
let ephemeral = root.join("phases/ephemeral/witx");
let paths = vec![
ephemeral.join("wasi_ephemeral_args.witx"),
ephemeral.join("wasi_ephemeral_clock.witx"),
ephemeral.join("wasi_ephemeral_environ.witx"),
ephemeral.join("wasi_ephemeral_fd.witx"),
ephemeral.join("wasi_ephemeral_path.witx"),
ephemeral.join("wasi_ephemeral_poll.witx"),
ephemeral.join("wasi_ephemeral_proc.witx"),
ephemeral.join("wasi_ephemeral_random.witx"),
ephemeral.join("wasi_ephemeral_sched.witx"),
ephemeral.join("wasi_ephemeral_sock.witx"),
];
ensure_exists(&paths)?;
Ok(paths)
}

pub mod old {
use super::*;
pub fn snapshot_0() -> Result<Vec<PathBuf>> {
let root = repo_root()?;
let snapshot_0 = root.join("phases/old/snapshot_0/witx");
let paths = vec![snapshot_0.join("wasi_unstable.witx")];
ensure_exists(&paths)?;
Ok(paths)
}
}

fn repo_root() -> Result<PathBuf> {
let repo_root = if let Ok(e) = env::var("WASI_REPO") {
PathBuf::from(e)
} else {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../..")
};
if repo_root.exists() {
Ok(repo_root)
} else {
bail!("could not find WASI repo root - try setting WASI_REPO env variable")
}
}

fn ensure_exists(paths: &[PathBuf]) -> Result<()> {
for p in paths.iter() {
if !p.exists() {
bail!(
"{} does not exist - is WASI_REPO set to repository root?",
Path::display(p)
)
}
}
Ok(())
}