Skip to content

Commit

Permalink
Merge branch 'main' into implement_fork
Browse files Browse the repository at this point in the history
  • Loading branch information
afsalthaj committed Jan 8, 2025
2 parents 55c2bff + 7494669 commit d61950f
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 74 deletions.
2 changes: 1 addition & 1 deletion golem-cli/src/command/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ impl ApplicationComponentContext {
for wasm_rpc_dep in wasm_rpc_deps {
let ifaces = self
.app_ctx
.component_stub_interfaces(&wasm_rpc_dep)
.component_stub_interfaces(&wasm_rpc_dep.name)
.map_err(|err| GolemError(err.to_string()))?;

mapping.push(ifaces);
Expand Down
172 changes: 109 additions & 63 deletions wasm-rpc-stubgen/src/commands/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::log::{
};
use crate::model::app::{
includes_from_yaml_file, AppBuildStep, Application, ComponentName,
ComponentPropertiesExtensions, ProfileName, DEFAULT_CONFIG_FILE_NAME,
ComponentPropertiesExtensions, DependencyType, DependentComponent, ProfileName,
DEFAULT_CONFIG_FILE_NAME,
};
use crate::model::app_raw;
use crate::stub::{StubConfig, StubDefinition};
Expand Down Expand Up @@ -394,8 +395,9 @@ async fn gen_rpc<CPE: ComponentPropertiesExtensions>(
for component_name in ctx.wit.component_order_cloned() {
create_generated_base_wit(ctx, &component_name)?;
}
for component_name in &ctx.application.all_wasm_rpc_dependencies() {
build_stub(ctx, component_name).await?;

for dep in &ctx.application.all_wasm_rpc_dependencies() {
build_stub(ctx, dep).await?;
}
}

Expand Down Expand Up @@ -460,7 +462,10 @@ async fn link_rpc<CPE: ComponentPropertiesExtensions>(
let source = ctx.application.component_source(component_name);
let dependencies = ctx
.application
.component_wasm_rpc_dependencies(component_name);
.component_wasm_rpc_dependencies(component_name)
.iter()
.filter(|dep| dep.dep_type == DependencyType::StaticWasmRpc)
.collect::<BTreeSet<_>>();
let component_wasm = ctx
.application
.component_wasm(component_name, ctx.profile());
Expand All @@ -479,7 +484,7 @@ async fn link_rpc<CPE: ComponentPropertiesExtensions>(
"linking wasm rpc dependencies ({}) into {}",
dependencies
.iter()
.map(|s| s.as_str().log_color_highlight())
.map(|s| s.name.as_str().log_color_highlight())
.join(", "),
component_name.as_str().log_color_highlight(),
));
Expand All @@ -503,7 +508,7 @@ async fn link_rpc<CPE: ComponentPropertiesExtensions>(
"WASM RPC dependencies ({}) into {}",
dependencies
.iter()
.map(|s| s.as_str().log_color_highlight())
.map(|s| s.name.as_str().log_color_highlight())
.join(", "),
component_name.as_str().log_color_highlight(),
),
Expand All @@ -512,7 +517,7 @@ async fn link_rpc<CPE: ComponentPropertiesExtensions>(

let stub_wasms = dependencies
.iter()
.map(|dep| ctx.application.stub_wasm(dep))
.map(|dep| ctx.application.stub_wasm(&dep.name))
.collect::<Vec<_>>();

commands::composition::compose(
Expand Down Expand Up @@ -614,18 +619,17 @@ pub fn clean<CPE: ComponentPropertiesExtensions>(config: Config<CPE>) -> anyhow:
log_action("Cleaning", "component stubs");
let _indent = LogIndent::new();

for component_name in app.all_wasm_rpc_dependencies() {
for dep in app.all_wasm_rpc_dependencies() {
log_action(
"Cleaning",
format!(
"component stub {}",
component_name.as_str().log_color_highlight()
),
format!("component stub {}", dep.name.as_str().log_color_highlight()),
);
let _indent = LogIndent::new();

delete_path("stub wit", &app.stub_wit(&component_name))?;
delete_path("stub wasm", &app.stub_wasm(&component_name))?;
delete_path("stub wit", &app.stub_wit(&dep.name))?;
if dep.dep_type == DependencyType::StaticWasmRpc {
delete_path("stub wasm", &app.stub_wasm(&dep.name))?;
}
}
}

Expand Down Expand Up @@ -1246,9 +1250,9 @@ fn update_cargo_toml<CPE: ComponentPropertiesExtensions>(

async fn build_stub<CPE: ComponentPropertiesExtensions>(
ctx: &mut ApplicationContext<CPE>,
component_name: &ComponentName,
component: &DependentComponent,
) -> anyhow::Result<bool> {
let stub_def = ctx.component_stub_def(component_name)?;
let stub_def = ctx.component_stub_def(&component.name)?;
let target_root = stub_def.target_wit_root();

let stub_dep_package_ids = stub_def.stub_dep_package_ids();
Expand All @@ -1261,69 +1265,111 @@ async fn build_stub<CPE: ComponentPropertiesExtensions>(
})
.collect();

let stub_wasm = ctx.application.stub_wasm(component_name);
let stub_wit = ctx.application.stub_wit(component_name);
let stub_wasm = ctx.application.stub_wasm(&component.name);
let stub_wit = ctx.application.stub_wit(&component.name);
let task_result_marker = TaskResultMarker::new(
&ctx.application.task_result_marker_dir(),
ComponentGeneratorMarkerHash {
component_name,
component_name: &component.name,
generator_kind: "stub",
},
)?;

if is_up_to_date(
ctx.config.skip_up_to_date_checks || !task_result_marker.is_up_to_date(),
|| stub_sources,
|| [stub_wit.clone(), stub_wasm.clone()],
|| {
if component.dep_type == DependencyType::StaticWasmRpc {
vec![stub_wit.clone(), stub_wasm.clone()]
} else {
vec![stub_wit.clone()]
}
},
) {
log_skipping_up_to_date(format!(
"building wasm rpc stub for {}",
component_name.as_str().log_color_highlight()
"generating wasm rpc stub for {}",
component.name.as_str().log_color_highlight()
));
Ok(false)
} else {
log_action(
"Building",
format!(
"wasm rpc stub for {}",
component_name.as_str().log_color_highlight()
),
);
let _indent = LogIndent::new();
match component.dep_type {
DependencyType::StaticWasmRpc => {
log_action(
"Building",
format!(
"wasm rpc stub for {}",
component.name.as_str().log_color_highlight()
),
);
let _indent = LogIndent::new();

delete_path("stub temp build dir", &target_root)?;
delete_path("stub wit", &stub_wit)?;
delete_path("stub wasm", &stub_wasm)?;
delete_path("stub temp build dir", &target_root)?;
delete_path("stub wit", &stub_wit)?;
delete_path("stub wasm", &stub_wasm)?;

log_action(
"Creating",
format!("stub temp build dir {}", target_root.log_color_highlight()),
);
fs::create_dir_all(&target_root)?;

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()?;

let skip_delete = std::env::var("WASM_RPC_KEEP_STUB_DIR")
.ok()
.map(|flag| {
let flag = flag.to_lowercase();
flag.starts_with("t") || flag == "1"
})
.unwrap_or_default();

if !skip_delete {
delete_path("stub temp build dir", &target_root)?;
log_action(
"Creating",
format!("stub temp build dir {}", target_root.log_color_highlight()),
);
fs::create_dir_all(&target_root)?;

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()?;

let skip_delete = std::env::var("WASM_RPC_KEEP_STUB_DIR")
.ok()
.map(|flag| {
let flag = flag.to_lowercase();
flag.starts_with("t") || flag == "1"
})
.unwrap_or_default();

if !skip_delete {
delete_path("stub temp build dir", &target_root)?;
}
Ok(true)
}
Err(err) => {
task_result_marker.failure()?;
Err(err)
}
}
Ok(true)
}
Err(err) => {
task_result_marker.failure()?;
Err(err)
DependencyType::DynamicWasmRpc => {
log_action(
"Generating",
format!(
"wasm rpc stub for {}",
component.name.as_str().log_color_highlight()
),
);
let _indent = LogIndent::new();

delete_path("stub wit", &stub_wit)?;

log_action(
"Creating",
format!("stub temp build dir {}", target_root.log_color_highlight()),
);
fs::create_dir_all(&target_root)?;

let stub_def = ctx.component_stub_def(&component.name)?;
let result = commands::generate::generate_and_copy_stub_wit(stub_def, &stub_wit);
match result {
Ok(_) => {
task_result_marker.success()?;
Ok(true)
}
Err(err) => {
task_result_marker.failure()?;
Err(err)
}
}
}
}
}
Expand All @@ -1349,19 +1395,19 @@ fn add_stub_deps<CPE: ComponentPropertiesExtensions>(

let _indent = LogIndent::new();

for dep_component_name in dependencies {
for dep_component in dependencies {
log_action(
"Adding",
format!(
"{} stub wit dependency to {}",
dep_component_name.as_str().log_color_highlight(),
dep_component.name.as_str().log_color_highlight(),
component_name.as_str().log_color_highlight()
),
);
let _indent = LogIndent::new();

add_stub_as_dependency_to_wit_dir(AddStubAsDepConfig {
stub_wit_root: ctx.application.stub_wit(dep_component_name),
stub_wit_root: ctx.application.stub_wit(&dep_component.name),
dest_wit_root: ctx
.application
.component_generated_wit(component_name, ctx.profile()),
Expand Down
15 changes: 15 additions & 0 deletions wasm-rpc-stubgen/src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ pub async fn build(
Ok(())
}

pub fn generate_and_copy_stub_wit(
stub_def: &StubDefinition,
dest_wit_root: &Path,
) -> anyhow::Result<()> {
let _ = generate_stub_wit_dir(stub_def)?;
fs::create_dir_all(dest_wit_root).context("Failed to create the target WIT root directory")?;
fs_extra::dir::copy(
stub_def.config.target_root.join(naming::wit::WIT_DIR),
dest_wit_root,
&CopyOptions::new().content_only(true).overwrite(true),
)
.context("Failed to copy the generated WIT files to the destination")?;
Ok(())
}

pub async fn generate_and_build_stub(
stub_def: &StubDefinition,
offline: bool,
Expand Down
Loading

0 comments on commit d61950f

Please sign in to comment.