turbopack_wasm/
lib.rs

1//! WebAssembly support for turbopack.
2//!
3//! WASM assets are copied directly to the output folder.
4//!
5//! When imported from ES modules, they produce a thin module that loads and
6//! instantiates the WebAssembly module.
7
8#![feature(min_specialization)]
9#![feature(arbitrary_self_types)]
10#![feature(arbitrary_self_types_pointers)]
11
12use anyhow::Result;
13use turbo_rcstr::RcStr;
14use turbo_tasks::Vc;
15use turbo_tasks_hash::hash_xxh3_hash64;
16use turbopack_core::asset::Asset;
17
18pub(crate) mod analysis;
19pub(crate) mod loader;
20pub mod module_asset;
21pub(crate) mod output_asset;
22pub mod raw;
23pub mod source;
24
25#[turbo_tasks::function]
26pub async fn wasm_edge_var_name(asset: Vc<Box<dyn Asset>>) -> Result<Vc<RcStr>> {
27    let content = asset.content().file_content().await?;
28    Ok(Vc::cell(
29        format!("wasm_{:08x}", hash_xxh3_hash64(content)).into(),
30    ))
31}
32
33pub fn register() {
34    turbo_tasks::register();
35    turbo_tasks_fs::register();
36    turbopack_core::register();
37    turbopack_ecmascript::register();
38    include!(concat!(env!("OUT_DIR"), "/register.rs"));
39}