forte_wit/lib.rs
1//! WASI wit definitions shared by forte-sdk (its own bindings) and
2//! forte-codegen (which routes them to user crates via build scripts).
3//!
4//! The wit tree is embedded at compile time via `include_dir!`, so any
5//! downstream crate can call [`extract_wit`] from a build script to
6//! materialize the same wit files into an arbitrary directory.
7
8use std::path::{Path, PathBuf};
9
10use include_dir::{Dir, include_dir};
11
12static WIT_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/wit");
13
14pub fn extract_wit(target_dir: &Path) -> PathBuf {
15 if target_dir.exists() {
16 std::fs::remove_dir_all(target_dir).ok();
17 }
18 std::fs::create_dir_all(target_dir).expect("failed to create wit target dir");
19 WIT_DIR
20 .extract(target_dir)
21 .expect("failed to extract bundled wit files");
22 target_dir.to_path_buf()
23}