Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.
Closed
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
4 changes: 2 additions & 2 deletions wasm-rpc-stubgen/src/commands/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::model::app::{
DEFAULT_CONFIG_FILE_NAME,
};
use crate::model::app_raw;
use crate::stub::{RustDependencyOverride, StubConfig, StubDefinition};
use crate::stub::{RustDependencyOverride, StubConfig, StubDefinition, StubSourceTransform};
use crate::validation::{ValidatedResult, ValidationBuilder};
use crate::wit_generate::{
add_client_as_dependency_to_wit_dir, extract_exports_as_wit_dep, AddClientAsDepConfig,
Expand Down Expand Up @@ -346,7 +346,7 @@ impl<CPE: ComponentPropertiesExtensions> ApplicationContext<CPE> {
selected_world: None,
stub_crate_version: WASM_RPC_VERSION.to_string(),
golem_rust_override: self.config.golem_rust_override.clone(),
extract_source_exports_package: false,
source_transform: StubSourceTransform::None,
seal_cargo_workspace: true,
component_name: component_name.clone(),
is_ephemeral,
Expand Down
31 changes: 0 additions & 31 deletions wasm-rpc-stubgen/src/commands/dependencies.rs

This file was deleted.

7 changes: 0 additions & 7 deletions wasm-rpc-stubgen/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ use fs_extra::dir::CopyOptions;
use heck::ToSnakeCase;
use std::path::{Path, PathBuf};

pub fn generate_client(stub_def: &StubDefinition) -> anyhow::Result<()> {
let _ = generate_client_wit_dir(stub_def)?;
generate_client_cargo_toml(stub_def).context("Failed to generate the Cargo.toml file")?;
generate_stub_source(stub_def).context("Failed to generate the client Rust source")?;
Ok(())
}

pub async fn build(
stub_def: &StubDefinition,
dest_wasm: &Path,
Expand Down
3 changes: 0 additions & 3 deletions wasm-rpc-stubgen/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
/// Top level commands for generating stub WASM components
pub mod generate;

/// Top level commands for managing dependencies on stubs
pub mod dependencies;

/// Top level commands for composing stubs with user components
pub mod composition;

Expand Down
19 changes: 18 additions & 1 deletion wasm-rpc-stubgen/src/naming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub mod wit {
))
}

pub fn client_import_exports_prefix_from_client_package_name(
pub fn client_import_prefix_from_client_package_name_extract_mode(
client_package: &wit_parser::PackageName,
) -> anyhow::Result<String> {
Ok(format!(
Expand All @@ -123,6 +123,23 @@ pub mod wit {
))
}

pub fn client_import_exports_prefix_from_client_package_name_stripped_mode(
client_package: &wit_parser::PackageName,
) -> anyhow::Result<String> {
Ok(format!(
"{}:{}/",
client_package.namespace,
client_package
.name
.clone()
.strip_suffix("-client")
.ok_or_else(|| anyhow!(
"Expected \"-client\" suffix in client package name: {}",
client_package.to_string()
))?
))
}

pub fn package_dep_dir_name_from_parser(package_name: &wit_parser::PackageName) -> String {
format!("{}_{}", package_name.namespace, package_name.name)
}
Expand Down
59 changes: 54 additions & 5 deletions wasm-rpc-stubgen/src/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::model::app::ComponentName;
use crate::naming;
use crate::rust::BindingMapping;
use crate::wit_encode::EncodedWitDir;
use crate::wit_generate::extract_exports_as_wit_dep;
use crate::wit_generate::{extract_exports_as_wit_dep, strip_main_package_for_client_in_wit_dir};
use crate::wit_resolve::{PackageSource, ResolvedWitDir};
use anyhow::{anyhow, Context};
use indexmap::IndexMap;
Expand All @@ -30,14 +30,21 @@ use wit_parser::{
Results, Type, TypeDef, TypeDefKind, TypeId, TypeOwner, World, WorldId, WorldItem, WorldKey,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StubSourceTransform {
None,
ExtractExportsPackage,
StripSourcePackage,
}

#[derive(Clone, Debug)]
pub struct StubConfig {
pub source_wit_root: PathBuf,
pub client_root: PathBuf,
pub selected_world: Option<String>,
pub stub_crate_version: String,
pub golem_rust_override: RustDependencyOverride,
pub extract_source_exports_package: bool,
pub source_transform: StubSourceTransform,
pub seal_cargo_workspace: bool,
pub component_name: ComponentName,
pub is_ephemeral: bool,
Expand Down Expand Up @@ -68,9 +75,17 @@ pub struct StubDefinition {

impl StubDefinition {
pub fn new(config: StubConfig) -> anyhow::Result<Self> {
if config.extract_source_exports_package {
extract_exports_as_wit_dep(&config.source_wit_root)
.context("Failed to extract exports package")?
match config.source_transform {
StubSourceTransform::None => {
// NOP
}
StubSourceTransform::ExtractExportsPackage => {
extract_exports_as_wit_dep(&config.source_wit_root)
.context("Failed to extract exports package")?
}
StubSourceTransform::StripSourcePackage => {
strip_main_package_for_client_in_wit_dir(&config.source_wit_root)?
}
}

let resolved_source = ResolvedWitDir::new(&config.source_wit_root)?;
Expand Down Expand Up @@ -460,8 +475,42 @@ impl StubDefinition {
.filter(|function| function.kind == FunctionKind::Freestanding),
);

// TODO: ?
/*let used_function_types = functions
.iter()
.flat_map(|function| {
function
.params
.iter()
.flat_map(|param| match &param.typ {
Type::Id(id) => Some(*id),
_ => None,
})
.chain(match &function.results {
FunctionResultStub::Anon(typ) => match typ {
Type::Id(id) => vec![*id],
_ => vec![],
},
FunctionResultStub::Named(stubs) => stubs
.iter()
.flat_map(|stub| match stub.typ {
Type::Id(id) => vec![id],
_ => vec![],
})
.collect::<Vec<_>>(),
FunctionResultStub::SelfType => vec![],
})
})
.collect::<Vec<_>>();*/

let (used_types, _) = self.extract_resource_interface_stubs_from_types(types.into_iter());

// TODO
/*let used_types = used_types
.into_iter()
.chain(used_function_types)
.collect::<Vec<_>>();*/

Some(InterfaceStub {
name: name.to_string(),
functions,
Expand Down
Loading
Loading