Skip to content

Commit

Permalink
Always export parse_wit_from_path
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Oct 7, 2023
1 parent 312d66a commit cae6115
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions crates/wit-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,10 @@ pub(crate) fn base_producers() -> wasm_metadata::Producers {

/// Parse a WIT file from a path that represents a top level 'wit' directory,
/// normally containing a 'deps' folder.
#[cfg(feature = "wat")]
pub fn parse_wit_from_path(
path: impl AsRef<std::path::Path>,
) -> Result<(Resolve, wit_parser::PackageId)> {
use anyhow::Context;
use wit_parser::UnresolvedPackage;

let mut resolver = Resolve::default();
let id = match path.as_ref() {
Expand All @@ -109,7 +107,21 @@ pub fn parse_wit_from_path(
// Non-directory files (including symlinks) can be either:
// - Wasm modules (binary or WAT) that are WIT packages
// - WIT files
#[cfg(not(feature = "wat"))]
p => {
let file_contents = std::fs::read(p)
.with_context(|| format!("failed to parse WIT from path [{}]", p.display()))?;
match decode(&file_contents)? {
DecodedWasm::Component(..) => {
bail!("specified path is a component, not a wit package")
}
DecodedWasm::WitPackage(resolve, pkg) => return Ok((resolve, pkg)),
}
}
#[cfg(feature = "wat")]
p => {
use wit_parser::UnresolvedPackage;

let file_contents = std::fs::read(p)
.with_context(|| format!("failed to parse WIT from path [{}]", p.display()))?;

Expand Down

0 comments on commit cae6115

Please sign in to comment.