Skip to content

Commit

Permalink
unify WIT files (fermyon#2283)
Browse files Browse the repository at this point in the history
* unify WIT files

This addresses two issues:

- When upgrading to WASI 0.2.0, I briefly considered bumping the `fermyon:spin`
  package version to 2.2.0 and updating the Rust and Go SDKs to use WASI 0.2.0.
  I later decided against that due to semver concerns, but forgot to change the
  package version back to 2.0.0.  Complicating things further was that the
  package version under wit-2023-10-18 was still 2.0.0, and that's the one we
  were actually using in `spin-core`, so we didn't notice there was a problem
  until someone tried to use the version under wit-0.2.0 instead.

- Having three separate WIT directories with inconsistent duplicates is
  obviously confusing, so I've unified them.  This unfortunately resulted in a
  lot of (superficial) code changes since `wit-bindgen` now needs to generate
  separate modules for various WASI package versions, but at least we've
  eliminated the duplication and ambiguity.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

* use aliases to omit versions in wasi compat modules

Signed-off-by: Joel Dice <joel.dice@fermyon.com>

---------

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
  • Loading branch information
dicej authored Feb 16, 2024
1 parent 5c7ad91 commit d2e89d8
Show file tree
Hide file tree
Showing 161 changed files with 258 additions and 1,074 deletions.
190 changes: 105 additions & 85 deletions crates/core/src/wasi_2023_10_18.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,91 +14,111 @@ mod latest {
}
}

wasmtime::component::bindgen!({
path: "../../wit-2023-10-18",
interfaces: r#"
include wasi:http/proxy@0.2.0-rc-2023-10-18;
// NB: this is handling the historical behavior where Spin supported
// more than "just" this snaphsot of the proxy world but additionally
// other CLI-related interfaces.
include wasi:cli/reactor@0.2.0-rc-2023-10-18;
"#,
async: {
only_imports: [
"[method]descriptor.access-at",
"[method]descriptor.advise",
"[method]descriptor.change-directory-permissions-at",
"[method]descriptor.change-file-permissions-at",
"[method]descriptor.create-directory-at",
"[method]descriptor.get-flags",
"[method]descriptor.get-type",
"[method]descriptor.is-same-object",
"[method]descriptor.link-at",
"[method]descriptor.lock-exclusive",
"[method]descriptor.lock-shared",
"[method]descriptor.metadata-hash",
"[method]descriptor.metadata-hash-at",
"[method]descriptor.open-at",
"[method]descriptor.read",
"[method]descriptor.read-directory",
"[method]descriptor.readlink-at",
"[method]descriptor.remove-directory-at",
"[method]descriptor.rename-at",
"[method]descriptor.set-size",
"[method]descriptor.set-times",
"[method]descriptor.set-times-at",
"[method]descriptor.stat",
"[method]descriptor.stat-at",
"[method]descriptor.symlink-at",
"[method]descriptor.sync",
"[method]descriptor.sync-data",
"[method]descriptor.try-lock-exclusive",
"[method]descriptor.try-lock-shared",
"[method]descriptor.unlink-file-at",
"[method]descriptor.unlock",
"[method]descriptor.write",
"[method]input-stream.read",
"[method]input-stream.blocking-read",
"[method]input-stream.blocking-skip",
"[method]input-stream.skip",
"[method]output-stream.forward",
"[method]output-stream.splice",
"[method]output-stream.blocking-splice",
"[method]output-stream.blocking-flush",
"[method]output-stream.blocking-write",
"[method]output-stream.blocking-write-and-flush",
"[method]output-stream.blocking-write-zeroes-and-flush",
"[method]directory-entry-stream.read-directory-entry",
"poll-list",
"poll-one",
],
},
with: {
"wasi:io/poll/pollable": latest::io::poll::Pollable,
"wasi:io/streams/input-stream": latest::io::streams::InputStream,
"wasi:io/streams/output-stream": latest::io::streams::OutputStream,
"wasi:io/streams/error": latest::io::streams::Error,
"wasi:filesystem/types/directory-entry-stream": latest::filesystem::types::DirectoryEntryStream,
"wasi:filesystem/types/descriptor": latest::filesystem::types::Descriptor,
"wasi:cli/terminal-input/terminal-input": latest::cli::terminal_input::TerminalInput,
"wasi:cli/terminal-output/terminal-output": latest::cli::terminal_output::TerminalOutput,
"wasi:sockets/tcp/tcp-socket": latest::sockets::tcp::TcpSocket,
"wasi:sockets/udp/udp-socket": UdpSocket,
"wasi:sockets/network/network": latest::sockets::network::Network,
"wasi:sockets/ip-name-lookup/resolve-address-stream": latest::sockets::ip_name_lookup::ResolveAddressStream,
"wasi:http/types/incoming-response": latest::http::types::IncomingResponse,
"wasi:http/types/incoming-request": latest::http::types::IncomingRequest,
"wasi:http/types/incoming-body": latest::http::types::IncomingBody,
"wasi:http/types/outgoing-response": latest::http::types::OutgoingResponse,
"wasi:http/types/outgoing-request": latest::http::types::OutgoingRequest,
"wasi:http/types/outgoing-body": latest::http::types::OutgoingBody,
"wasi:http/types/fields": latest::http::types::Fields,
"wasi:http/types/response-outparam": latest::http::types::ResponseOutparam,
"wasi:http/types/future-incoming-response": latest::http::types::FutureIncomingResponse,
"wasi:http/types/future-trailers": latest::http::types::FutureTrailers,
},
});
mod bindings {
use super::latest;
pub use super::UdpSocket;

wasmtime::component::bindgen!({
path: "../../wit",
interfaces: r#"
include wasi:http/proxy@0.2.0-rc-2023-10-18;
// NB: this is handling the historical behavior where Spin supported
// more than "just" this snaphsot of the proxy world but additionally
// other CLI-related interfaces.
include wasi:cli/reactor@0.2.0-rc-2023-10-18;
"#,
async: {
only_imports: [
"[method]descriptor.access-at",
"[method]descriptor.advise",
"[method]descriptor.change-directory-permissions-at",
"[method]descriptor.change-file-permissions-at",
"[method]descriptor.create-directory-at",
"[method]descriptor.get-flags",
"[method]descriptor.get-type",
"[method]descriptor.is-same-object",
"[method]descriptor.link-at",
"[method]descriptor.lock-exclusive",
"[method]descriptor.lock-shared",
"[method]descriptor.metadata-hash",
"[method]descriptor.metadata-hash-at",
"[method]descriptor.open-at",
"[method]descriptor.read",
"[method]descriptor.read-directory",
"[method]descriptor.readlink-at",
"[method]descriptor.remove-directory-at",
"[method]descriptor.rename-at",
"[method]descriptor.set-size",
"[method]descriptor.set-times",
"[method]descriptor.set-times-at",
"[method]descriptor.stat",
"[method]descriptor.stat-at",
"[method]descriptor.symlink-at",
"[method]descriptor.sync",
"[method]descriptor.sync-data",
"[method]descriptor.try-lock-exclusive",
"[method]descriptor.try-lock-shared",
"[method]descriptor.unlink-file-at",
"[method]descriptor.unlock",
"[method]descriptor.write",
"[method]input-stream.read",
"[method]input-stream.blocking-read",
"[method]input-stream.blocking-skip",
"[method]input-stream.skip",
"[method]output-stream.forward",
"[method]output-stream.splice",
"[method]output-stream.blocking-splice",
"[method]output-stream.blocking-flush",
"[method]output-stream.blocking-write",
"[method]output-stream.blocking-write-and-flush",
"[method]output-stream.blocking-write-zeroes-and-flush",
"[method]directory-entry-stream.read-directory-entry",
"poll-list",
"poll-one",
],
},
with: {
"wasi:io/poll/pollable": latest::io::poll::Pollable,
"wasi:io/streams/input-stream": latest::io::streams::InputStream,
"wasi:io/streams/output-stream": latest::io::streams::OutputStream,
"wasi:io/streams/error": latest::io::streams::Error,
"wasi:filesystem/types/directory-entry-stream": latest::filesystem::types::DirectoryEntryStream,
"wasi:filesystem/types/descriptor": latest::filesystem::types::Descriptor,
"wasi:cli/terminal-input/terminal-input": latest::cli::terminal_input::TerminalInput,
"wasi:cli/terminal-output/terminal-output": latest::cli::terminal_output::TerminalOutput,
"wasi:sockets/tcp/tcp-socket": latest::sockets::tcp::TcpSocket,
"wasi:sockets/udp/udp-socket": UdpSocket,
"wasi:sockets/network/network": latest::sockets::network::Network,
"wasi:sockets/ip-name-lookup/resolve-address-stream": latest::sockets::ip_name_lookup::ResolveAddressStream,
"wasi:http/types/incoming-response": latest::http::types::IncomingResponse,
"wasi:http/types/incoming-request": latest::http::types::IncomingRequest,
"wasi:http/types/incoming-body": latest::http::types::IncomingBody,
"wasi:http/types/outgoing-response": latest::http::types::OutgoingResponse,
"wasi:http/types/outgoing-request": latest::http::types::OutgoingRequest,
"wasi:http/types/outgoing-body": latest::http::types::OutgoingBody,
"wasi:http/types/fields": latest::http::types::Fields,
"wasi:http/types/response-outparam": latest::http::types::ResponseOutparam,
"wasi:http/types/future-incoming-response": latest::http::types::FutureIncomingResponse,
"wasi:http/types/future-trailers": latest::http::types::FutureTrailers,
},
});
}

mod wasi {
pub use super::bindings::wasi::{
cli0_2_0_rc_2023_10_18 as cli, clocks0_2_0_rc_2023_10_18 as clocks,
filesystem0_2_0_rc_2023_10_18 as filesystem, http0_2_0_rc_2023_10_18 as http,
io0_2_0_rc_2023_10_18 as io, random0_2_0_rc_2023_10_18 as random,
sockets0_2_0_rc_2023_10_18 as sockets,
};
}

pub mod exports {
pub mod wasi {
pub use super::super::bindings::exports::wasi::http0_2_0_rc_2023_10_18 as http;
}
}

use wasi::cli::terminal_input::TerminalInput;
use wasi::cli::terminal_output::TerminalOutput;
Expand Down
179 changes: 99 additions & 80 deletions crates/core/src/wasi_2023_11_10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,86 +14,105 @@ mod latest {
}
}

wasmtime::component::bindgen!({
path: "../../wit-2023-11-10",
interfaces: r#"
include wasi:http/proxy@0.2.0-rc-2023-11-10;
// NB: this is handling the historical behavior where Spin supported
// more than "just" this snapshot of the proxy world but additionally
// other CLI-related interfaces.
include wasi:cli/reactor@0.2.0-rc-2023-11-10;
"#,
async: {
only_imports: [
"[method]descriptor.advise",
"[method]descriptor.create-directory-at",
"[method]descriptor.get-flags",
"[method]descriptor.get-type",
"[method]descriptor.is-same-object",
"[method]descriptor.link-at",
"[method]descriptor.metadata-hash",
"[method]descriptor.metadata-hash-at",
"[method]descriptor.open-at",
"[method]descriptor.read",
"[method]descriptor.read-directory",
"[method]descriptor.readlink-at",
"[method]descriptor.remove-directory-at",
"[method]descriptor.rename-at",
"[method]descriptor.set-size",
"[method]descriptor.set-times",
"[method]descriptor.set-times-at",
"[method]descriptor.stat",
"[method]descriptor.stat-at",
"[method]descriptor.symlink-at",
"[method]descriptor.sync",
"[method]descriptor.sync-data",
"[method]descriptor.unlink-file-at",
"[method]descriptor.write",
"[method]input-stream.read",
"[method]input-stream.blocking-read",
"[method]input-stream.blocking-skip",
"[method]input-stream.skip",
"[method]output-stream.splice",
"[method]output-stream.blocking-splice",
"[method]output-stream.blocking-flush",
"[method]output-stream.blocking-write",
"[method]output-stream.blocking-write-and-flush",
"[method]output-stream.blocking-write-zeroes-and-flush",
"[method]directory-entry-stream.read-directory-entry",
"[method]pollable.block",
"[method]pollable.ready",
"poll",
]
},
with: {
"wasi:io/poll/pollable": latest::io::poll::Pollable,
"wasi:io/streams/input-stream": latest::io::streams::InputStream,
"wasi:io/streams/output-stream": latest::io::streams::OutputStream,
"wasi:io/error/error": latest::io::error::Error,
"wasi:filesystem/types/directory-entry-stream": latest::filesystem::types::DirectoryEntryStream,
"wasi:filesystem/types/descriptor": latest::filesystem::types::Descriptor,
"wasi:cli/terminal-input/terminal-input": latest::cli::terminal_input::TerminalInput,
"wasi:cli/terminal-output/terminal-output": latest::cli::terminal_output::TerminalOutput,
"wasi:sockets/tcp/tcp-socket": latest::sockets::tcp::TcpSocket,
"wasi:sockets/udp/udp-socket": latest::sockets::udp::UdpSocket,
"wasi:sockets/udp/outgoing-datagram-stream": latest::sockets::udp::OutgoingDatagramStream,
"wasi:sockets/udp/incoming-datagram-stream": latest::sockets::udp::IncomingDatagramStream,
"wasi:sockets/network/network": latest::sockets::network::Network,
"wasi:sockets/ip-name-lookup/resolve-address-stream": latest::sockets::ip_name_lookup::ResolveAddressStream,
"wasi:http/types/incoming-response": latest::http::types::IncomingResponse,
"wasi:http/types/incoming-request": latest::http::types::IncomingRequest,
"wasi:http/types/incoming-body": latest::http::types::IncomingBody,
"wasi:http/types/outgoing-response": latest::http::types::OutgoingResponse,
"wasi:http/types/outgoing-request": latest::http::types::OutgoingRequest,
"wasi:http/types/outgoing-body": latest::http::types::OutgoingBody,
"wasi:http/types/fields": latest::http::types::Fields,
"wasi:http/types/response-outparam": latest::http::types::ResponseOutparam,
"wasi:http/types/future-incoming-response": latest::http::types::FutureIncomingResponse,
"wasi:http/types/future-trailers": latest::http::types::FutureTrailers,
"wasi:http/types/request-options": latest::http::types::RequestOptions,
},
});
mod bindings {
use super::latest;

wasmtime::component::bindgen!({
path: "../../wit",
interfaces: r#"
include wasi:http/proxy@0.2.0-rc-2023-11-10;
// NB: this is handling the historical behavior where Spin supported
// more than "just" this snapshot of the proxy world but additionally
// other CLI-related interfaces.
include wasi:cli/reactor@0.2.0-rc-2023-11-10;
"#,
async: {
only_imports: [
"[method]descriptor.advise",
"[method]descriptor.create-directory-at",
"[method]descriptor.get-flags",
"[method]descriptor.get-type",
"[method]descriptor.is-same-object",
"[method]descriptor.link-at",
"[method]descriptor.metadata-hash",
"[method]descriptor.metadata-hash-at",
"[method]descriptor.open-at",
"[method]descriptor.read",
"[method]descriptor.read-directory",
"[method]descriptor.readlink-at",
"[method]descriptor.remove-directory-at",
"[method]descriptor.rename-at",
"[method]descriptor.set-size",
"[method]descriptor.set-times",
"[method]descriptor.set-times-at",
"[method]descriptor.stat",
"[method]descriptor.stat-at",
"[method]descriptor.symlink-at",
"[method]descriptor.sync",
"[method]descriptor.sync-data",
"[method]descriptor.unlink-file-at",
"[method]descriptor.write",
"[method]input-stream.read",
"[method]input-stream.blocking-read",
"[method]input-stream.blocking-skip",
"[method]input-stream.skip",
"[method]output-stream.splice",
"[method]output-stream.blocking-splice",
"[method]output-stream.blocking-flush",
"[method]output-stream.blocking-write",
"[method]output-stream.blocking-write-and-flush",
"[method]output-stream.blocking-write-zeroes-and-flush",
"[method]directory-entry-stream.read-directory-entry",
"[method]pollable.block",
"[method]pollable.ready",
"poll",
]
},
with: {
"wasi:io/poll/pollable": latest::io::poll::Pollable,
"wasi:io/streams/input-stream": latest::io::streams::InputStream,
"wasi:io/streams/output-stream": latest::io::streams::OutputStream,
"wasi:io/error/error": latest::io::error::Error,
"wasi:filesystem/types/directory-entry-stream": latest::filesystem::types::DirectoryEntryStream,
"wasi:filesystem/types/descriptor": latest::filesystem::types::Descriptor,
"wasi:cli/terminal-input/terminal-input": latest::cli::terminal_input::TerminalInput,
"wasi:cli/terminal-output/terminal-output": latest::cli::terminal_output::TerminalOutput,
"wasi:sockets/tcp/tcp-socket": latest::sockets::tcp::TcpSocket,
"wasi:sockets/udp/udp-socket": latest::sockets::udp::UdpSocket,
"wasi:sockets/udp/outgoing-datagram-stream": latest::sockets::udp::OutgoingDatagramStream,
"wasi:sockets/udp/incoming-datagram-stream": latest::sockets::udp::IncomingDatagramStream,
"wasi:sockets/network/network": latest::sockets::network::Network,
"wasi:sockets/ip-name-lookup/resolve-address-stream": latest::sockets::ip_name_lookup::ResolveAddressStream,
"wasi:http/types/incoming-response": latest::http::types::IncomingResponse,
"wasi:http/types/incoming-request": latest::http::types::IncomingRequest,
"wasi:http/types/incoming-body": latest::http::types::IncomingBody,
"wasi:http/types/outgoing-response": latest::http::types::OutgoingResponse,
"wasi:http/types/outgoing-request": latest::http::types::OutgoingRequest,
"wasi:http/types/outgoing-body": latest::http::types::OutgoingBody,
"wasi:http/types/fields": latest::http::types::Fields,
"wasi:http/types/response-outparam": latest::http::types::ResponseOutparam,
"wasi:http/types/future-incoming-response": latest::http::types::FutureIncomingResponse,
"wasi:http/types/future-trailers": latest::http::types::FutureTrailers,
"wasi:http/types/request-options": latest::http::types::RequestOptions,
},
});
}

mod wasi {
pub use super::bindings::wasi::{
cli0_2_0_rc_2023_11_10 as cli, clocks0_2_0_rc_2023_11_10 as clocks,
filesystem0_2_0_rc_2023_11_10 as filesystem, http0_2_0_rc_2023_11_10 as http,
io0_2_0_rc_2023_11_10 as io, random0_2_0_rc_2023_11_10 as random,
sockets0_2_0_rc_2023_11_10 as sockets,
};
}

pub mod exports {
pub mod wasi {
pub use super::super::bindings::exports::wasi::http0_2_0_rc_2023_11_10 as http;
}
}

use wasi::cli::terminal_input::TerminalInput;
use wasi::cli::terminal_output::TerminalOutput;
Expand Down
2 changes: 1 addition & 1 deletion crates/trigger-http/benches/spin-http-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
wit_bindgen::generate!({
world: "http-trigger",
path: "../../../../wit-2023-10-18/deps/spin@unversioned",
path: "../../../../wit/deps/spin@unversioned",
exports: {
"fermyon:spin/inbound-http": SpinHttp,
}
Expand Down
2 changes: 1 addition & 1 deletion crates/trigger-redis/tests/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::str::{from_utf8, Utf8Error};

wit_bindgen::generate!({
world: "redis-trigger",
path: "../../../../wit-2023-10-18/deps/spin@unversioned",
path: "../../../../wit/deps/spin@unversioned",
exports: {
"fermyon:spin/inbound-redis": SpinRedis,
}
Expand Down
Loading

0 comments on commit d2e89d8

Please sign in to comment.