Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/ninety-squids-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rspack/binding": patch
"@rspack/core": patch
"@rspack/cli": patch
---

add async-wasm & js-async-module support
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions crates/node_binding/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface RawEntryItem {
export interface RawExperiments {
lazyCompilation: boolean
incrementalRebuild: boolean
asyncWebAssembly: boolean
}
export interface RawExternalItem {
type: "string" | "regexp" | "object"
Expand Down Expand Up @@ -303,6 +304,7 @@ export interface RawOutputOptions {
path: string
publicPath: string
assetModuleFilename: string
webassemblyModuleFilename: string
filename: string
chunkFilename: string
cssFilename: string
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_binding_options/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ rspack_plugin_progress = { path = "../rspack_plugin_progress" }
rspack_plugin_remove_empty_chunks = { path = "../rspack_plugin_remove_empty_chunks" }
rspack_plugin_runtime = { path = "../rspack_plugin_runtime" }
rspack_plugin_split_chunks = { path = "../rspack_plugin_split_chunks" }
rspack_plugin_wasm = { path = "../rspack_plugin_wasm" }
rspack_regex = { path = "../rspack_regex" }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions crates/rspack_binding_options/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ impl RawOptionsApply for RawOptions {
if self.externals_presets.node {
plugins.push(rspack_plugin_externals::node_target_plugin());
}
if experiments.async_web_assembly {
plugins.push(rspack_plugin_wasm::AsyncWasmPlugin::new().boxed());
plugins.push(rspack_plugin_wasm::FetchCompileAsyncWasmPlugin {}.boxed());
}
plugins.push(rspack_plugin_javascript::JsPlugin::new().boxed());
plugins.push(rspack_plugin_javascript::InferAsyncModulesPlugin {}.boxed());
plugins.push(
rspack_plugin_devtool::DevtoolPlugin::new(rspack_plugin_devtool::DevtoolPluginOptions {
inline: devtool.inline(),
Expand Down
2 changes: 2 additions & 0 deletions crates/rspack_binding_options/src/options/raw_experiments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use serde::Deserialize;
pub struct RawExperiments {
pub lazy_compilation: bool,
pub incremental_rebuild: bool,
pub async_web_assembly: bool,
}

impl From<RawExperiments> for Experiments {
fn from(value: RawExperiments) -> Self {
Self {
lazy_compilation: value.lazy_compilation,
incremental_rebuild: value.incremental_rebuild,
async_web_assembly: value.async_web_assembly,
}
}
}
2 changes: 2 additions & 0 deletions crates/rspack_binding_options/src/options/raw_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub struct RawOutputOptions {
pub path: String,
pub public_path: String,
pub asset_module_filename: String,
pub webassembly_module_filename: String,
pub filename: String,
pub chunk_filename: String,
pub css_filename: String,
Expand All @@ -101,6 +102,7 @@ impl RawOptionsApply for RawOutputOptions {
path: self.path.into(),
public_path: self.public_path.into(),
asset_module_filename: self.asset_module_filename.into(),
webassembly_module_filename: self.webassembly_module_filename.into(),
unique_name: self.unique_name,
filename: self.filename.into(),
chunk_filename: self.chunk_filename.into(),
Expand Down
9 changes: 9 additions & 0 deletions crates/rspack_core/src/dependency/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use std::{any::Any, fmt::Debug, hash::Hash};

use dyn_clone::{clone_trait_object, DynClone};
pub use require_context_dependency::RequireContextDependency;
mod static_exports_dependency;
pub use static_exports_dependency::*;

use crate::{
AsAny, ContextMode, ContextOptions, DynEq, DynHash, ErrorSpan, ModuleGraph, ModuleIdentifier,
Expand Down Expand Up @@ -59,6 +61,12 @@ pub enum DependencyType {
CommonJSRequireContext,
// require.context
RequireContext,
/// wasm import
WasmImport,
/// wasm export import
WasmExportImported,
/// static exports
StaticExports,
}

#[derive(Default, Copy, Clone, PartialEq, Eq, Hash, Debug)]
Expand All @@ -70,6 +78,7 @@ pub enum DependencyCategory {
Url,
CssImport,
CssCompose,
Wasm,
}

pub trait Dependency:
Expand Down
65 changes: 65 additions & 0 deletions crates/rspack_core/src/dependency/static_exports_dependency.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::{
CodeGeneratable, CodeGeneratableContext, CodeGeneratableResult, Dependency, DependencyCategory,
DependencyId, DependencyType, ErrorSpan, ModuleDependency, ModuleIdentifier,
};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StaticExportsDependency {
pub id: Option<DependencyId>,
exports: Vec<String>,
can_mangle: bool,

request: String,
}
impl StaticExportsDependency {
pub fn new(exports: Vec<String>, can_mangle: bool) -> Self {
Self {
id: None,
request: "".to_string(),
exports,
can_mangle,
}
}
}

impl Dependency for StaticExportsDependency {
fn id(&self) -> Option<DependencyId> {
self.id
}
fn set_id(&mut self, id: Option<DependencyId>) {
self.id = id;
}
fn parent_module_identifier(&self) -> Option<&ModuleIdentifier> {
None
}
fn category(&self) -> &DependencyCategory {
&DependencyCategory::Unknown
}

fn dependency_type(&self) -> &DependencyType {
&DependencyType::StaticExports
}
}

impl ModuleDependency for StaticExportsDependency {
fn request(&self) -> &str {
&self.request
}

fn user_request(&self) -> &str {
&self.request
}

fn span(&self) -> Option<&ErrorSpan> {
None
}
}

impl CodeGeneratable for StaticExportsDependency {
fn generate(
&self,
_code_generatable_context: &mut CodeGeneratableContext,
) -> rspack_error::Result<CodeGeneratableResult> {
todo!()
}
}
13 changes: 13 additions & 0 deletions crates/rspack_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub use rspack_sources;
pub enum SourceType {
JavaScript,
Css,
Wasm,
Asset,
#[default]
Unknown,
Expand All @@ -94,6 +95,8 @@ pub enum ModuleType {
JsxEsm,
Tsx,
Ts,
WasmSync,
WasmAsync,
AssetInline,
AssetResource,
AssetSource,
Expand Down Expand Up @@ -124,6 +127,10 @@ impl ModuleType {
ModuleType::Tsx | ModuleType::Jsx | ModuleType::JsxEsm | ModuleType::JsxDynamic
)
}

pub fn is_wasm_like(&self) -> bool {
matches!(self, ModuleType::WasmSync | ModuleType::WasmAsync)
}
}

impl fmt::Display for ModuleType {
Expand All @@ -148,6 +155,9 @@ impl fmt::Display for ModuleType {

ModuleType::Json => "json",

ModuleType::WasmSync => "webassembly/sync",
ModuleType::WasmAsync => "webassembly/async",

ModuleType::Asset => "asset",
ModuleType::AssetSource => "asset/source",
ModuleType::AssetResource => "asset/resource",
Expand Down Expand Up @@ -180,6 +190,9 @@ impl TryFrom<&str> for ModuleType {

"json" => Ok(Self::Json),

"webassembly/sync" => Ok(Self::WasmSync),
"webassembly/async" => Ok(Self::WasmAsync),

"asset" => Ok(Self::Asset),
"asset/resource" => Ok(Self::AssetResource),
"asset/source" => Ok(Self::AssetSource),
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct BuildInfo {
#[derive(Debug, Default, Clone)]
pub struct BuildMeta {
pub strict_harmony_module: bool,
pub is_async: bool,
// TODO webpack exportsType
pub esm: bool,
}
Expand Down
23 changes: 23 additions & 0 deletions crates/rspack_core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,29 @@ impl ModuleGraph {
.and_then(|mgm| mgm.get_issuer().get_module(self))
}

pub fn is_async(&self, module: &ModuleIdentifier) -> bool {
self
.module_graph_module_by_identifier(module)
.map(|mgm| {
mgm
.build_meta
.as_ref()
.expect("build_meta should be initialized")
.is_async
})
.unwrap_or_default()
}

pub fn set_async(&mut self, module: &ModuleIdentifier) {
if let Some(mgm) = self.module_graph_module_by_identifier_mut(module) {
mgm
.build_meta
.as_mut()
.expect("build_meta should be initialized")
.is_async = true;
}
}

pub fn get_outgoing_connections(&self, module: &BoxModule) -> HashSet<&ModuleGraphConnection> {
self
.module_graph_module_by_identifier(&module.identifier())
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/options/experiments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
pub struct Experiments {
pub lazy_compilation: bool,
pub incremental_rebuild: bool,
pub async_web_assembly: bool,
}
1 change: 1 addition & 0 deletions crates/rspack_core/src/options/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct OutputOptions {
pub path: PathBuf,
pub public_path: PublicPath,
pub asset_module_filename: Filename,
pub webassembly_module_filename: Filename,
pub unique_name: String,
//todo we are not going to support file_name & chunk_file_name as function in the near feature
pub filename: Filename,
Expand Down
Loading