Skip to content

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

Open
@Skgland

Description

@Skgland

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions