Skip to content

refactor: 'features' -> 'feature' in WIT & Rust component #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
6 changes: 3 additions & 3 deletions crates/spidermonkey-embedding-splicer/src/bin/splicer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::str::FromStr;
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};

use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;
use spidermonkey_embedding_splicer::{splice, stub_wasi};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -85,7 +85,7 @@ fn main() -> Result<()> {
let wit_path_str = wit_path.as_ref().map(|p| p.to_string_lossy().to_string());
let features = features
.iter()
.map(|v| Features::from_str(v))
.map(|v| Feature::from_str(v))
.collect::<Result<Vec<_>>>()?;

let result = stub_wasi::stub_wasi(wasm, features, None, wit_path_str, world_name)
Expand Down Expand Up @@ -120,7 +120,7 @@ fn main() -> Result<()> {

let features = features
.iter()
.map(|v| Features::from_str(v))
.map(|v| Feature::from_str(v))
.collect::<Result<Vec<_>>>()?;

let result =
Expand Down
8 changes: 4 additions & 4 deletions crates/spidermonkey-embedding-splicer/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use wit_component::StringEncoding;
use wit_parser::abi::WasmType;
use wit_parser::abi::{AbiVariant, WasmSignature};

use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;

use crate::{uwrite, uwriteln};

Expand Down Expand Up @@ -108,7 +108,7 @@ struct JsBindgen<'a> {
imported_resources: BTreeSet<TypeId>,

/// Features that were enabled at the time of generation
features: &'a Vec<Features>,
features: &'a Vec<Feature>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -139,7 +139,7 @@ pub struct Componentization {
pub fn componentize_bindgen(
resolve: &Resolve,
wid: WorldId,
features: &Vec<Features>,
features: &Vec<Feature>,
) -> Result<Componentization> {
let mut bindgen = JsBindgen {
src: Source::default(),
Expand Down Expand Up @@ -407,7 +407,7 @@ impl JsBindgen<'_> {
// Skip bindings generation for wasi:http/incoming-handler if the fetch-event
// feature was enabled. We expect that the built-in engine implementation will be used
if name.starts_with("wasi:http/incoming-handler@0.2.")
&& self.features.contains(&Features::FetchEvent)
&& self.features.contains(&Feature::FetchEvent)
{
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions crates/spidermonkey-embedding-splicer/src/splice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use wit_parser::Resolve;

use crate::bindgen::BindingItem;
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::{
CoreFn, CoreTy, Features, SpliceResult,
CoreFn, CoreTy, Feature, SpliceResult,
};
use crate::{bindgen, map_core_fn, parse_wit, splice};

Expand All @@ -32,7 +32,7 @@ use crate::{bindgen, map_core_fn, parse_wit, splice};
// }
pub fn splice_bindings(
engine: Vec<u8>,
features: Vec<Features>,
features: Vec<Feature>,
wit_source: Option<String>,
wit_path: Option<String>,
world_name: Option<String>,
Expand Down Expand Up @@ -340,7 +340,7 @@ pub fn splice(
engine: Vec<u8>,
imports: Vec<(String, String, CoreFn, Option<i32>)>,
exports: Vec<(String, CoreFn)>,
features: Vec<Features>,
features: Vec<Feature>,
debug: bool,
) -> Result<Vec<u8>> {
let mut module = Module::parse(&engine, false).unwrap();
Expand All @@ -351,7 +351,7 @@ pub fn splice(

// if 'fetch-event' feature is disabled (default being default-enabled),
// remove the built-in incoming-handler which is built around it's use.
if !features.contains(&Features::FetchEvent) {
if !features.contains(&Feature::FetchEvent) {
remove_if_exported_by_js(
&mut module,
&exports,
Expand Down
18 changes: 9 additions & 9 deletions crates/spidermonkey-embedding-splicer/src/stub_wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use wasmparser::{MemArg, TypeRef};
use wit_parser::Resolve;

use crate::parse_wit;
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;

const WASI_VERSIONS: [&str; 4] = ["0.2.0", "0.2.1", "0.2.2", "0.2.3"];

Expand Down Expand Up @@ -96,7 +96,7 @@ fn unreachable_stub(body: &mut FunctionBuilder) -> Result<Vec<LocalID>> {

pub fn stub_wasi(
wasm: Vec<u8>,
features: Vec<Features>,
features: Vec<Feature>,
wit_source: Option<String>,
wit_path: Option<String>,
world_name: Option<String>,
Expand Down Expand Up @@ -127,25 +127,25 @@ pub fn stub_wasi(
stub_filesystem(&mut module, &target_world_imports)?;
stub_cli(&mut module, &target_world_imports)?;

if !features.contains(&Features::Random) {
if !features.contains(&Feature::Random) {
stub_random(&mut module)?;
}

if !features.contains(&Features::Clocks) {
if !features.contains(&Feature::Clocks) {
stub_clocks(&mut module)?;
}

if !features.contains(&Features::Stdio) {
if !features.contains(&Feature::Stdio) {
stub_stdio(&mut module)?;
}

if !features.contains(&Features::Http) && !features.contains(&Features::FetchEvent) {
if !features.contains(&Feature::Http) && !features.contains(&Feature::FetchEvent) {
stub_http(&mut module)?;
}

let has_io = features.contains(&Features::Clocks)
|| features.contains(&Features::Stdio)
|| features.contains(&Features::Http)
let has_io = features.contains(&Feature::Clocks)
|| features.contains(&Feature::Stdio)
|| features.contains(&Feature::Http)
|| target_world_requires_io(&target_world_imports);
if !has_io {
stub_io(&mut module)?;
Expand Down
14 changes: 7 additions & 7 deletions crates/spidermonkey-embedding-splicer/src/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ wit_bindgen::generate!({
pub_export_macro: true
});

use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Features;
use crate::wit::exports::local::spidermonkey_embedding_splicer::splicer::Feature;

impl std::str::FromStr for Features {
impl std::str::FromStr for Feature {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self> {
match s {
"stdio" => Ok(Features::Stdio),
"clocks" => Ok(Features::Clocks),
"random" => Ok(Features::Random),
"http" => Ok(Features::Http),
"fetch-event" => Ok(Features::FetchEvent),
"stdio" => Ok(Feature::Stdio),
"clocks" => Ok(Feature::Clocks),
"random" => Ok(Feature::Random),
"http" => Ok(Feature::Http),
"fetch-event" => Ok(Feature::FetchEvent),
_ => bail!("unrecognized feature string [{s}]"),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface splicer {
%f64
}

enum features {
enum feature {
stdio,
clocks,
random,
Expand Down Expand Up @@ -37,7 +37,7 @@ interface splicer {
/// imports may be stubbed (for example to be made unreachable).
stub-wasi: func(
engine: list<u8>,
features: list<features>,
features: list<feature>,
wit-world: option<string>,
wit-path: option<string>,
world-name: option<string>
Expand All @@ -47,7 +47,7 @@ interface splicer {
/// this function produces a new WebAssembly component
splice-bindings: func(
spidermonkey-engine: list<u8>,
features: list<features>,
features: list<feature>,
wit-world: option<string>,
wit-path: option<string>,
world-name: option<string>,
Expand Down
6 changes: 3 additions & 3 deletions crates/splicer-component/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use spidermonkey_embedding_splicer::stub_wasi::stub_wasi;
use spidermonkey_embedding_splicer::wit::{self, export};
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::{Features, Guest, SpliceResult};
use spidermonkey_embedding_splicer::wit::exports::local::spidermonkey_embedding_splicer::splicer::{Feature, Guest, SpliceResult};
use spidermonkey_embedding_splicer::splice;

struct SpidermonkeyEmbeddingSplicerComponent;

impl Guest for SpidermonkeyEmbeddingSplicerComponent {
fn stub_wasi(
wasm: Vec<u8>,
features: Vec<Features>,
features: Vec<Feature>,
wit_source: Option<String>,
wit_path: Option<String>,
world_name: Option<String>,
Expand All @@ -18,7 +18,7 @@ impl Guest for SpidermonkeyEmbeddingSplicerComponent {

fn splice_bindings(
engine: Vec<u8>,
features: Vec<Features>,
features: Vec<Feature>,
wit_source: Option<String>,
wit_path: Option<String>,
world_name: Option<String>,
Expand Down
Loading