-
Notifications
You must be signed in to change notification settings - Fork 96
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
Make it easier to build an artifact and record its path #153
Comments
I guess this means |
If it helps, this is how I adapted the example: // First, build `threenp1` and record the generated executable
// Adapted from the example at https://docs.rs/cargo_metadata/0.12.3/cargo_metadata/#examples.
// TODO: I opened https://github.com/oli-obk/cargo_metadata/issues/153 to hopefully require less copy/pasting in the future.
let mut command = Command::new(std::env::var("CARGO").unwrap_or("cargo"))
.args(&["build", "--example=threenp1", "--message-format=json-render-diagnostics"])
.stdout(Stdio::piped())
.spawn()
.unwrap();
let reader = std::io::BufReader::new(command.stdout.take().unwrap());
let threenp1 = cargo_metadata::Message::parse_stream(reader).find_map(|message| {
// original jq script: `select(.reason == "compiler-artifact" and (.target.kind[] | contains("example"))) | .executable`
if let Message::CompilerArtifact(Artifact { executable, target, .. }) = message {
if target.kind.contains("example") {
return executable;
}
}
None
}).unwrap();
let output = command.wait().unwrap();
assert!(output.status.success(), "failed to run `cargo build`"); |
We could certainly start exposing more helpers (e.g. for getting a cargo command), or just use something like I'm less sold on the builder/typestate solution, but maybe I'm just not actually seeing what you are envisioning. |
Right now, there's an example on the front page, which is much appreciated:
This has a few issues though:
CARGO
the wayMetadataCommand
does: https://docs.rs/cargo_metadata/0.12.3/src/cargo_metadata/lib.rs.html#557It would be really useful for
MetadataCommand
to work for things other thancargo metadata
itself. Maybe this is as simple as addingMetadataSubcommand(&mut self, cmd: String) -> Self
, and replacingmetadata --format-version=1
with that command? Everything else should work the same sinceother_options
is public.The text was updated successfully, but these errors were encountered: