Skip to main content

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::{Context, Result};
13use turbo_rcstr::RcStr;
14use turbo_tasks::Vc;
15use turbo_tasks_hash::HashAlgorithm;
16use turbopack_core::asset::{Asset, no_hash_salt};
17
18pub(crate) mod analysis;
19pub(crate) mod embed;
20pub(crate) mod loader;
21pub mod module_asset;
22pub(crate) mod output_asset;
23pub mod raw;
24pub mod source;
25
26#[turbo_tasks::function]
27pub async fn wasm_edge_var_name(asset: Vc<Box<dyn Asset>>) -> Result<Vc<RcStr>> {
28    let hash = asset
29        .content()
30        .content_hash(no_hash_salt(), HashAlgorithm::Xxh3Hash128Hex)
31        .await?;
32    let hash = hash
33        .as_ref()
34        .context("Missing content when trying to generate the content hash for a WASM asset")?;
35    Ok(Vc::cell(format!("wasm_{}", hash).into()))
36}