turbo_tasks_fs/embed/
dir.rs1pub use ::include_dir::{
2 include_dir, {self},
3};
4use anyhow::Result;
5use turbo_rcstr::RcStr;
6use turbo_tasks::Vc;
7
8use crate::{DiskFileSystem, FileSystem, embed::EmbeddedFileSystem};
9
10#[turbo_tasks::function]
11pub async fn directory_from_relative_path(
12 name: RcStr,
13 path: RcStr,
14) -> Result<Vc<Box<dyn FileSystem>>> {
15 let disk_fs = DiskFileSystem::new(name, path, vec![]);
16 disk_fs.await?.start_watching(None).await?;
17
18 Ok(Vc::upcast(disk_fs))
19}
20
21pub fn directory_from_include_dir(
22 name: RcStr,
23 dir: &'static include_dir::Dir<'static>,
24) -> Vc<Box<dyn FileSystem>> {
25 Vc::upcast(EmbeddedFileSystem::new(name, dir))
26}
27
28#[macro_export]
40macro_rules! embed_directory {
41 ($name:tt, $path:tt) => {{ assert!($path.contains("$CARGO_MANIFEST_DIR"));
43 assert!(!$path.replace("$CARGO_MANIFEST_DIR", "").contains('$'));
45
46 turbo_tasks_fs::embed_directory_internal!($name, $path)
47 }};
48}
49
50#[cfg(feature = "dynamic_embed_contents")]
51#[macro_export]
52#[doc(hidden)]
53macro_rules! embed_directory_internal {
54 ($name:tt, $path:tt) => {{
55 use turbo_tasks_fs::embed::include_dir;
57
58 let path = $path.replace("$CARGO_MANIFEST_DIR", env!("CARGO_MANIFEST_DIR"));
59
60 turbo_tasks_fs::embed::directory_from_relative_path($name.into(), path.into())
61 }};
62}
63
64#[cfg(not(feature = "dynamic_embed_contents"))]
65#[macro_export]
66#[doc(hidden)]
67macro_rules! embed_directory_internal {
68 ($name:tt, $path:tt) => {{
69 use turbo_tasks_fs::embed::include_dir;
71
72 static DIR: include_dir::Dir<'static> = turbo_tasks_fs::embed::include_dir!($path);
73
74 turbo_tasks_fs::embed::directory_from_include_dir($name.into(), &DIR)
75 }};
76}