Skip to content

Commit a45d4e9

Browse files
committed
Auto merge of #4088 - Nemikolh:buildscript-stderr, r=alexcrichton
Write stderr output from build-scripts next to stdout output Closes #3462. Please let me know if you want to change the file name for the error output. I originally thought that `stdout` and `stderr` would have been nice but I'm worried that changing `output` to `stdout` would cause breakage. So I choose the more conservative route.
2 parents 9fcdbb4 + 8fa39fc commit a45d4e9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/cargo/ops/cargo_rustc/custom_build.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
164164
let pkg_name = unit.pkg.to_string();
165165
let build_state = cx.build_state.clone();
166166
let id = unit.pkg.package_id().clone();
167-
let output_file = build_output.parent().unwrap().join("output");
167+
let (output_file, err_file) = {
168+
let build_output_parent = build_output.parent().unwrap();
169+
let output_file = build_output_parent.join("output");
170+
let err_file = build_output_parent.join("stderr");
171+
(output_file, err_file)
172+
};
168173
let all = (id.clone(), pkg_name.clone(), build_state.clone(),
169174
output_file.clone());
170175
let build_scripts = super::load_build_deps(cx, unit);
@@ -237,7 +242,9 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
237242
pkg_name, e.desc);
238243
Human(e)
239244
})?;
245+
240246
paths::write(&output_file, &output.stdout)?;
247+
paths::write(&err_file, &output.stderr)?;
241248

242249
// After the build command has finished running, we need to be sure to
243250
// remember all of its output so we can later discover precisely what it

src/doc/build-script.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ cargo:libdir=/path/to/foo/lib
5858
cargo:include=/path/to/foo/include
5959
```
6060

61+
On the other hand, lines printed to stderr are written to a file like
62+
`target/debug/build/<pkg>/stderr` but are not interpreted by cargo.
63+
6164
There are a few special keys that Cargo recognizes, some affecting how the
6265
crate is built:
6366

0 commit comments

Comments
 (0)