Skip to content

Commit

Permalink
Merge pull request #147 from lann/unstable
Browse files Browse the repository at this point in the history
Include unstable features in published packages
  • Loading branch information
lann authored Jan 31, 2025
2 parents c6bd2aa + 2b568a6 commit 1361b55
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 167 deletions.
100 changes: 12 additions & 88 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ futures-util = "0.3.30"
oci-client = { version = "0.14", default-features = false, features = [
"rustls-tls",
] }
oci-wasm = { version = "0.2", default-features = false, features = [
oci-wasm = { version = "0.2.1", default-features = false, features = [
"rustls-tls",
] }
semver = "1.0.23"
Expand Down
7 changes: 6 additions & 1 deletion crates/wasm-pkg-core/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ impl DecodedDependency<'_> {
match self {
Self::Wit { package, .. } => {
let mut resolve = Resolve::new();
resolve.all_features = true;
let source_files = package
.source_map
.source_files()
Expand Down Expand Up @@ -677,7 +678,11 @@ impl DependencyResolutionMap {
/// Given a path to a component or a directory containing wit, use the given dependencies to
/// generate a [`Resolve`] for the root package.
pub async fn generate_resolve(&self, dir: impl AsRef<Path>) -> Result<(Resolve, PackageId)> {
let mut merged = Resolve::default();
let mut merged = Resolve {
// Retain @unstable features; downstream tooling will process them further
all_features: true,
..Resolve::default()
};

let deps = self.decode_dependencies().await?;

Expand Down
34 changes: 24 additions & 10 deletions crates/wasm-pkg-core/tests/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use wasm_pkg_core::{config::Config as WkgConfig, lock::LockFile};
use wit_component::DecodedWasm;
use wit_parser::Stability;

mod common;

Expand Down Expand Up @@ -28,7 +29,7 @@ async fn test_build_wit() {
);
assert_eq!(
version.unwrap().to_string(),
"0.2.0",
"0.2.3",
"Should have the correct version"
);

Expand All @@ -53,18 +54,31 @@ async fn test_build_wit() {
_ => panic!("Should be a package"),
};

let name = resolve
.package_names
.iter()
.find_map(|(name, id)| (pkg_id == *id).then_some(name))
.expect("Should be able to find the package name");
let package = resolve
.packages
.get(pkg_id)
.expect("Should contain decoded package");

assert_eq!(
name.to_string(),
"wasi:[email protected].0",
package.name.to_string(),
"wasi:[email protected].3",
"Should have the correct package name"
);

// @unstable items are retained
let types_id = package
.interfaces
.get("types")
.expect("wasi:http should have a types interface");
let send_informational = resolve.interfaces[*types_id]
.functions
.get("[method]response-outparam.send-informational")
.expect("Should have send-informational method");
assert!(
matches!(send_informational.stability, Stability::Unstable { .. }),
"response-outparam.send-informational should be unstable"
);

assert!(
resolve.package_direct_deps(pkg_id).count() > 0,
"Should have direct dependencies embedded"
Expand All @@ -85,8 +99,8 @@ async fn test_bad_dep_failure() {
.await
.expect("Should be able to read the world file");
let str_world = str_world.replace(
"import wasi:cli/[email protected].0;",
"import totally:not/[email protected].0;",
"import wasi:cli/[email protected].3;",
"import totally:not/[email protected].3;",
);
tokio::fs::write(world_file, str_world)
.await
Expand Down
6 changes: 6 additions & 0 deletions crates/wasm-pkg-core/tests/fixtures/wasi-http/wit/handler.wit
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// This interface defines a handler of incoming HTTP Requests. It should
/// be exported by components which can respond to HTTP Requests.
@since(version = 0.2.0)
interface incoming-handler {
@since(version = 0.2.0)
use types.{incoming-request, response-outparam};

/// This function is invoked with an incoming HTTP Request, and a resource
Expand All @@ -13,6 +15,7 @@ interface incoming-handler {
/// The implementor of this function must write a response to the
/// `response-outparam` before returning, or else the caller will respond
/// with an error on its behalf.
@since(version = 0.2.0)
handle: func(
request: incoming-request,
response-out: response-outparam
Expand All @@ -21,7 +24,9 @@ interface incoming-handler {

/// This interface defines a handler of outgoing HTTP Requests. It should be
/// imported by components which wish to make HTTP Requests.
@since(version = 0.2.0)
interface outgoing-handler {
@since(version = 0.2.0)
use types.{
outgoing-request, request-options, future-incoming-response, error-code
};
Expand All @@ -36,6 +41,7 @@ interface outgoing-handler {
/// This function may return an error if the `outgoing-request` is invalid
/// or not allowed to be made. Otherwise, protocol errors are reported
/// through the `future-incoming-response`.
@since(version = 0.2.0)
handle: func(
request: outgoing-request,
options: option<request-options>
Expand Down
40 changes: 29 additions & 11 deletions crates/wasm-pkg-core/tests/fixtures/wasi-http/wit/proxy.wit
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
package wasi:http@0.2.0;
package wasi:http@0.2.3;

/// The `wasi:http/proxy` world captures a widely-implementable intersection of
/// hosts that includes HTTP forward and reverse proxies. Components targeting
/// this world may concurrently stream in and out any number of incoming and
/// outgoing HTTP requests.
world proxy {
/// The `wasi:http/imports` world imports all the APIs for HTTP proxies.
/// It is intended to be `include`d in other worlds.
@since(version = 0.2.0)
world imports {
/// HTTP proxies have access to time and randomness.
include wasi:clocks/imports@0.2.0;
import wasi:random/random@0.2.0;
@since(version = 0.2.0)
import wasi:clocks/monotonic-clock@0.2.3;
@since(version = 0.2.0)
import wasi:clocks/wall-clock@0.2.3;
@since(version = 0.2.0)
import wasi:random/random@0.2.3;

/// Proxies have standard output and error streams which are expected to
/// terminate in a developer-facing console provided by the host.
import wasi:cli/stdout@0.2.0;
import wasi:cli/stderr@0.2.0;
@since(version = 0.2.0)
import wasi:cli/stdout@0.2.3;
@since(version = 0.2.0)
import wasi:cli/stderr@0.2.3;

/// TODO: this is a temporary workaround until component tooling is able to
/// gracefully handle the absence of stdin. Hosts must return an eof stream
/// for this import, which is what wasi-libc + tooling will do automatically
/// when this import is properly removed.
import wasi:cli/stdin@0.2.0;
@since(version = 0.2.0)
import wasi:cli/stdin@0.2.3;

/// This is the default handler to use when user code simply wants to make an
/// HTTP request (e.g., via `fetch()`).
@since(version = 0.2.0)
import outgoing-handler;
}

/// The `wasi:http/proxy` world captures a widely-implementable intersection of
/// hosts that includes HTTP forward and reverse proxies. Components targeting
/// this world may concurrently stream in and out any number of incoming and
/// outgoing HTTP requests.
@since(version = 0.2.0)
world proxy {
@since(version = 0.2.0)
include imports;

/// The host delivers incoming HTTP requests to a component by calling the
/// `handle` function of this exported interface. A host may arbitrarily reuse
/// or not reuse component instance when delivering incoming HTTP requests and
/// thus a component must be able to handle 0..N calls to `handle`.
@since(version = 0.2.0)
export incoming-handler;
}
Loading

0 comments on commit 1361b55

Please sign in to comment.