Skip to content

Mechanism to unconditionally emit warnings from build scripts #3777

@SergioBenitez

Description

@SergioBenitez

At present, I can use println!("cargo:warning={}", message) in a build script to ask cargo to emit a warning message during compilation. Unfortunately, this warning message cannot be seen from end-users of a library unless they pass -vv to their cargo invocation. Of course, this is not something that users do, and as a result, these warnings are never seen by end-users.

This inability to unconditionally emit a warning message during compilation leads to usability issues in libraries that utilize build scripts. As an example, consider Rocket's build script. The script attempts to detect the version of the user's rustc so that it can decline to compile with known incompatible versions. When the rustc version cannot be determined, the build script attempts to emit a warning. Unfortunately this warning is hidden by cargo by default leading to users being confused about why Rocket is failing to build; this is the exact thing the script is trying to prevent.

I would like a mechanism by which build scripts can log to the console, regardless of the verbosity level set by the user. I can think of several such mechanisms:

  1. Use the same cargo:warning={} trick, but always emit the warnings.
  2. Emit everything written to stderr from build scripts.
  3. Add levels to warnings, and always emit errors above some threshold. Something like: cargo:warning(k) where k is some integer defining the level.
  4. Add something like cargo:critical={} which unconditionally emits critical messages.

My personal preference is for 2. This is what I would expect when writing a build script, but I'd be content with any solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions