Skip to content

Commit f101d88

Browse files
committed
fixed #5602, expose cached build script output in json output
1 parent 9f09778 commit f101d88

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,22 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
365365
BuildOutput::parse_file(&output_file, &pkg_name, &prev_root_output, &root_output)?
366366
}
367367
};
368+
369+
if json_messages {
370+
let library_paths = output
371+
.library_paths
372+
.iter()
373+
.map(|l| l.display().to_string())
374+
.collect::<Vec<_>>();
375+
machine_message::emit(&machine_message::BuildScript {
376+
package_id: &id,
377+
linked_libs: &output.library_links,
378+
linked_paths: &library_paths,
379+
cfgs: &output.cfgs,
380+
env: &output.env,
381+
});
382+
}
383+
368384
build_state.insert(id, kind, output);
369385
Ok(())
370386
});

tests/testsuite/build.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,11 +3976,13 @@ fn compiler_json_error_format() {
39763976
name = "foo"
39773977
version = "0.5.0"
39783978
authors = ["[email protected]"]
3979+
build = "build.rs"
39793980
39803981
[dependencies.bar]
39813982
path = "bar"
39823983
"#,
39833984
)
3985+
.file("build.rs", "fn main() { println!(\"cargo:rustc-cfg=xyz\") }")
39843986
.file("src/main.rs", "fn main() { let unused = 92; }")
39853987
.file(
39863988
"bar/Cargo.toml",
@@ -4035,6 +4037,36 @@ fn compiler_json_error_format() {
40354037
"fresh": false
40364038
}
40374039
4040+
{
4041+
"reason":"compiler-artifact",
4042+
"package_id":"foo 0.5.0 ([..])",
4043+
"target":{
4044+
"kind":["custom-build"],
4045+
"crate_types":["bin"],
4046+
"name":"build-script-build",
4047+
"src_path":"[..]build.rs"
4048+
},
4049+
"profile": {
4050+
"debug_assertions": true,
4051+
"debuginfo": 2,
4052+
"opt_level": "0",
4053+
"overflow_checks": true,
4054+
"test": false
4055+
},
4056+
"features": [],
4057+
"filenames": "{...}",
4058+
"fresh": false
4059+
}
4060+
4061+
{
4062+
"reason":"build-script-executed",
4063+
"package_id":"foo 0.5.0 ([..])",
4064+
"linked_libs":[],
4065+
"linked_paths":[],
4066+
"env":[],
4067+
"cfgs":["xyz"]
4068+
}
4069+
40384070
{
40394071
"reason":"compiler-message",
40404072
"package_id":"foo 0.5.0 ([..])",
@@ -4080,6 +4112,27 @@ fn compiler_json_error_format() {
40804112
.arg("json"),
40814113
execs().with_status(0).with_json(
40824114
r#"
4115+
{
4116+
"reason":"compiler-artifact",
4117+
"package_id":"foo 0.5.0 ([..])",
4118+
"target":{
4119+
"kind":["custom-build"],
4120+
"crate_types":["bin"],
4121+
"name":"build-script-build",
4122+
"src_path":"[..]build.rs"
4123+
},
4124+
"profile": {
4125+
"debug_assertions": true,
4126+
"debuginfo": 2,
4127+
"opt_level": "0",
4128+
"overflow_checks": true,
4129+
"test": false
4130+
},
4131+
"features": [],
4132+
"filenames": "{...}",
4133+
"fresh": true
4134+
}
4135+
40834136
{
40844137
"reason":"compiler-artifact",
40854138
"profile": {
@@ -4101,6 +4154,15 @@ fn compiler_json_error_format() {
41014154
"fresh": true
41024155
}
41034156
4157+
{
4158+
"reason":"build-script-executed",
4159+
"package_id":"foo 0.5.0 ([..])",
4160+
"linked_libs":[],
4161+
"linked_paths":[],
4162+
"env":[],
4163+
"cfgs":["xyz"]
4164+
}
4165+
41044166
{
41054167
"reason":"compiler-artifact",
41064168
"package_id":"foo 0.5.0 ([..])",

0 commit comments

Comments
 (0)