diff --git a/golem-cli/src/command/component.rs b/golem-cli/src/command/component.rs index b8111d71af..2dddb749e4 100644 --- a/golem-cli/src/command/component.rs +++ b/golem-cli/src/command/component.rs @@ -327,7 +327,7 @@ impl< } => { let project_id = projects.resolve_id_or_default(project_ref).await?; - let ctx = ApplicationComponentContext::new( + let mut ctx = ApplicationComponentContext::new( app, build_profile.map(|profile| profile.into()), &component_name.0, @@ -401,7 +401,7 @@ impl< let project_id = projects.resolve_id_or_default_opt(project_ref).await?; - let ctx = ApplicationComponentContext::new( + let mut ctx = ApplicationComponentContext::new( app, build_profile.map(|profile| profile.into()), &component_name, @@ -576,15 +576,21 @@ impl ApplicationComponentContext { }) } - fn dynamic_linking(&self) -> Option { + fn dynamic_linking(&mut self) -> Option { let mapping = Vec::new(); let wasm_rpc_deps = self .app_ctx .application - .component_wasm_rpc_dependencies(&self.name); + .component_wasm_rpc_dependencies(&self.name) + .clone(); for wasm_rpc_dep in wasm_rpc_deps { + let ifaces = self + .app_ctx + .component_stub_interfaces(&wasm_rpc_dep) + .unwrap(); // TODO + println!("{:?}", ifaces); // let target_props = self // .app_ctx // .application diff --git a/golem-common/src/model/component_metadata.rs b/golem-common/src/model/component_metadata.rs index 5c4b89f4dd..c0b796268d 100644 --- a/golem-common/src/model/component_metadata.rs +++ b/golem-common/src/model/component_metadata.rs @@ -48,7 +48,7 @@ impl ComponentMetadata { } } -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, Encode, Decode)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Encode, Decode)] #[cfg_attr(feature = "poem", derive(poem_openapi::Union))] #[cfg_attr(feature = "poem", oai(discriminator_name = "type", one_of = true))] #[serde(tag = "type")] @@ -56,19 +56,22 @@ pub enum DynamicLinkedInstance { WasmRpc(DynamicLinkedWasmRpc), } -#[derive( - Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, Serialize, Deserialize, Encode, Decode, -)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Encode, Decode)] #[cfg_attr(feature = "poem", derive(poem_openapi::Object))] #[cfg_attr(feature = "poem", oai(rename_all = "camelCase"))] #[serde(rename_all = "camelCase")] pub struct DynamicLinkedWasmRpc { - pub target_interface_name: String, + /// Maps resource names within the dynamic linked interface to target interfaces + pub target_interface_name: HashMap, } impl DynamicLinkedWasmRpc { - pub fn target_site(&self) -> Result { - ParsedFunctionSite::parse(&self.target_interface_name) + pub fn target_site(&self, stub_resource: &str) -> Result { + let target_interface = self + .target_interface_name + .get(stub_resource) + .ok_or("Resource not found in dynamic linked interface")?; + ParsedFunctionSite::parse(&target_interface) } } diff --git a/wasm-rpc-stubgen/src/commands/app.rs b/wasm-rpc-stubgen/src/commands/app.rs index 097605375b..36e7212c65 100644 --- a/wasm-rpc-stubgen/src/commands/app.rs +++ b/wasm-rpc-stubgen/src/commands/app.rs @@ -61,6 +61,7 @@ pub enum ApplicationSourceMode { Explicit(Vec), } +#[derive(Debug)] pub struct ComponentStubInterfaces { stub_interface_name: String, exported_interfaces: Vec, @@ -325,14 +326,15 @@ impl ApplicationContext { version: stub_def.source_package_name.version.clone(), }; - Ok(ComponentStubInterfaces { + let result = ComponentStubInterfaces { stub_interface_name: stub_package_name.interface_id(&stub_def.target_interface_name()), - exported_interfaces: vec![stub_def + exported_interfaces: stub_def .stub_imported_interfaces() .iter() - .flat_map(|interface| interface.owner_interface.clone()) - .collect()], - }) + .filter_map(|interface| interface.owner_interface.clone()) + .collect(), + }; + Ok(result) } fn common_wit_deps(&self) -> anyhow::Result<&WitDepsResolver> { @@ -1293,8 +1295,9 @@ async fn build_stub( ); fs::create_dir_all(&target_root)?; - let result = - commands::generate::build(&stub_def, &stub_wasm, &stub_wit, ctx.config.offline).await; + let offline = ctx.config.offline; + let stub_def = ctx.component_stub_def(component_name)?; + let result = commands::generate::build(&stub_def, &stub_wasm, &stub_wit, offline).await; match result { Ok(()) => { task_result_marker.success()?;