-
Notifications
You must be signed in to change notification settings - Fork 56
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
Refactor cargo-component
internals and introduce proc-macro.
#101
Refactor cargo-component
internals and introduce proc-macro.
#101
Conversation
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 bytecodealliance#97. Closes bytecodealliance#91.
Additionally, this PR also refactors some of the This will allow for sharing implementation with |
This includes the latest API changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not very familiar with the registry parts, but overall this looks good! My main concern is just how we can make the bindings module accessible to other modules:
Co-authored-by: Dan Gohman <[email protected]>
Co-authored-by: Dan Gohman <[email protected]>
Co-authored-by: Dan Gohman <[email protected]>
Co-authored-by: Dan Gohman <[email protected]>
Also update the example lock file.
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.
@sunfishcode thanks for looking this huge change over! |
This PR 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 theexport!
macro is being removed.Instead, component projects will need to reference the
cargo-component-bindings
crate to invoke thegenerate!
proc-macro. This macro will expand to the bindings code based on the target world encoded from dependency resolution performed bycargo-component
.By default, the
generate!
macro will assume that the world / all exported interfaces are implemented by a type namedComponent
, 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 thecargo
crate as a dependency. Instead, it now spawnscargo
for all subcommands that aren't built-in tocargo-component
.For this to function,
cargo-component
detects certaincargo
options that may alter output (--verbose
,--quiet
, etc.) or what gets built (--manifest-path
,--target
, etc.). Before any unrecognized commands are passed tocargo
,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 certaincargo
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 ascargo component expand
now "just work" withoutcargo-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.