Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for sccache+msvc+LLVM #78

Merged
merged 3 commits into from
Apr 11, 2017
Merged

Conversation

alexcrichton
Copy link
Contributor

This few commits were what I found was necessary to get sccache fully working on MSVC when compiling LLVM in rust-lang/rust. It basically boiled down to:

Fixes #61
Fixes #47

Copy link

@KalitaAlexey KalitaAlexey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked as much as I understood.

let ParsedArguments {
input,
extension,
depfile: _depfile,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write _ instead of _depfile.
https://is.gd/7nHDiH

}
o @ _ => assert!(false, format!("Got unexpected parse result: {:?}", o)),
}
let args = stringvec!["-c", "foo.cxx", "-arch", "xyz", "-fabc","-I", "include", "-o", "foo.o", "-include", "file"];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after `"-afbc".

let ParsedArguments {
input,
extension,
depfile: _depfile,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as I suggested above.

let ParsedArguments {
input,
extension,
depfile: _depfile,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as I suggested above.

@@ -108,56 +109,58 @@ pub fn parse_arguments(arguments: &[String]) -> CompilerArguments {
let mut debug_info = false;
let mut pdb = None;
let mut depfile = None;
let mut show_includes = false;

//TODO: support arguments that start with / as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the comment is no longer needed.

v @ _ if v.starts_with("-deps") => {
depfile = Some(v[5..].to_owned());
}
// Arguments we can't handle.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be placed below because we will be able to handle "-showIncludes".

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 16, 2017
I've built a local copy with mozilla/sccache#79 and mozilla/sccache#78. Let's
see if that helps rust-lang#40240!
bors added a commit to rust-lang/rust that referenced this pull request Mar 16, 2017
travis: Update sccache binary

I've built a local copy with mozilla/sccache#79 and mozilla/sccache#78. Let's
see if that helps #40240!
bors added a commit to rust-lang/rust that referenced this pull request Mar 17, 2017
travis: Update sccache binary

I've built a local copy with mozilla/sccache#79 and mozilla/sccache#78. Let's
see if that helps #40240!
@alexcrichton alexcrichton force-pushed the msvc-ninja branch 2 times, most recently from e927bc8 to 4020e89 Compare March 27, 2017 17:14
let mut it = arguments.iter();
let mut it = arguments.iter().map(|i| {
if i.starts_with("/") {
format!("-{}", &i[1..])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a clever hack!

debug_info = true;
common_args.push(arg.clone());
}
v if v.starts_with("-Fd") => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking it might be nice to refactor some of the other compiler argument parsing code to use the ArgsIter pattern I implemented for Rust:

let it = ArgsIter::new(arguments, &args_with_val);

It's probably not as useful here, but it was nice to be able to write all the match arms as strings instead of having v.starts_with(...) all over the place.

@@ -77,7 +79,7 @@ struct CCompilation<I: CCompilerImpl> {
parsed_args: ParsedArguments,
executable: String,
/// The output from running the preprocessor.
preprocessor_output: Vec<u8>,
preprocessor_result: process::Output,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change ought to make it easier to fix #72 as well!

msvc_show_includes,
common_args,
} = match _parse_arguments(&args) {
CompilerArguments::Ok(args) => args,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a much more sensible way to write this.

}
Box::new(ret.map(|(cacheable, mut output)| {
let prev = mem::replace(&mut output.stderr, extra_stderr);
output.stderr.extend(prev);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is actually correct, and this is probably what breaks the configure test in the Firefox build. See my comment in detect_showincludes_prefix:

// The MSDN docs say the -showIncludes output goes to stderr,

I just did a simple local test with MSVC2015 and the -showIncludes output goes to stdout when compiling:

ted@DESKTOP-32V9ND8 /c/build
$ cl -Fonul -nologo -showIncludes -c test.c > /tmp/cl.stdout 2>/tmp/cl.stderr

ted@DESKTOP-32V9ND8 /c/build
$ cat /tmp/cl.stdout
test.c
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt\stdio.h
Note: including file:  C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt\corecrt.h
Note: including file:   C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vcruntime.h
Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\sal.h
Note: including file:     C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\ConcurrencySal.h
Note: including file:    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\vadefs.h
Note: including file:  C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt\corecrt_wstdio.h
Note: including file:   C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt\corecrt_stdio_config.h

When running the preprocessor it definitely goes to stderr.

Unfortunately I think this means we'll have to do something slightly more complex here, like parse the preprocessor stderr to get just the showIncludes lines, and then put just those in the compiler stdout.

@alexcrichton
Copy link
Contributor Author

Thanks for the review! It'll take a bit I think to get time to cover the comments, but I'll dig in as soon as I get a chance.

@alexcrichton
Copy link
Contributor Author

According to https://msdn.microsoft.com/en-us/library/hdkef6tk.aspx

The /showIncludes option emits to stderr, not stdout.

This seems empirically false...

Helps avoid some extra indentation
Just do a simple translation from `/foo` to `-foo`
Track the `-showIncludes` flag being passed down to the compilation itself, and
then also be sure to thread the entire output of the preprocessor down to
compilations instead of just stdout. Once that was done support was implemented
by simply prepending the preprocessor stderr to the compiler stderr if the
`-showIncludes` flag was passed.
// means that the "show includes" business when to stderr. Normally, though,
// the compiler emits `-showIncludes` output to stdout. To handle that we
// take the stderr of the preprocessor and prepend it to the stdout of the
// compilation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at some point we'll want to do something like this for all compilers to fix #72, but we'll probably have to put the warnings on stderr for compatibility.

@luser luser merged commit 334359c into mozilla:master Apr 11, 2017
@alexcrichton
Copy link
Contributor Author

Oh sorry I pushed an update but then confused myself as to how it could work at all! I'm not actually sure how this patch works but maybe I'm missing something?

We recreate stderr_bytes but don't add include lines to it, so I'm not sure how this reaches the final compiler's output. When manually executing sccache cl foo.c -c -showIncludes though it seems to work!

@alexcrichton alexcrichton deleted the msvc-ninja branch April 11, 2017 14:22
@alexcrichton
Copy link
Contributor Author

Oh so it turns out my cl.exe was totally broken for other resons for totally unrelated reasons. I'll send a follow-up patch.

@alexcrichton
Copy link
Contributor Author

Ok, I've sent a PR which I believe fixes the issue: #106

@alexcrichton
Copy link
Contributor Author

Sorry for the runaround!

crystalin pushed a commit to PureStake/sccache that referenced this pull request Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants