-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Support cargo:info=MESSAGE
in build.rs
stdout
#7037
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
Comments
This would be quite useful. |
I was looking at putting up a PR for this, but after looking at the code, I can see there is some more discussion needed first. Internally, cargo has support for printing "warn", "error" and "note" messages to the shell. For consistency, I suggest this feature should be implemented as "cargo:note=MESSAGE" which would print the cyan note message. Additionally, similar functionality should be implemented for "error" as well (presumably error would also trigger cargo to abort). A complication with the existing architecture is that messages are collected from the custom build script and are not written to the console until after the build script has completed. Would this restriction still support the motivating use cases for this feature? In my use case, waiting until the end of the build script would not be sufficient. I have a build which requires the presence of a 500MB archive, which is downloaded if not present. I want to display a note to the user that this download is in progress, otherwise the impression is that cargo build has hung, particularly on slow connections. |
We talked about this in today's @rust-lang/cargo meeting. A summary of the rough consensus:
|
Yeah, that would be a problem, but I think this might be useful too for . We can perhaps allow logs from certain crates with configuration or/and crates that are locally hosted (rather than fetched from Crates.io)? |
If you want a workaround you can abuse escape codes to overwrite the line with something new. macro_rules! p {
($($tokens: tt)*) => {
println!("cargo:warning=\r\x1b[32;1m {}", format!($($tokens)*))
}
} p!("Compiling XYZ"); |
This is also blocked on #11461 being resolved.. |
I overlooked at that time. #11593 seems kinda a duplicate of this? |
Isn't #11593 about non-cap-lint build script warnings while this is about info messages? |
Hey, what's the status on this? There are legitimate use cases for printing general build info like when using an environment variable that will be overridden with a default value if not found. Anything I can help with? |
Within cargo's current model, that sounds like something that would be gated behind verbose output. iirc build script output is shown on verbose (or is it very verbose) output. What additional value would |
Hey, I stumbled back into this after a few years to find it still open :) I think the key distinction here is that you want to show some kind of potentially important message, but not the entire output of the build script. Our use case is - we have
|
Not that the "currrent operation" ("Compiling") would be unlikely to be overriden because that reflects a concurrent operation and trying to analyze what should be shown would be tricky. This just leaves the sticky result ("Compiled"). I can understand wanting to show nuance for very different build script operations but we also have a lot of people not thrilled with how much we output (on top of the abuse seen in other ecosystemsb) and we're looking at redoing our output in #8889. What we'd want from an "info status" after that may be very different |
Describe the problem you are trying to solve
Provide meaningful information to a developer when using a
build.rs
script.In my case, I provide duration of specific steps to monitor the performance of thoses.
Currently, I use
cargo:warning=MESSAGE
to provide this output.This is not fine because it is not an actual warning.
Describe the solution you'd like
Supporting
cargo:info=MESSAGE
to output a string in the cargo's output with info log level.Example:
(build.rs)
Will print in the cargo output if the
build.rs
script is executed:with the look of an info entry.
The text was updated successfully, but these errors were encountered: