Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ pub fn prepare<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRe
}
}

fn emit_build_output(state: &JobState<'_>, output: &BuildOutput, package_id: PackageId) {
fn emit_build_output(
state: &JobState<'_>,
output: &BuildOutput,
out_dir: &Path,
package_id: PackageId,
) {
let library_paths = output
.library_paths
.iter()
Expand All @@ -119,6 +124,7 @@ fn emit_build_output(state: &JobState<'_>, output: &BuildOutput, package_id: Pac
linked_paths: &library_paths,
cfgs: &output.cfgs,
env: &output.env,
out_dir,
}
.to_json_string();
state.stdout(msg);
Expand Down Expand Up @@ -349,7 +355,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
BuildOutput::parse(&output.stdout, &pkg_name, &script_out_dir, &script_out_dir)?;

if json_messages {
emit_build_output(state, &parsed_output, id);
emit_build_output(state, &parsed_output, script_out_dir.as_path(), id);
}
build_script_outputs
.lock()
Expand All @@ -374,7 +380,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
};

if json_messages {
emit_build_output(state, &output, id);
emit_build_output(state, &output, script_out_dir.as_path(), id);
}

build_script_outputs
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/util/machine_message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::path::{Path, PathBuf};

use serde::ser;
use serde::Serialize;
Expand Down Expand Up @@ -66,6 +66,7 @@ pub struct BuildScript<'a> {
pub linked_paths: &'a [String],
pub cfgs: &'a [String],
pub env: &'a [(String, String)],
pub out_dir: &'a Path,
}

impl<'a> Message for BuildScript<'a> {
Expand Down
6 changes: 5 additions & 1 deletion src/doc/src/reference/external-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ may be found in [the chapter on build scripts](build-scripts.md).
"env": [
["SOME_KEY", "some value"],
["ANOTHER_KEY", "another value"]
]
],
/* A path which is used as a value of `OUT_DIR` environmental variable
when compiling current package.
*/
"out_dir": "/some/path/in/target/dir"
}
```

Expand Down
3 changes: 2 additions & 1 deletion tests/testsuite/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,8 @@ fn compiler_json_error_format() {
"linked_libs":[],
"linked_paths":[],
"env":[],
"cfgs":["xyz"]
"cfgs":["xyz"],
"out_dir": "[..]target/debug/build/foo-[..]/out"
}

{
Expand Down
1 change: 1 addition & 0 deletions tests/testsuite/metabuild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ fn metabuild_json_artifact() {
"linked_libs": [],
"linked_paths": [],
"package_id": "foo [..]",
"out_dir": "[..]",
"reason": "build-script-executed"
}
"#,
Expand Down