Skip to content

Commit

Permalink
Remove cargo_component_bindings crate. (#212)
Browse files Browse the repository at this point in the history
This commit is a breaking change to `cargo-component` with the intention of
improving component build time (now down to two transitive crate dependencies)
and get `rust-analyzer` fully working with bindings.

It removes the `cargo_component_bindings` and `cargo_component_macro` crates.
Instead of using a macro for including the generated bindings,
`cargo-component` now directly writes to a `src/bindings.rs` file which is
included as a submodule in `main.rs` or `lib.rs`.

Additionally, the `update` subcommand was removed as it is no longer necessary
since there is no `cargo_component_bindings` crate referenced in `Cargo.toml`;
the functionality to update `cargo-component` itself can simply be replaced
with a `cargo install` or `cargo binstall`.

Closes #210.
  • Loading branch information
peterhuene authored Jan 25, 2024
1 parent b21ce6d commit 5cf73a6
Show file tree
Hide file tree
Showing 37 changed files with 310 additions and 1,040 deletions.
26 changes: 0 additions & 26 deletions Cargo.lock

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

6 changes: 1 addition & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ warg-server = { workspace = true }
tempfile = { workspace = true }

[workspace]
members = ["crates/bindings", "crates/macro", "crates/core", "crates/wit"]
members = ["crates/core", "crates/wit"]

[workspace.dependencies]
cargo-component-core = { path = "crates/core", version = "0.6.0" }
cargo-component-macro = { path = "crates/macro", version = "0.6.0" }
warg-protocol = "0.2.0"
warg-crypto = "0.2.0"
warg-client = "0.2.0"
Expand Down Expand Up @@ -96,9 +95,6 @@ rand_core = "0.6.4"
rpassword = "7.3.1"
futures = "0.3.30"
bytes = "1.5.0"
proc-macro2 = "1.0.76"
quote = "1.0.35"
syn = "2.0.48"
which = "5.0.0"
wit-bindgen-rust = "0.16.0"
wit-bindgen-core = "0.16.0"
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ The component will export a `hello-world` function returning a string.
The implementation of the component will be in `src/lib.rs`:

```rust
cargo_component_bindings::generate!();
mod bindings;

use bindings::Guest;

Expand All @@ -245,11 +245,9 @@ impl Guest for Component {
}
```

The `generate!` macro is responsible for generating the bindings to allow the
Rust code to export what is expected of the component.

It generates a Rust module named `bindings` containing the types and traits the
correspond to the world definition.
The `bindings` module contains the the types and traits that correspond to the
world targeted by the component; it is automatically generated by
`cargo-component`.

## Usage

Expand Down
4 changes: 0 additions & 4 deletions ci/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use std::time::Duration;

// note that this list must be topologically sorted by dependencies
const CRATES_TO_PUBLISH: &[&str] = &[
"cargo-component-macro",
"cargo-component-bindings",
"cargo-component-core",
"wit",
"cargo-component",
Expand All @@ -26,8 +24,6 @@ const CRATES_TO_PUBLISH: &[&str] = &[
// releases since everything not mentioned here is just an organizational detail
// that no one else should rely on.
const PUBLIC_CRATES: &[&str] = &[
"cargo-component-macro",
"cargo-component-bindings",
"cargo-component-core",
"wit",
"cargo-component",
Expand Down
14 changes: 0 additions & 14 deletions crates/bindings/Cargo.toml

This file was deleted.

14 changes: 0 additions & 14 deletions crates/bindings/src/lib.rs

This file was deleted.

18 changes: 0 additions & 18 deletions crates/macro/Cargo.toml

This file was deleted.

41 changes: 0 additions & 41 deletions crates/macro/build.rs

This file was deleted.

105 changes: 0 additions & 105 deletions crates/macro/src/lib.rs

This file was deleted.

58 changes: 3 additions & 55 deletions example/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 example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
cargo-component-bindings = { path = "../crates/bindings" }
wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"]}

[package.metadata.component]
package = "example:component"
Expand Down
Loading

0 comments on commit 5cf73a6

Please sign in to comment.