Skip to content
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

Support cargo:info=MESSAGE in build.rs stdout #7037

Open
fredericvauchelles opened this issue Jun 16, 2019 · 8 comments
Open

Support cargo:info=MESSAGE in build.rs stdout #7037

fredericvauchelles opened this issue Jun 16, 2019 · 8 comments
Labels
A-build-scripts Area: build.rs scripts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@fredericvauchelles
Copy link

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)

fn main() {
     println!("cargo:info=Hello World!");
}

Will print in the cargo output if the build.rs script is executed:

info: Hello World!

with the look of an info entry.

@fredericvauchelles fredericvauchelles added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Jun 16, 2019
@ehuss ehuss added the A-build-scripts Area: build.rs scripts label Jun 24, 2019
@Fishrock123
Copy link

This would be quite useful.

@davidkern
Copy link

davidkern commented Mar 30, 2021

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.

@joshtriplett
Copy link
Member

We talked about this in today's @rust-lang/cargo meeting.

A summary of the rough consensus:

  • This needs design work, and an RFC; we don't just want to do this via PR.
  • Info messages should not show up by default, only if you pass -v or similar. We're concerned about this being misused if visible by default. The equivalent in npm, for instance, is sometimes used for advertisements.
  • We'd be interested in a more narrowly scoped mechanism for cargo:progress= messages, which would only carry numeric progress information (e.g. percentage done); Cargo's own progress could then show something like cratename(build x%), and that could be shown by default. Such a mechanism would need to allow for multiple progress indicators from the same crate, because this would almost certainly come primarily from helper crates rather than from build scripts directly. (For instance, the cc or cmake crates could give progress indicators for their builds, or a common download helper crate could provide progress indicators for its downloads.) We don't want such a mechanism to introduce too much complexity, but a simple tag+number system might work.

@togetherwithasteria
Copy link

Info messages should not show up by default, only if you pass -v or similar. We're concerned about this being misused if visible by default. The equivalent in npm, for instance, is sometimes used for advertisements.

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)?

@codecnotsupported
Copy link

codecnotsupported commented May 19, 2023

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");

ttys3 added a commit to ttys3/xapian-rs that referenced this issue Jun 10, 2023
@epage
Copy link
Contributor

epage commented Nov 1, 2023

This is also blocked on #11461 being resolved..

@epage epage added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label Nov 1, 2023
@weihanglo
Copy link
Member

I overlooked at that time. #11593 seems kinda a duplicate of this?

@epage
Copy link
Contributor

epage commented Nov 1, 2023

Isn't #11593 about non-cap-lint build script warnings while this is about info messages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

9 participants