Skip to content

Commit

Permalink
refactor: move compiler options builder to new crate (#8941)
Browse files Browse the repository at this point in the history
* refactor: move compiler options builder to new crate

* chore: update
  • Loading branch information
h-a-n-a authored Jan 6, 2025
1 parent 1e9fc0e commit 0a4e43a
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 47 deletions.
15 changes: 15 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ignored = [
"rspack_plugin_mini_css_extract",
"rspack_binding",
"rspack_plugin_merge",
"rspack",
]
[workspace.dependencies]
anyhow = { version = "1.0.95", features = ["backtrace"] }
Expand Down Expand Up @@ -106,6 +107,7 @@ rspack_dojang = { version = "0.1.9" }


# all rspack workspace dependencies
rspack = { version = "0.2.0", path = "crates/rspack" }
rspack_allocator = { version = "0.2.0", path = "crates/rspack_allocator" }
rspack_ast = { version = "0.2.0", path = "crates/rspack_ast" }
rspack_base64 = { version = "0.2.0", path = "crates/rspack_base64" }
Expand Down
21 changes: 21 additions & 0 deletions crates/rspack/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
description = "rspack"
edition = "2021"
license = "MIT"
name = "rspack"
repository = "https://github.com/web-infra-dev/rspack"
version = "0.2.0"

[dependencies]
bitflags = { workspace = true }
indexmap = { workspace = true, features = ["rayon"] }
regex = { workspace = true }
rspack_core = { workspace = true }
rspack_hash = { workspace = true }
rspack_paths = { workspace = true }
rspack_regex = { workspace = true }
rustc-hash = { workspace = true }
serde_json = { workspace = true }

[lints]
workspace = true
22 changes: 22 additions & 0 deletions crates/rspack/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2022-present Bytedance, Inc. and its affiliates.


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions crates/rspack/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod options;
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
use indexmap::IndexMap;
use rspack_core::{incremental::IncrementalPasses, ModuleType};
use rspack_core::{
AssetParserDataUrl, AssetParserDataUrlOptions, AssetParserOptions, ByDependency, CacheOptions,
ChunkLoading, ChunkLoadingType, CleanOptions, CompilerOptions, Context, CrossOriginLoading,
CssAutoGeneratorOptions, CssAutoParserOptions, CssExportsConvention, CssGeneratorOptions,
CssModuleGeneratorOptions, CssModuleParserOptions, CssParserOptions, DynamicImportMode,
EntryDescription, Environment, ExperimentCacheOptions, Experiments, Filename, FilenameTemplate,
GeneratorOptions, GeneratorOptionsMap, JavascriptParserOptions, JavascriptParserOrder,
JavascriptParserUrl, LibraryName, LibraryNonUmdObject, LibraryOptions, Mode, ModuleNoParseRules,
ModuleOptions, ModuleRule, ModuleRuleEffect, OutputOptions, ParserOptions, ParserOptionsMap,
PathInfo, PublicPath, Resolve, RspackFuture, RuleSetCondition, RuleSetLogicalConditions,
TrustedTypes, WasmLoading, WasmLoadingType,
};
use rspack_hash::{HashDigest, HashFunction, HashSalt};
use rspack_paths::{AssertUtf8, Utf8PathBuf};
use rspack_regex::RspackRegex;
use rustc_hash::FxHashMap as HashMap;

use super::{
get_targets_properties, AssetParserDataUrl, AssetParserDataUrlOptions, AssetParserOptions,
ByDependency, CacheOptions, ChunkLoading, ChunkLoadingType, CleanOptions, CompilerOptions,
Context, CrossOriginLoading, CssAutoGeneratorOptions, CssAutoParserOptions, CssExportsConvention,
CssGeneratorOptions, CssModuleGeneratorOptions, CssModuleParserOptions, CssParserOptions,
Devtool, DynamicImportMode, EntryDescription, Environment, ExperimentCacheOptions, Experiments,
Filename, FilenameTemplate, GeneratorOptions, GeneratorOptionsMap, JavascriptParserOptions,
JavascriptParserOrder, JavascriptParserUrl, LibraryName, LibraryNonUmdObject, LibraryOptions,
Mode, ModuleNoParseRules, ModuleOptions, ModuleRule, ModuleRuleEffect, OutputOptions,
ParserOptions, ParserOptionsMap, PathInfo, PublicPath, Resolve, RspackFuture, RuleSetCondition,
RuleSetLogicalConditions, Target, TargetProperties, TrustedTypes, WasmLoading, WasmLoadingType,
};
use crate::{incremental::IncrementalPasses, ModuleType};

use super::target::{get_targets_properties, TargetProperties};
use super::{Devtool, Target};
macro_rules! d {
($o:expr, $v:expr) => {{
$o.unwrap_or($v)
Expand All @@ -36,6 +37,39 @@ macro_rules! f {
}};
}

pub trait Builder {
type Item;
fn builder() -> Self::Item;
}

impl Builder for CompilerOptions {
type Item = CompilerOptionsBuilder;
fn builder() -> Self::Item {
CompilerOptionsBuilder::default()
}
}

impl Builder for OutputOptions {
type Item = OutputOptionsBuilder;
fn builder() -> Self::Item {
OutputOptionsBuilder::default()
}
}

impl Builder for ModuleOptions {
type Item = ModuleOptionsBuilder;
fn builder() -> Self::Item {
ModuleOptionsBuilder::default()
}
}

impl Builder for Experiments {
type Item = ExperimentsBuilder;
fn builder() -> Self::Item {
ExperimentsBuilder::default()
}
}

#[derive(Debug, Default)]
pub struct CompilerOptionsBuilder {
name: Option<String>,
Expand All @@ -52,12 +86,6 @@ pub struct CompilerOptionsBuilder {
output: Option<OutputOptionsBuilder>,
}

impl CompilerOptions {
pub fn builder() -> CompilerOptionsBuilder {
CompilerOptionsBuilder::default()
}
}

impl CompilerOptionsBuilder {
pub fn name(&mut self, name: String) -> &mut Self {
self.name = Some(name);
Expand Down Expand Up @@ -230,12 +258,6 @@ pub struct ModuleOptionsBuilder {
no_parse: Option<ModuleNoParseRules>,
}

impl ModuleOptions {
pub fn builder() -> ModuleOptionsBuilder {
ModuleOptionsBuilder::default()
}
}

impl ModuleOptionsBuilder {
pub fn rule(&mut self, rule: ModuleRule) -> &mut Self {
self.rules.push(rule);
Expand Down Expand Up @@ -1074,13 +1096,13 @@ impl OutputOptionsBuilder {
});

let chunk_loading_global = f!(self.chunk_loading_global.take(), || {
format!("webpackChunk{}", crate::utils::to_identifier(&unique_name))
format!("webpackChunk{}", rspack_core::to_identifier(&unique_name))
});

let hot_update_global = f!(self.hot_update_global.take(), || {
format!(
"webpackHotUpdate{}",
crate::utils::to_identifier(&unique_name)
rspack_core::to_identifier(&unique_name)
)
});

Expand Down Expand Up @@ -1293,12 +1315,6 @@ impl OutputOptionsBuilder {
}
}

impl OutputOptions {
pub fn builder() -> OutputOptionsBuilder {
OutputOptionsBuilder::default()
}
}

#[derive(Debug, Default)]
pub struct ExperimentsBuilder {
layers: Option<bool>,
Expand All @@ -1314,11 +1330,6 @@ pub struct ExperimentsBuilder {
async_web_assembly: Option<bool>,
}

impl Experiments {
pub fn builder() -> ExperimentsBuilder {
ExperimentsBuilder::default()
}
}
impl ExperimentsBuilder {
pub fn layers(&mut self, layers: bool) -> &mut Self {
self.layers = Some(layers);
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions crates/rspack/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mod builder;
mod devtool;
mod target;

pub use builder::{
Builder, CompilerOptionsBuilder, ExperimentsBuilder, ModuleOptionsBuilder, OutputOptionsBuilder,
};
pub use devtool::Devtool;
pub use target::Target;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::Context;
use rspack_core::Context;

pub type Target = Vec<String>;

Expand Down
8 changes: 1 addition & 7 deletions crates/rspack_core/src/options/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod compiler_options;
mod compiler_options_builder;

pub use compiler_options::*;
pub use compiler_options_builder::*;

mod entry;
pub use entry::*;
mod optimizations;
Expand Down Expand Up @@ -33,7 +31,3 @@ mod filename;
pub use filename::*;
mod clean_options;
pub use clean_options::*;
mod target;
pub use target::*;
mod devtool;
pub use devtool::*;

2 comments on commit 0a4e43a

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 0a4e43a Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ecosystem CI detail: Open

suite result
modernjs ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
rsdoctor ❌ failure
examples ❌ failure
devserver ✅ success
nuxt ✅ success

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 0a4e43a Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2025-01-06 f81f1c7) Current Change
10000_big_production-mode_disable-minimize + exec 38 s ± 659 ms 37.9 s ± 558 ms -0.24 %
10000_development-mode + exec 1.91 s ± 39 ms 1.88 s ± 26 ms -1.73 %
10000_development-mode_hmr + exec 688 ms ± 25 ms 681 ms ± 37 ms -1.07 %
10000_production-mode + exec 2.51 s ± 29 ms 2.5 s ± 55 ms -0.39 %
arco-pro_development-mode + exec 1.78 s ± 139 ms 1.77 s ± 66 ms -0.73 %
arco-pro_development-mode_hmr + exec 378 ms ± 4.1 ms 377 ms ± 1.9 ms -0.21 %
arco-pro_production-mode + exec 3.61 s ± 65 ms 3.56 s ± 112 ms -1.49 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.68 s ± 100 ms 3.64 s ± 105 ms -1.01 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.64 s ± 80 ms 3.58 s ± 81 ms -1.71 %
threejs_development-mode_10x + exec 1.5 s ± 15 ms 1.52 s ± 19 ms +1.21 %
threejs_development-mode_10x_hmr + exec 771 ms ± 14 ms 800 ms ± 37 ms +3.83 %
threejs_production-mode_10x + exec 5.36 s ± 68 ms 5.37 s ± 127 ms +0.18 %
10000_big_production-mode_disable-minimize + rss memory 9499 MiB ± 279 MiB 9594 MiB ± 236 MiB +1.00 %
10000_development-mode + rss memory 666 MiB ± 20.7 MiB 685 MiB ± 21.6 MiB +2.91 %
10000_development-mode_hmr + rss memory 1433 MiB ± 386 MiB 1435 MiB ± 383 MiB +0.17 %
10000_production-mode + rss memory 623 MiB ± 22.8 MiB 672 MiB ± 27.7 MiB +7.93 %
arco-pro_development-mode + rss memory 567 MiB ± 29.5 MiB 586 MiB ± 31.5 MiB +3.42 %
arco-pro_development-mode_hmr + rss memory 625 MiB ± 64.7 MiB 619 MiB ± 57.6 MiB -0.98 %
arco-pro_production-mode + rss memory 722 MiB ± 54.8 MiB 734 MiB ± 29.8 MiB +1.71 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 712 MiB ± 54.5 MiB 752 MiB ± 53.9 MiB +5.49 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 725 MiB ± 62.4 MiB 726 MiB ± 55.7 MiB +0.16 %
threejs_development-mode_10x + rss memory 574 MiB ± 11.9 MiB 598 MiB ± 16.6 MiB +4.06 %
threejs_development-mode_10x_hmr + rss memory 1141 MiB ± 70.6 MiB 1170 MiB ± 200 MiB +2.47 %
threejs_production-mode_10x + rss memory 842 MiB ± 37.9 MiB 872 MiB ± 34.5 MiB +3.58 %

Please sign in to comment.