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

Support both -arg and /arg with msvc/clang-cl without altering paths #674

Merged
merged 1 commit into from
Feb 28, 2020

Conversation

glandium
Copy link
Collaborator

34c6f9a added support for /arg flags by replacing the initial slash with
a -, and falling back to normal argument parsing. Unfortunately, when
running clang-cl on a non-Windows system, that means absolute paths get
garbled, and that can lead to bad argument parsing with separate
arguments (e.g. -I /absolute/path).

We change the arguments definition for MSVC to include both styles, by
hacking up a macro that generates two lists, one with - arguments, and
one with / arguments. Merging the two lists at build time doesn't seem
possible without going full procedural macro.

Fixes #669

34c6f9a added support for /arg flags by replacing the initial slash with
a -, and falling back to normal argument parsing. Unfortunately, when
running clang-cl on a non-Windows system, that means absolute paths get
garbled, and that can lead to bad argument parsing with separate
arguments (e.g. -I /absolute/path).

We change the arguments definition for MSVC to include both styles, by
hacking up a macro that generates two lists, one with - arguments, and
one with / arguments. Merging the two lists at build time doesn't seem
possible without going full procedural macro.

Fixes mozilla#669
@emilio
Copy link
Contributor

emilio commented Feb 27, 2020

Merging the two lists at build time doesn't seem
possible without going full procedural macro.

Doesn't this achieve what you want?

diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs
index 3302856..7197b8c 100644
--- a/src/compiler/msvc.rs
+++ b/src/compiler/msvc.rs
@@ -229,8 +229,10 @@ use self::ArgData::*;
 
 macro_rules! msvc_args {
     (static ARGS: [$t:ty; _] = [$($macro:ident ! ($($v:tt)*),)*]) => {
-        counted_array!(static ARGS: [$t; _] = [$(msvc_args!(@one "-", $macro!($($v)*)),)*]);
-        counted_array!(static SLASH_ARGS: [$t; _] = [$(msvc_args!(@one "/", $macro!($($v)*)),)*]);
+        counted_array!(static ARGS: [$t; _] = [
+            $(msvc_args!(@one "-", $macro!($($v)*)),)*
+            $(msvc_args!(@one "/", $macro!($($v)*)),)*
+        ]);
     };
     (@one $prefix:expr, msvc_take_arg!($s:expr, $($t:tt)*)) => {
         take_arg!(concat!($prefix, $s), $($t)+)
@@ -284,7 +286,7 @@ pub fn parse_arguments(
     let mut show_includes = false;
     let mut xclangs: Vec<OsString> = vec![];
 
-    for arg in ArgsIter::new(arguments.iter().cloned(), (&ARGS[..], &SLASH_ARGS[..])) {
+    for arg in ArgsIter::new(arguments.iter().cloned(), &ARGS[..]) {
         let arg = try_or_cannot_cache!(arg, "argument parse");
         match arg.get_data() {
             Some(TooHardFlag) | Some(TooHard(_)) | Some(TooHardPath(_)) => {

@froydnj
Copy link
Contributor

froydnj commented Feb 27, 2020

This doesn't work because of the requirement of ARGS to be sorted. (I'm having trouble figuring out where we actually use this fact, but glandium pointed out the same thing to me when I made this argument last night and we do have tests for non-sorted arg arrays panic'ing, so I assume it must make a difference somewhere...)

@glandium
Copy link
Collaborator Author

We're using a binary search in args.rs, which requires the list to be sorted. @emilio's diff would work if there wasn't the "@" argument. I tried something similar to that diff with a scheme to eliminate non-msvc_* arguments in prefixed passes and a final non-prefixed pass without the msvc_* arguments, but all I ended up with was this tweet: https://twitter.com/MikeHommey/status/1232932709409771522

@glandium glandium merged commit 2aadef2 into mozilla:master Feb 28, 2020
@glandium glandium deleted the dash-slash-clang-cl branch February 28, 2020 00:08
@peterjc123
Copy link
Contributor

peterjc123 commented Apr 16, 2020

Caching is broken for commands like cl /c /EHsc a.cpp after this PR.
Related log:

DEBUG 2020-04-16T08:04:08Z: sccache::server: handle_client: compile
DEBUG 2020-04-16T08:04:08Z: sccache::server: check_compiler: Supported compiler
DEBUG 2020-04-16T08:04:08Z: sccache::server: parse_arguments: CannotCache(multiple input files): ["/c", "/EHsc", "a.cpp"]

But if I change to cl /c -EHsc a.cpp, it is working.

DEBUG 2020-04-16T08:02:45Z: sccache::server: handle_client: compile
DEBUG 2020-04-16T08:02:45Z: sccache::server: check_compiler: Supported compiler
DEBUG 2020-04-16T08:02:45Z: sccache::server: parse_arguments: Ok: ["/c", "-EHsc", "a.cpp"]
DEBUG 2020-04-16T08:02:45Z: sccache::compiler::compiler: [a.obj]: get_cached_or_compile: ["/c", "-EHsc", "a.cpp"]
DEBUG 2020-04-16T08:02:45Z: sccache::compiler::msvc: preprocess: Some("C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\cl.EXE" "-E" "a.cpp" "-nologo" "-EHsc")
DEBUG 2020-04-16T08:02:45Z: sccache::compiler::compiler: [a.obj]: generate_hash_key took 0.232 s

@glandium
Copy link
Collaborator Author

Please open a new issue.

@peterjc123
Copy link
Contributor

@glandium No problem.

mostynb added a commit to mostynb/sccache that referenced this pull request Jun 1, 2020
mozilla#674 broke caching for msvc /foo style arguments that weren't
handled in our arg list. So let's expand that list.

Fixes mozilla#725.
mostynb added a commit to mostynb/sccache that referenced this pull request Jun 1, 2020
mozilla#674 broke caching for msvc /foo style arguments that weren't
handled in our arg list. So let's expand that list.

Fixes mozilla#725.
froydnj pushed a commit that referenced this pull request Jun 1, 2020
#674 broke caching for msvc /foo style arguments that weren't
handled in our arg list. So let's expand that list.

Fixes #725.
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.

sccache doesn't support clang-cl on non-Windows
4 participants