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
13 changes: 13 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,19 @@ jobs:
$SCCACHE_EXE "$(where cl.exe)" -c "@args.rsp"
$SCCACHE_EXE --show-stats

- name: Prepare - MSBuild support
shell: bash
working-directory: ./tests/msvc-msbuild
# Force stop server to drop compiler cache - need to test showInclude prefix detection
run: |
$SCCACHE_EXE --stop-server
mkdir -p compiler
cp $SCCACHE_EXE compiler/cl.exe

- name: Compile - MSBuild support
working-directory: ./tests/msvc-msbuild
run: msbuild MsbuildCpp.vcxproj -property:Configuration=Release -property:Platform=x64 "-property:SolutionDir=${{ github.workspace }}/tests/msvc-msbuild/"

- name: Stop Server
if: success() || failure()
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,7 @@ mod test {
s = &s[4..];
}
let prefix = String::from("blah: ");
let stdout = format!("{}{}\r\n", prefix, s);
let stderr = format!("{}{}\r\n", prefix, s);
// Compiler detection output
next_command(
&creator,
Expand All @@ -1982,7 +1982,7 @@ mod test {
// showincludes prefix detection output
next_command(
&creator,
Ok(MockChild::new(exit_status(0), stdout, String::new())),
Ok(MockChild::new(exit_status(0), String::new(), stderr)),
);
let c = detect_compiler(creator, &f.bins[0], f.tempdir.path(), &[], &[], pool, None)
.wait()
Expand Down
30 changes: 15 additions & 15 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use std::collections::{HashMap, HashSet};
use std::ffi::{OsStr, OsString};
use std::io::{self, BufWriter, Read, Write};
use std::path::{Path, PathBuf};
use std::process::{self, Stdio};
use std::process;

use crate::errors::*;

Expand Down Expand Up @@ -201,13 +201,9 @@ where
if is_clang {
cmd.arg("--driver-mode=cl");
}
cmd.args(&["-nologo", "-showIncludes", "-c", "-Fonul", "-I."])
cmd.args(&["-nologo", "-showIncludes", "-c", "-Fonul", "-I.", "-E"])
.arg(&input)
.current_dir(tempdir.path())
// The MSDN docs say the -showIncludes output goes to stderr,
// but that's not true unless running with -E.
.stdout(Stdio::piped())
.stderr(Stdio::null());
.current_dir(tempdir.path());
for (k, v) in env {
cmd.env(k, v);
}
Expand All @@ -216,16 +212,20 @@ where
let output = run_input_output(cmd, None).await?;

if !output.status.success() {
bail!("Failed to detect showIncludes prefix")
warn!(
"Failed to detect showIncludes prefix (status: {:?})",
output.status.code().unwrap_or(-1)
);
}

let process::Output {
stdout: stdout_bytes,
stderr: stderr_bytes,
..
} = output;
let stdout = from_local_codepage(&stdout_bytes)
.context("Failed to convert compiler stdout while detecting showIncludes prefix")?;
for line in stdout.lines() {
let preprocessor_output = from_local_codepage(&stderr_bytes)
.context("Failed to convert compiler stderr while detecting showIncludes prefix")?;

for line in preprocessor_output.lines() {
if !line.ends_with("test.h") {
continue;
}
Expand All @@ -246,7 +246,7 @@ where

debug!(
"failed to detect showIncludes prefix with output: {}",
stdout
preprocessor_output
);

bail!("Failed to detect showIncludes prefix")
Expand Down Expand Up @@ -1416,8 +1416,8 @@ mod test {
if s.starts_with("\\\\?\\") {
s = &s[4..];
}
let stdout = format!("blah: {}\r\n", s);
let stderr = String::from("some\r\nstderr\r\n");
let stderr = format!("blah: {}\r\n", s);
let stdout = String::from("some\r\nstdout\r\n");
next_command(&creator, Ok(MockChild::new(exit_status(0), stdout, stderr)));
assert_eq!(
"blah: ",
Expand Down
4 changes: 4 additions & 0 deletions tests/msvc-msbuild/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*
!.gitignore
!*.vcxproj
!*.cpp
54 changes: 54 additions & 0 deletions tests/msvc-msbuild/MsbuildCpp.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{0e44c32e-bffa-4f4b-aac8-5db71447ce37}</ProjectGuid>
<RootNamespace>MsbuildCpp</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<!-- Based on https://medium.com/@parakram.majumdar/ccache-with-msbuild-devenv-f286778e0be7 -->
<TrackFileAccess>false</TrackFileAccess>
<UseMultiToolTask>true</UseMultiToolTask>
<CLToolExe>$(SolutionDir)/compiler/cl.exe</CLToolExe>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<!-- Also mandatory: only /Z7 mode is supported -->
<DebugInformationFormat>OldStyle</DebugInformationFormat>
</ClCompile>
<Link>
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="test_foo.cpp" />
<ClCompile Include="test_bar.cpp" />
<ClCompile Include="test_baz.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
1 change: 1 addition & 0 deletions tests/msvc-msbuild/test_bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int bar(int x) { return x; }
1 change: 1 addition & 0 deletions tests/msvc-msbuild/test_baz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int baz(int x) { return x; }
1 change: 1 addition & 0 deletions tests/msvc-msbuild/test_foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int foo(int x) { return x; }
Loading