Skip to content

build-script-executed json message not emitted when build script failed #15424

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

Open
Skgland opened this issue Apr 12, 2025 · 0 comments
Open
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@Skgland
Copy link

Skgland commented Apr 12, 2025

Problem

When using --message-format=json the build-script-executed message is not emitted when the build script fails.

I would consider an unsuccessful build script execution to still be a build scrip execution.
In the cases 3a and 3c cargo even emits error: [email protected]: MSG for the user so cargo must have parsed the out put to at least the point that the error instruction was emitted.
As such I would have expected a build-script-executed with the parsed build script output being emitted.

Steps

  1. cargo init build-scrip-test
  2. cd build-scrip-test
  3. add a build.rs file
    3a. echo "fn main() { println!("cargo::error=MSG"); }" > build.rs
    3b. echo "fn main() -> Result<(), &'static str>{ Err(\"MSG\") }" > build.rs
    3c. echo "fn main() -> Result<(), &'static str>{ println!("cargo::error=MSG"); Err(\"MSG\") }" > build.rs
  4. cargo build --message-format=json

No build-script-executed message was emmited even though the build scrip was executed (and is the reason the build failed)

Possible Solution(s)

In the event of an unsuccessful build script execution build-script-executed
should be emitted.

Ideally some fields would be added:

  • "success": boolean to indicate whether the build script execution was successful or failed
  • "warnings": list of warnings emitted via cargo::warning=MSG (surprised this doesn't already exist)
  • "errors": list of errors emitted via cargo::error=MSG
{
    /* The "reason" indicates the kind of message. */
    "reason": "build-script-executed",
    /* The Package ID, a unique identifier for referring to the package. */
    "package_id": "file:///path/to/my-package#0.1.0",

    // skipping other already documented fields

    /* list of MSG strings of cargo::warning=MSG */
    "warnings": ["warning1", "warning2"],
    /* list of MSG strings of cargo::error=MSG */
    "errors": ["error1", "error2"],
    "success": false,
}

Notes

Noticed this while trying to see if there is a better way to see that an error originates in a build script than what rust-lang/crater#672 does.
The suggested solution would help as one could look for build-script-executed massages with success == false and then assign blame based on package_id

The cargo error not being emitted as json likely falls under #8283.
This is also likely related to #12377.

Version

cargo 1.86.0 (adf9b6ad1 2025-02-28)
@Skgland Skgland added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

1 participant