Skip to content

Commit

Permalink
feat: support run, test and bench cargo commands (#143)
Browse files Browse the repository at this point in the history
* feat: support run, test and bench cargo commands

* feat: take into account cargo config toml

* chore: update comments

* chore: include tests for test command

* chore: include tests for bench command

* chore(ci): run tests with rust nightly

* feat: componentize output before command

* chore: add test for run command

* chore(ci): simplify tests and github workflow

* chore(ci): disable fail fast strategy

* chore(ci): ensure rust nightly is installed

* chore(ci): free space in rust installation

* chore: install clippy and rustfmt

* chore: use nightly when compiling bench test itself

* chore: set rust toolchain to nightly with env

* chore: disable benchmark test on windows

* feat: extract build details properly

* fix: split runtime arguments to pass to runner

* chore: add tests for command and reactor components

* fix: hide json message in stdout by default

* fix: test entrypoint clashing with command

* chore: simplify main github workflow

* chore: include some extra code comments

* fix: missing ansi colors in command output

* chore: use package id for binaries

* Improve the UX for supporting the run/test commands.

This commit pipes the stdout and inherits stderr when spawning `cargo`,
allowing for immediate output from cargo without buffering.

It also improves the processing of wasm artifacts to componentize; the
"creating component" message no longer prints on every build for macOS users.

Removed forcing colors in cargo output as we now inherit stderr, allowing cargo
to detect if it is a terminal or not.

* Revert unnecessary test changes.

* Use Wasmtime 15 in CI.

---------

Co-authored-by: Peter Huene <[email protected]>
  • Loading branch information
eduardomourar and peterhuene authored Dec 4, 2023
1 parent b062069 commit 8794955
Show file tree
Hide file tree
Showing 9 changed files with 663 additions and 113 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ jobs:
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Install Rust
run: rustup update stable --no-self-update && rustup default stable && rustup target add wasm32-wasi && rustup target add wasm32-unknown-unknown
run: |
rustup set profile minimal
rustup update stable --no-self-update
rustup update nightly --no-self-update
rustup default stable
rustup target add wasm32-wasi
rustup target add wasm32-wasi --toolchain nightly
rustup target add wasm32-unknown-unknown
shell: bash
- name: Install Wasmtime
run: cargo install wasmtime-cli --locked --features="component-model" --version 15.0.0
- name: Run all tests
run: cargo test --all

Expand Down
46 changes: 37 additions & 9 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ wit-component = { workspace = true }
wasm-metadata = { workspace = true }
parse_arg = { workspace = true }
cargo_metadata = { workspace = true }
cargo-config2 = { workspace = true }
libc = { workspace = true }
warg-protocol = { workspace = true }
warg-crypto = { workspace = true }
Expand All @@ -48,6 +49,7 @@ rand_core = { workspace = true }
rpassword = { workspace = true }
futures = { workspace = true }
bytes = { workspace = true }
which = { workspace = true }

[dev-dependencies]
assert_cmd = "2.0.12"
Expand Down Expand Up @@ -78,12 +80,13 @@ semver = "1.0.20"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
indexmap = "2.1.0"
url = { version = "2.4.1", features = ["serde"] }
url = { version = "2.5.0", features = ["serde"] }
wit-parser = "0.13.0"
wit-component = "0.18.2"
wasm-metadata = "0.10.13"
parse_arg = "0.1.4"
cargo_metadata = "0.18.1"
cargo-config2 = "0.1.16"
keyring = "2.0.5"
libc = "0.2.150"
owo-colors = "3.5.0"
Expand All @@ -96,5 +99,6 @@ bytes = "1.5.0"
proc-macro2 = "1.0.69"
quote = "1.0.33"
syn = "2.0.39"
which = "5.0.0"
wit-bindgen-rust = "0.14.0"
wit-bindgen-core = "0.14.0"
1 change: 1 addition & 0 deletions src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl PublishCommand {
quiet: self.common.quiet,
targets: self.target.clone().into_iter().collect(),
manifest_path: self.manifest_path.clone(),
message_format: None,
frozen: self.frozen,
locked: self.locked,
release: true,
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ pub struct CargoArguments {
pub targets: Vec<String>,
/// The --manifest-path argument.
pub manifest_path: Option<PathBuf>,
/// The `--message-format`` argument.
pub message_format: Option<String>,
/// The --frozen argument.
pub frozen: bool,
/// The --locked argument.
Expand Down Expand Up @@ -392,6 +394,7 @@ impl CargoArguments {
let mut args = Args::default()
.single("--color", "WHEN", Some('c'))
.single("--manifest-path", "PATH", None)
.single("--message-format", "FMT", None)
.multiple("--package", "SPEC", Some('p'))
.multiple("--target", "TRIPLE", None)
.flag("--release", Some('r'))
Expand Down Expand Up @@ -438,6 +441,7 @@ impl CargoArguments {
.unwrap()
.take_single()
.map(PathBuf::from),
message_format: args.get_mut("--message-format").unwrap().take_single(),
targets: args.get_mut("--target").unwrap().take_multiple(),
frozen: args.get("--frozen").unwrap().count() > 0,
locked: args.get("--locked").unwrap().count() > 0,
Expand Down Expand Up @@ -756,6 +760,7 @@ mod test {
quiet: false,
targets: Vec::new(),
manifest_path: None,
message_format: None,
release: false,
frozen: false,
locked: false,
Expand All @@ -773,6 +778,8 @@ mod test {
"--color=auto",
"--manifest-path",
"Cargo.toml",
"--message-format",
"json-render-diagnostics",
"--release",
"--package",
"package1",
Expand All @@ -798,6 +805,7 @@ mod test {
quiet: true,
targets: vec!["foo".to_string(), "bar".to_string()],
manifest_path: Some("Cargo.toml".into()),
message_format: Some("json-render-diagnostics".into()),
release: true,
frozen: true,
locked: true,
Expand Down
Loading

0 comments on commit 8794955

Please sign in to comment.