Skip to content
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

Support invoking wasi:http/incoming-handler #1249

Merged
merged 9 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ exclude = [
"test-components/update-test-v3-11",
"test-components/update-test-v4",
"test-components/variant-service",
"test-components/wasi-http-incoming-request-handler",
"test-components/wasi-http-incoming-request-handler-echo",
"test-components/wasi-http-incoming-request-handler-state",
"test-components/write-stderr",
"test-components/write-stdout",
]
Expand Down
1 change: 1 addition & 0 deletions golem-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ prost-types = { workspace = true, optional = true }
rand = { workspace = true }
range-set-blaze = "0.1.16"
regex = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions golem-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub mod tracing;

pub mod uri;

pub mod virtual_exports;

#[cfg(test)]
test_r::enable!();

Expand Down
14 changes: 13 additions & 1 deletion golem-common/src/model/component_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use bincode::{Decode, Encode};
use std::collections::HashMap;
use std::fmt::{self, Display, Formatter};

use crate::SafeDisplay;
use crate::{virtual_exports, SafeDisplay};
use golem_wasm_ast::analysis::AnalysedFunctionParameter;
use golem_wasm_ast::core::Mem;
use golem_wasm_ast::metadata::Producers as WasmAstProducers;
Expand Down Expand Up @@ -182,6 +182,7 @@ impl RawComponentMetadata {
.map_err(ComponentProcessingError::Analysis)?;

add_resource_drops(&mut exports);
add_virtual_exports(&mut exports);

let exports = exports.into_iter().collect::<Vec<_>>();

Expand Down Expand Up @@ -327,6 +328,17 @@ fn drop_from_constructor(constructor: &AnalysedFunction) -> AnalysedFunction {
}
}

fn add_virtual_exports(exports: &mut Vec<AnalysedExport>) {
// Some interfaces like the golem/http:incoming-handler do not exist on the component,
// but are dynamically created by the worker executor based on other existing interfaces.

if virtual_exports::http_incoming_handler::implements_required_interfaces(exports) {
exports.extend(vec![
virtual_exports::http_incoming_handler::ANALYZED_EXPORT.clone(),
]);
};
}

#[cfg(feature = "protobuf")]
mod protobuf {
use crate::model::component_metadata::{
Expand Down
21 changes: 2 additions & 19 deletions golem-common/src/model/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,7 @@ use golem_wasm_ast::analysis::{AnalysedExport, AnalysedFunction, AnalysedInstanc

use rib::{ParsedFunctionName, ParsedFunctionReference, ParsedFunctionSite};

pub trait AnalysedExportExtensions {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were unused

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

fn function_names(&self) -> Vec<String>;
}

impl AnalysedExportExtensions for AnalysedExport {
fn function_names(&self) -> Vec<String> {
match self {
AnalysedExport::Instance(instance) => instance
.functions
.iter()
.map(|function| format!("{}.{{{}}}", instance.name, function.name))
.collect(),
AnalysedExport::Function(function) => vec![function.name.clone()],
}
}
}

pub fn instances(exports: &Vec<AnalysedExport>) -> Vec<AnalysedInstance> {
fn instances(exports: &Vec<AnalysedExport>) -> Vec<AnalysedInstance> {
let mut instances = vec![];
for export in exports {
if let AnalysedExport::Instance(instance) = export {
Expand All @@ -43,7 +26,7 @@ pub fn instances(exports: &Vec<AnalysedExport>) -> Vec<AnalysedInstance> {
instances
}

pub fn functions(exports: &Vec<AnalysedExport>) -> Vec<AnalysedFunction> {
fn functions(exports: &Vec<AnalysedExport>) -> Vec<AnalysedFunction> {
let mut functions = vec![];
for export in exports {
if let AnalysedExport::Function(function) = export {
Expand Down
Loading
Loading