-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process_wrapper: add support for terminating rustc after it emits rmeta.
This is a key component of supporting pipelining in rules_rust. The bazel rules will (in a follow-up PR) configure rustc to run either to completion for rules whose dependencies require the full rlib files or until they emit the rmeta files if dependencies only require that. This is safe to commit as there are no changes to user-visible behavior until the new flags are used.
- Loading branch information
Showing
11 changed files
with
355 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() { | ||
eprintln!(r#"{{"rendered": "I am a fake rustc\nvery very fake"}}"#); | ||
eprintln!(r#"{{"emit": "metadata"}}"#); | ||
std::thread::sleep(std::time::Duration::from_secs(1)); | ||
eprintln!(r#"{{"rendered": "I should not print this"}}"#); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
use std::str; | ||
|
||
use runfiles::Runfiles; | ||
|
||
fn fake_rustc(process_wrapper_args: &[&'static str]) -> String { | ||
let r = Runfiles::create().unwrap(); | ||
let fake_rustc = r.rlocation( | ||
&[ | ||
"rules_rust", | ||
"test", | ||
"process_wrapper", | ||
if cfg!(unix) { | ||
"fake_rustc" | ||
} else { | ||
"fake_rustc.exe" | ||
}, | ||
] | ||
.iter() | ||
.collect::<PathBuf>(), | ||
); | ||
|
||
let process_wrapper = r.rlocation( | ||
&[ | ||
"rules_rust", | ||
"util", | ||
"process_wrapper", | ||
if cfg!(unix) { | ||
"process_wrapper" | ||
} else { | ||
"process_wrapper.exe" | ||
}, | ||
] | ||
.iter() | ||
.collect::<PathBuf>(), | ||
); | ||
|
||
let output = Command::new(process_wrapper) | ||
.args(process_wrapper_args) | ||
.arg("--") | ||
.arg(fake_rustc) | ||
.output() | ||
.unwrap(); | ||
|
||
assert!( | ||
output.status.success(), | ||
"unable to run process_wrapper: {} {}", | ||
str::from_utf8(&output.stdout).unwrap(), | ||
str::from_utf8(&output.stderr).unwrap(), | ||
); | ||
|
||
String::from_utf8(output.stderr).unwrap() | ||
} | ||
|
||
#[test] | ||
fn test_rustc_quit_on_rmeta_quits() { | ||
let out_content = fake_rustc(&["--rustc-quit-on-rmeta", "true"]); | ||
assert!( | ||
!out_content.contains("I should not print this"), | ||
"output should not contain 'I should not print this' but did: {}", | ||
out_content | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_rustc_quit_on_rmeta_output_json() { | ||
let json_content = fake_rustc(&[ | ||
"--rustc-quit-on-rmeta", | ||
"true", | ||
"--rustc-output-format", | ||
"json", | ||
]); | ||
assert_eq!( | ||
json_content, | ||
concat!(r#"{"rendered": "I am a fake rustc\nvery very fake"}"#, "\n") | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_rustc_quit_on_rmeta_output_rendered() { | ||
let rendered_content = fake_rustc(&[ | ||
"--rustc-quit-on-rmeta", | ||
"true", | ||
"--rustc-output-format", | ||
"rendered", | ||
]); | ||
assert_eq!(rendered_content, "I am a fake rustc\nvery very fake"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# buildifier: disable=bzl-visibility | ||
load("@rules_rust//rust/private:rust.bzl", "rust_library_without_process_wrapper") | ||
|
||
rust_library_without_process_wrapper( | ||
name = "tinyjson", | ||
srcs = glob(["src/*.rs"]), | ||
visibility = ["@rules_rust//util/process_wrapper:__pkg__"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.