Skip to content

Commit 981d7b1

Browse files
authoredAug 16, 2023
refactor(common): Make ahash optional (#7816)
**Description:** This adds the ability to not include `ahash` with swc_common, which caused some issues for me compiling dprint-plugin-typescript to Wasm because of: ``` Compiling ahash v0.8.3 Compiling getrandom v0.2.10 error: the wasm*-unknown-unknown targets are not supported by default, you may need to enable the "js" feature. For more information see: https://docs.rs/getrandom/#webassembly-support --> C:\Users\david\.cargo\registry\src\index.crates.io-6f17d22bba15001f\getrandom-0.2.10\src\lib.rs:285:9 | 285 | / compile_error!("the wasm*-unknown-unknown targets are not supported by \ 286 | | default, you may need to enable the \"js\" feature. \ 287 | | For more information see: \ 288 | | https://docs.rs/getrandom/#webassembly-support"); | |________________________________________________________________________^ ``` (I can't enable the JS feature because it's running the wasm file in Wasmer and also I don't support Wasi in dprint plugins) **BREAKING CHANGE:** This removes swc_common's "perf" feature and makes it the default, then adds an `ahash` feature instead. An alternative would be to make the `ahash` dep optional and part of the default features, then do `default-features = false` in the downstream crates (I think, but I'm not sure), but I figure most people will be using the perf default anyway? I'm not sure what's preferable. **Related issue:** - Closes #7729.
1 parent d5495ee commit 981d7b1

File tree

7 files changed

+13
-15
lines changed

7 files changed

+13
-15
lines changed
 

‎bindings/binding_core_wasm/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ serde = { version = "1", features = ["derive"] }
3737
serde-wasm-bindgen = "0.4.5"
3838
swc_core = { version = "0.79.59", features = [
3939
"ecma_ast_serde",
40-
"common_perf",
4140
"binding_macro_wasm",
4241
"ecma_transforms",
4342
"ecma_visit",

‎crates/swc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ url = "2.4.0"
6969
swc_atoms = { version = "0.5.8", path = "../swc_atoms" }
7070
swc_cached = { version = "0.3.17", path = "../swc_cached" }
7171
swc_common = { version = "0.31.20", path = "../swc_common", features = [
72+
"ahash",
7273
"sourcemap",
7374
"parking_lot",
7475
] }

‎crates/swc_common/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ bench = false
1919
__plugin = []
2020
__plugin_mode = []
2121
__plugin_rt = []
22+
ahash = ["dep:ahash"]
2223
concurrent = ["parking_lot"]
2324
debug = []
2425
default = []
2526
diagnostic-serde = []
26-
perf = []
2727
plugin-base = ["__plugin", "anyhow", "rkyv-impl", "diagnostic-serde"]
2828
plugin-mode = ["__plugin_mode", "plugin-base"]
2929
plugin-rt = ["__plugin_rt", "plugin-base"]
@@ -37,7 +37,7 @@ __rkyv = []
3737
rkyv-impl = ["__rkyv", "rkyv", "swc_atoms/rkyv-impl", "bytecheck"]
3838

3939
[dependencies]
40-
ahash = "0.8.3"
40+
ahash = { version = "0.8.3", optional = true }
4141
anyhow = { version = "1.0.71", optional = true }
4242
arbitrary = { version = "1", optional = true, features = ["derive"] }
4343
atty = { version = "0.2", optional = true }

‎crates/swc_common/src/collections.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#[cfg(not(feature = "perf"))]
1+
#[cfg(feature = "ahash")]
22
pub use self::ahash::*;
3-
#[cfg(feature = "perf")]
4-
pub use self::fxhash::*;
3+
#[cfg(not(feature = "ahash"))]
4+
pub use self::rustchash::*;
55

6-
#[cfg(feature = "perf")]
7-
mod fxhash {
6+
#[cfg(not(feature = "ahash"))]
7+
mod rustchash {
88
use std::{
99
collections::{HashMap, HashSet},
1010
hash::BuildHasherDefault,
@@ -19,7 +19,7 @@ mod fxhash {
1919
pub type AHashSet<V> = HashSet<V, ARandomState>;
2020
}
2121

22-
#[cfg(not(feature = "perf"))]
22+
#[cfg(feature = "ahash")]
2323
mod ahash {
2424
use std::collections::{HashMap, HashSet};
2525

‎crates/swc_common/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
//! Allows replacing operations related to thread-local variables with a trait.
2929
//!
3030
//!
31-
//! ## `perf`
31+
//! ## `ahash`
3232
//!
33-
//! Use `fxhash` instead of `ahash` for `AHashMap` and `AHashSet`.
33+
//! Use `ahash` instead of `rustc_hash` for `AHashMap` and `AHashSet`.
3434
#![deny(clippy::all)]
3535
#![cfg_attr(docsrs, feature(doc_cfg))]
3636

‎crates/swc_core/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ repository = "https://github.com/swc-project/swc.git"
99
version = "0.79.62"
1010
[package.metadata.docs.rs]
1111
features = [
12-
"common_perf",
1312
"allocator_node",
1413
"base",
1514
"base_node",
@@ -38,8 +37,8 @@ doctest = false
3837
## but changes internal logics to perform differently. These flag should be turned on in combination with
3938
## actual features. Refer build.rs for more details.
4039

41-
# swc_common/perf
42-
common_perf = ["swc_common/perf"]
40+
# swc_common/ahash
41+
common_ahash = ["swc_common/ahash"]
4342

4443
# swc_ecma_loader/cache*
4544
ecma_loader_lru = ["swc_ecma_loader/lru"]

‎crates/swc_core/tests/fixture/stub_wasm/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ anyhow = "1.0.66"
1919
serde = { version = "1", features = ["derive"] }
2020
serde-wasm-bindgen = "0.4.5"
2121
swc_core = { path = "../../../../swc_core", features = [
22-
"common_perf",
2322
"ecma_ast_serde",
2423
"binding_macro_wasm",
2524
"ecma_transforms",

0 commit comments

Comments
 (0)