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: build-scrip-test@0.1.0: 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
cargo init build-scrip-test
cd build-scrip-test
- 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
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)
Problem
When using
--message-format=jsonthebuild-script-executedmessage 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: build-scrip-test@0.1.0: MSGfor 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-executedwith the parsed build script output being emitted.Steps
cargo init build-scrip-testcd build-scrip-test3a.
echo "fn main() { println!("cargo::error=MSG"); }" > build.rs3b.
echo "fn main() -> Result<(), &'static str>{ Err(\"MSG\") }" > build.rs3c.
echo "fn main() -> Result<(), &'static str>{ println!("cargo::error=MSG"); Err(\"MSG\") }" > build.rscargo build --message-format=jsonNo
build-script-executedmessage 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-executedshould be emitted.
Ideally some fields would be added:
cargo::warning=MSG(surprised this doesn't already exist)cargo::error=MSGNotes
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-executedmassages withsuccess == falseand then assign blame based onpackage_idThe cargo error not being emitted as json likely falls under #8283.
This is also likely related to #12377.
Version