Skip to content

Commit 10d2e21

Browse files
authored
wasm-tools, wit-parser: add --all-features to enable all features gated with @unstable (#1599)
* wasm-tools, wit-parser: add --all-features to enable all features gated with @unstable * wasm-tools: put logic for --all-features into WitResolve::resolve_with_features * wit-parser, wasm-tools: --all-features is now an alias for --features * * wasm-tools, wit-parser: --features . instead of * to imply --all-features * wasm-tools: document --features . as alias for --all-features * tests/cli: add tests for --all-features and --features . * wasm-tools: rustfmt * wasm-tools: remove --features . as alias for --all-features
1 parent 1e537ed commit 10d2e21

4 files changed

Lines changed: 64 additions & 5 deletions

File tree

crates/wit-parser/src/resolve.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ pub struct Resolve {
7474
/// set.
7575
#[cfg_attr(feature = "serde", serde(skip))]
7676
pub features: IndexSet<String>,
77+
78+
/// Activate all features for this [`Resolve`].
79+
#[cfg_attr(feature = "serde", serde(skip))]
80+
pub all_features: bool,
7781
}
7882

7983
/// A WIT package within a `Resolve`.
@@ -1142,7 +1146,7 @@ impl Resolve {
11421146
fn include_stability(&self, stability: &Stability) -> bool {
11431147
match stability {
11441148
Stability::Stable { .. } | Stability::Unknown => true,
1145-
Stability::Unstable { feature } => self.features.contains(feature),
1149+
Stability::Unstable { feature } => self.features.contains(feature) || self.all_features,
11461150
}
11471151
}
11481152
}

src/bin/wasm-tools/component.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,19 @@ struct WitResolve {
182182
/// items are otherwise hidden by default.
183183
#[clap(long)]
184184
features: Vec<String>,
185+
186+
/// Enable all features when parsing the `wit` option.
187+
///
188+
/// This flag enables all `@unstable` features in WIT documents where the
189+
/// items are otherwise hidden by default.
190+
#[clap(long)]
191+
all_features: bool,
185192
}
186193

187194
impl WitResolve {
188-
fn resolve_with_features(features: &[String]) -> Resolve {
195+
fn resolve_with_features(features: &[String], all_features: bool) -> Resolve {
189196
let mut resolve = Resolve::default();
197+
resolve.all_features = all_features;
190198
for feature in features {
191199
for f in feature.split_whitespace() {
192200
for f in f.split(',').filter(|s| !s.is_empty()) {
@@ -198,7 +206,7 @@ impl WitResolve {
198206
}
199207

200208
fn load(&self) -> Result<(Resolve, Vec<PackageId>)> {
201-
let mut resolve = Self::resolve_with_features(&self.features);
209+
let mut resolve = Self::resolve_with_features(&self.features, self.all_features);
202210
let (pkg_ids, _) = resolve.push_path(&self.wit)?;
203211
Ok((resolve, pkg_ids))
204212
}
@@ -494,6 +502,13 @@ pub struct WitOpts {
494502
/// items are otherwise hidden by default.
495503
#[clap(long)]
496504
features: Vec<String>,
505+
506+
/// Enable all features when parsing the `wit` option.
507+
///
508+
/// This flag enables all `@unstable` features in WIT documents where the
509+
/// items are otherwise hidden by default.
510+
#[clap(long)]
511+
all_features: bool,
497512
}
498513

499514
impl WitOpts {
@@ -524,7 +539,8 @@ impl WitOpts {
524539
// `parse_wit_from_path`.
525540
if let Some(input) = &self.input {
526541
if input.is_dir() {
527-
let mut resolve = WitResolve::resolve_with_features(&self.features);
542+
let mut resolve =
543+
WitResolve::resolve_with_features(&self.features, self.all_features);
528544
let (pkg_ids, _) = resolve.push_dir(&input)?;
529545
return Ok(DecodedWasm::WitPackages(resolve, pkg_ids));
530546
}
@@ -572,7 +588,8 @@ impl WitOpts {
572588
Ok(s) => s,
573589
Err(_) => bail!("input was not valid utf-8"),
574590
};
575-
let mut resolve = WitResolve::resolve_with_features(&self.features);
591+
let mut resolve =
592+
WitResolve::resolve_with_features(&self.features, self.all_features);
576593
let pkgs = UnresolvedPackageGroup::parse(path, input)?;
577594
let ids = resolve.append(pkgs)?;
578595
Ok(DecodedWasm::WitPackages(resolve, ids))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: component wit --all-features %
2+
3+
package a:b;
4+
5+
@unstable(feature = foo)
6+
interface foo {
7+
@unstable(feature = foo)
8+
type t = u32;
9+
}
10+
11+
@unstable(feature = bar)
12+
interface bar {
13+
@unstable(feature = baz)
14+
use foo.{t};
15+
16+
@unstable(feature = qux)
17+
record x { y: t }
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// RUN: component wit --all-features %
2+
package a:b;
3+
4+
@unstable(feature = foo)
5+
interface foo {
6+
@unstable(feature = foo)
7+
type t = u32;
8+
}
9+
10+
@unstable(feature = bar)
11+
interface bar {
12+
@unstable(feature = baz)
13+
use foo.{t};
14+
15+
@unstable(feature = qux)
16+
record x {
17+
y: t,
18+
}
19+
}
20+

0 commit comments

Comments
 (0)