-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
cargo-component
internals and introduce proc-macro. (#101)
* Refactor `cargo-component` internals and introduce proc-macro. This commit includes a *very* large refactoring to the internals of `cargo-component` and how it works. The biggest change is that `cargo-component` no longer generates an external bindings crate that is automatically added as a dependency to a user's component project. The motivation behind this change is that support for resources from the component model will preclude the ability to reference types from the user's crate because the `export!` macro is being removed. Instead, component projects will need to reference the `cargo-component-bindings` crate to invoke the `generate!` proc-macro. This macro will expand to the bindings code based on the target world encoded from dependency resolution performed by `cargo-component`. By default, the `generate!` macro will assume that the world / all exported interfaces are implemented by a type named `Component`, however that can be changed with an argument to the macro. With the removal of the need for an external bindings crate, `cargo-component` no longer has a concrete reason to directly depend on the `cargo` crate as a dependency. Instead, it now spawns `cargo` for all subcommands that aren't built-in to `cargo-component`. For this to function, `cargo-component` detects certain `cargo` options that may alter output (`--verbose`, `--quiet`, etc.) or what gets built (`--manifest-path`, `--target`, etc.). Before any unrecognized commands are passed to `cargo`, `cargo-component` will update the encoding of target worlds for bindings allowing commands that analyze or build the source code to work. Additionally, `cargo-component` will recognize certain `cargo` subcommands that have outputs that need to be componentized. As a result of these changes, about 150 crate dependencies were removed, the `cargo-component` executable shrunk about 12 MiB in size, and commands such as `cargo component expand` now "just work" without `cargo-component` having to provide its own implementation. All dependencies, and the WASI adapters, are updated as part of these changes. Note: the `test` command still isn't implemented. Closes #97. Closes #91. * Update wit-bindgen deps. * Fix windows build. * More Windows fixes. * Update warg dependencies. This includes the latest API changes. * More dep updates. * Update crates/core/src/progress.rs Co-authored-by: Dan Gohman <dev@sunfishcode.online> * Update crates/core/src/progress.rs Co-authored-by: Dan Gohman <dev@sunfishcode.online> * Update crates/core/src/progress.rs Co-authored-by: Dan Gohman <dev@sunfishcode.online> * Update crates/core/src/progress.rs Co-authored-by: Dan Gohman <dev@sunfishcode.online> * Add `pub(crate)` to the bindings module. Also update the example lock file. * Add examples of commands passed through to `cargo` to README. * Update README to explain what a "reactor" component is. * Add more context for failure to create a target world. This commit adds more context to when there's a problem creating the target world. It gives users a way of determining which cargo package is at fault for the error when building a multi-package workspace. --------- Co-authored-by: Dan Gohman <dev@sunfishcode.online>
- Loading branch information
1 parent
1fc8d21
commit e24c73e
Showing
56 changed files
with
6,125 additions
and
5,256 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "cargo-component-bindings" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Peter Huene <peter@huene.dev>"] | ||
description = "A crate for generating bindings of WebAssembly components." | ||
license = "Apache-2.0 WITH LLVM-exception" | ||
documentation = "https://docs.rs/cargo-component-bindings" | ||
categories = ["wasm"] | ||
keywords = ["webassembly", "wasm", "components", "component model"] | ||
repository = "https://github.com/bytecodealliance/cargo-component" | ||
|
||
[dependencies] | ||
cargo-component-macro = { workspace = true } | ||
wit-bindgen = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! A crate for generating bindings with `cargo-component`. | ||
|
||
#![deny(missing_docs)] | ||
|
||
// Export the `generate` macro. | ||
pub use cargo_component_macro::generate; | ||
|
||
// Re-export `wit_bindgen::rt` module for the generated code to use. | ||
#[doc(hidden)] | ||
pub use wit_bindgen::rt; |
Oops, something went wrong.