Skip to content

Commit b505e8a

Browse files
committed
Auto merge of #7622 - matklad:out-dir, r=ehuss
Add value OUT_DIR to build-script-executed JSON message The target audience here is IDE authors, who can use this feature to better support crates which generate code to OUT_DIR
2 parents b50ef2f + a87aceb commit b505e8a

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/cargo/core/compiler/custom_build.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ pub fn prepare<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRe
106106
}
107107
}
108108

109-
fn emit_build_output(state: &JobState<'_>, output: &BuildOutput, package_id: PackageId) {
109+
fn emit_build_output(
110+
state: &JobState<'_>,
111+
output: &BuildOutput,
112+
out_dir: &Path,
113+
package_id: PackageId,
114+
) {
110115
let library_paths = output
111116
.library_paths
112117
.iter()
@@ -119,6 +124,7 @@ fn emit_build_output(state: &JobState<'_>, output: &BuildOutput, package_id: Pac
119124
linked_paths: &library_paths,
120125
cfgs: &output.cfgs,
121126
env: &output.env,
127+
out_dir,
122128
}
123129
.to_json_string();
124130
state.stdout(msg);
@@ -349,7 +355,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
349355
BuildOutput::parse(&output.stdout, &pkg_name, &script_out_dir, &script_out_dir)?;
350356

351357
if json_messages {
352-
emit_build_output(state, &parsed_output, id);
358+
emit_build_output(state, &parsed_output, script_out_dir.as_path(), id);
353359
}
354360
build_script_outputs
355361
.lock()
@@ -374,7 +380,7 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>) -> CargoRes
374380
};
375381

376382
if json_messages {
377-
emit_build_output(state, &output, id);
383+
emit_build_output(state, &output, script_out_dir.as_path(), id);
378384
}
379385

380386
build_script_outputs

src/cargo/util/machine_message.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::PathBuf;
1+
use std::path::{Path, PathBuf};
22

33
use serde::ser;
44
use serde::Serialize;
@@ -66,6 +66,7 @@ pub struct BuildScript<'a> {
6666
pub linked_paths: &'a [String],
6767
pub cfgs: &'a [String],
6868
pub env: &'a [(String, String)],
69+
pub out_dir: &'a Path,
6970
}
7071

7172
impl<'a> Message for BuildScript<'a> {

src/doc/src/reference/external-tools.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ may be found in [the chapter on build scripts](build-scripts.md).
209209
"env": [
210210
["SOME_KEY", "some value"],
211211
["ANOTHER_KEY", "another value"]
212-
]
212+
],
213+
/* A path which is used as a value of `OUT_DIR` environmental variable
214+
when compiling current package.
215+
*/
216+
"out_dir": "/some/path/in/target/dir"
213217
}
214218
```
215219

tests/testsuite/build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3095,7 +3095,8 @@ fn compiler_json_error_format() {
30953095
"linked_libs":[],
30963096
"linked_paths":[],
30973097
"env":[],
3098-
"cfgs":["xyz"]
3098+
"cfgs":["xyz"],
3099+
"out_dir": "[..]target/debug/build/foo-[..]/out"
30993100
}
31003101
31013102
{

tests/testsuite/metabuild.rs

+1
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ fn metabuild_json_artifact() {
711711
"linked_libs": [],
712712
"linked_paths": [],
713713
"package_id": "foo [..]",
714+
"out_dir": "[..]",
714715
"reason": "build-script-executed"
715716
}
716717
"#,

0 commit comments

Comments
 (0)