Merged PR 616796: [Github Issue] Building bxl fails with missing VisualCppTools NuGet package

- Update MSVC package to 14.16.27034
- Update internal feed to use VisualCppTools.Internal.VS2017Layout from devdiv feed.
- Update external build instructions to get user to download visual studio build tools manually.
- Add Qspectre flag to msvc.
- Ignore some newer warnings being hit on windows sdk source files.

Related work items: #1846018
This commit is contained in:
Pasindu Gunasekara 2021-07-14 21:21:37 +00:00
Родитель 0715e38a7c
Коммит 8d04598d33
19 изменённых файлов: 168 добавлений и 12 удалений

Просмотреть файл

@ -2,6 +2,7 @@
## Windows
* You should use Windows 10 with BuildXL. You do not need to install [Visual Studio](https://visualstudio.microsoft.com/vs/) to get a working build, but it can be very helpful and is recommended for Windows development.
* You will also need to install the Windows development kit. When you build the repo, the build script will determine if you have a compatible version installed and provide an error message with a link if one needs to be installed
* [Visual Studio 2019 Build Tools](https://visualstudio.microsoft.com/downloads/) build tools must be installed. Scroll down to the "Tools for Visual Studio 2019" section, download and run the installer for "Build Tools for Visual Studio 2019". Within the Visual Studio installer under "Individual Components", search for and install "MSVC (v142) - VS 2019 C++ x64/x86 Spectre-mitigated libs (v14.29-16.10)".
## macOS
To run BuildXL on macOS you need to install:

Просмотреть файл

@ -0,0 +1,20 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
import {Transformer} from "Sdk.Transformers";
// This is an empty facade for a Microsoft internal package.
namespace Contents {
export declare const qualifier: {
};
@@public
export const all: StaticDirectory = Transformer.sealDirectory({
root: d`.`,
files: []
});
}
@@public
export const pkg: NugetPackage = {contents: Contents.all, dependencies: []};

Просмотреть файл

@ -0,0 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
module({
name: "VisualCppTools.Internal.VS2017Layout",
projects: [f`VisualCppTools.Internal.VS2017Layout.dsc`]
});

Просмотреть файл

@ -147,7 +147,8 @@ namespace Binary {
sources: undefined,
preprocessorSymbols: [
{name: "_STL_WARNING_LEVEL", value: "3" }
]
],
enableSpectreVariantOneMitigation: true,
};
/** Computes all the include search paths from the NativeBinaryArguments */

Просмотреть файл

@ -105,6 +105,7 @@ export function evaluate(args: Arguments): File {
workingDirectory: Context.getSpecFileDirectory(),
dependencies: includes,
arguments: cmdArgs,
allowedSurvivingChildProcessNames: importFrom("VisualCpp").clToolSurvivingChildProcesses,
});
return outputs.getOutputFile(outFile);

Просмотреть файл

@ -265,6 +265,7 @@ function evaluateOneSourceFile(
"telemetry:cl",
...(args.tags || [])
],
allowedSurvivingChildProcessNames: importFrom("VisualCpp").clToolSurvivingChildProcesses,
});
let compOutput = <CompilationOutput> {
@ -448,6 +449,7 @@ function optionsToCmdLineArgs(opts: ClOptions, includeLocalDir: boolean, include
Cmd.sign("/guard:cf", opts.guardControlFlow, true),
Cmd.flag("/Brepro", opts.compilerDeterminism),
Cmd.flag("/ZH:SHA_256", opts.useSha256ForChecksum),
Cmd.flag("/Qspectre", opts.enableSpectreVariantOneMitigation),
];
}
@ -1232,6 +1234,12 @@ export interface ClOptions {
*/
@@Tool.option("/ZH:SHA_256")
useSha256ForChecksum?: boolean;
/**
* The compiler will generate instructions to mitigate certain Spectre variant 1 vulnerabilities.
*/
@@Tool.option("/Qspectre")
enableSpectreVariantOneMitigation?: boolean;
}
/**

Просмотреть файл

@ -9,8 +9,9 @@ export declare const qualifier: {
platform: "x86" | "x64";
};
const pkgContents = importFrom("VisualCppTools.Community.VS2017Layout").Contents.all;
const rootFolder = r`lib/native`;
const isInternal = Environment.getFlag("[Sdk.BuildXL]microsoftInternal"); // Indicates whether to use the MSVC nuget package
const pkgContents = getMsvcPackage();
const rootFolder = isInternal ? r`lib/native` : r`.`;
@@public
export const cvtResTool = createMsvcTool(a`CvtRes.exe`, "Microsoft Resource to Object Converter");
@ -38,6 +39,14 @@ export const include = pkgContents.ensureContents({subFolder: r`${rootFolder}/in
@@public
export const lib = pkgContents.ensureContents({subFolder: r`${rootFolder}/lib/${qualifier.platform}`});
/**
* Gets a list of surviving child processes that cl.exe may create. NOTE: Do not add any
* processes here that write meaningful outputs to disk.
* VCTIP.EXE - "VC++ Technology Improvement Program" uploader used for telemetry.
*/
@@public
export const clToolSurvivingChildProcesses : PathAtom[] = [a`VCTIP.EXE`];
// narrowed down sealed directory with just the tools folder
const toolContents = pkgContents.ensureContents({subFolder: r`${rootFolder}/bin/${"Host" + qualifier.platform}/${qualifier.platform}`});
@ -52,5 +61,58 @@ function createMsvcTool(exe: PathAtom, description: string) : Transformer.ToolDe
prepareTempDirectory: true,
dependsOnWindowsDirectories: true,
dependsOnAppDataDirectory: true,
untrackedDirectoryScopes: [
d`${Context.getMount("ProgramData").path}/microsoft/netFramework/breadcrumbStore`,
// cl.exe or child processes will create this directory if it doesn't exist
// Then it will write MachineStorage.dat and MachineStorage.dat.bak to it.
d`${Context.getMount("ProgramData").path}/Microsoft Visual Studio`,
// Temporary state files accessed by VCTIP.EXE
d`${Context.getMount("ProgramData").path}/Microsoft/VisualStudio/Packages`,
],
runtimeDependencies: [
f`${Context.getMount("ProgramData").path}/Microsoft/VisualStudio/Setup/${qualifier.platform}/Microsoft.VisualStudio.Setup.Configuration.Native.dll`,
],
};
}
/**
* When building internally, returns the VisualCppTools.Internal.VS2017Layout package.
* When building externally, search for the Visual Studio 2017 build tools directory.
*/
function getMsvcPackage() : StaticDirectory {
// The VisualCppTools.Community.VS2017Layout package has been deprecated for external users.
// Due to this, when building externally, the Visual C++ build tools must be installed manually.
// Please see the BuildXL README on how to build externally.
if (isInternal) {
return importFrom("VisualCppTools.Internal.VS2017Layout").Contents.all;
}
else {
let msvcVersions = [
"14.29.30037"
];
// ADO will set this variable if the version above is not installed
if (Environment.hasVariable("MSVC_VERSION")) {
msvcVersions = msvcVersions.push(Environment.getStringValue("MSVC_VERSION"));
}
const buildToolsDirectories = [
d`${Context.getMount("ProgramFilesX86").path}/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC`,
d`${Context.getMount("ProgramFilesX86").path}/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC`,
];
for (let buildToolsDirectory of buildToolsDirectories)
{
for (let version of msvcVersions)
{
const dir = d`${buildToolsDirectory.path}/${version}`;
if (Directory.exists(dir)) {
return Transformer.sealDirectory(dir, globR(dir, "*"));
}
}
}
Contract.fail(`Prerequisite Visual Studio 2017 build tools not found at any of the following locations: '${buildToolsDirectories}'. Please see BuildXL/Documentation/Wiki/DeveloperGuide.md on how to acquire these tools for building externally.`);
}
}

Просмотреть файл

@ -6,6 +6,12 @@
// Disable warnings about unreferenced inline functions. We'd do this below but this disable has to be in effect
// at optimization time.
#pragma warning( disable : 4514 4710 4191)
// 'function': pointer or reference to potentially throwing function passed to extern C function under -EHc. Undefined behavior may occur if this function throws an exception.
// Thrown for source files included from the Windows SDK.
#pragma warning( disable : 5039)
// warning C5045: Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
// The /Qspectre flag has been specified to mitigate this, however this warning will continue to show up with /Wall enabled
#pragma warning( disable : 5045)
#define WIN32_LEAN_AND_MEAN

Просмотреть файл

@ -15,6 +15,10 @@
// We don't care about the addition of needed struct padding.
#pragma warning( disable : 4820 )
// warning C5045: Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
// This spectre mitigation has been applied to detours, however this warning will continue to show up with /Wall enabled
#pragma warning( disable : 5045)
// BuildXL should run on Win7+.
#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_WIN7

Просмотреть файл

@ -1,10 +1,11 @@
// dllmain.cpp : Defines the entry point for the DLL application.
// Disable warnings about unreferenced inline functions. We'd do this below but this disable has to be in effect
// at optimization time.
#pragma warning( disable : 4514 4710 )
#pragma warning( disable : 4514 4710 5045 )
// C4820 'bytes' bytes padding added after construct 'member_name' hit on certain Windows SDK headers
#pragma warning( push )
#pragma warning( disable : 4350 4668 )
#pragma warning( disable : 4350 4668 4820 )
#include <windows.h>
#include <string>
#include <iostream>

Просмотреть файл

@ -730,8 +730,11 @@ bool ParseFileAccessManifest(
if (*g_manifestSizePtr <= sizeof(size_t))
{
#pragma warning( push ) //warning C4777: 'wprintf' : format string '%llu' requires an argument of type 'unsigned __int64', but variadic argument 2 has type 'size_t'
#pragma warning( disable : 4777)
wprintf(L"Error bad payload size %d:%llu.", (int)*g_manifestSizePtr, (unsigned long long)sizeof(size_t));
fwprintf(stderr, L"Error bad payload size %d:%llu.", (int)*g_manifestSizePtr, (unsigned long long)sizeof(size_t));
#pragma warning( pop )
HandleDetoursInjectionAndCommunicationErrors(DETOURS_PAYLOAD_PARSE_FAILED_14, L"Error bad payload size: exit(-56).", DETOURS_WINDOWS_LOG_MESSAGE_14);
return false;
}

Просмотреть файл

@ -31,6 +31,7 @@
#include "SendReport.h"
#include <Psapi.h>
#include "FilesCheckedForAccess.h"
#include "locale.h"
#define BUILDXL_DETOURS_CREATE_PROCESS_RETRY_COUNT 5
#define BUILDXL_DETOURS_INJECT_PROCESS_RETRY_COUNT 5
@ -1210,6 +1211,8 @@ static bool DllProcessAttach()
// Next, attach to (detour) each API function of interest.
if (!DisableDetours())
{
#pragma warning( push )
#pragma warning( disable : 5039)
ATTACH(CreateProcessA);
ATTACH(CreateProcessW);
@ -1284,6 +1287,7 @@ static bool DllProcessAttach()
// on this function.
ATTACH(NtClose);
ATTACH(ZwSetInformationFile);
#pragma warning( pop )
}
else {
Dbg(L"File detours are disabled while running inside of WinDbg. Child processes will still be detoured.");

Просмотреть файл

@ -3,7 +3,7 @@
#pragma once
#pragma warning(disable: 4710)
#pragma warning(disable: 4710 5045)
#define EXPORT __declspec( dllexport )

Просмотреть файл

@ -16,6 +16,13 @@
// Allegedly triggered by HandleOverlay.cpp, but suppressing there doesn't work for some reason.
#pragma warning (disable : 4350)
// warning C5039: 'function': pointer or reference to potentially throwing function passed to extern C function under -EHc. Undefined behavior may occur if this function throws an exception.
// Setting /Wall will cause this to get hit for many that the Windows SDK violates in almost every source file in detours.
#pragma warning( disable : 5039)
// warning C5045: Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
// This spectre mitigation has been applied to detours, however this warning will continue to show up with /Wall enabled
#pragma warning( disable : 5045)
// In order to compile with /Wall (mega pedantic warnings), we need to turn off a few that the Windows SDK violates.
// We could do this in stdafx.cpp so long as a precompiled header is being generated, since the compiler state from
// that file (including warning state!) would be dumped to the .pch - instead, we stick to the sane compilation

Просмотреть файл

@ -15,6 +15,10 @@
// We don't care about the addition of needed struct padding.
#pragma warning( disable : 4820 )
// warning C5045: Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
// This spectre mitigation has been applied to detours, however this warning will continue to show up with /Wall enabled
#pragma warning( disable : 5045)
// BuildXL should run on Win7+.
#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_WIN7
@ -34,4 +38,4 @@
#include <string>
#include <vector>
#include <memory>
#pragma warning( pop )
#pragma warning( pop )

Просмотреть файл

@ -0,0 +1,17 @@
## Sets the MSVC Version to be used the VisualCpp SDK in ADO
$InstalledMsvcVersions=Get-ChildItem -Path 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC' -Directory -Name
$PIPELINE_MSVC_VER=$null
if ( $InstalledMsvcVersions -is [system.array] )
{
# If multiple versions are found, then set to the last one
$PIPELINE_MSVC_VER=$InstalledMsvcVersions[$InstalledMsvcVersions.Length-1]
}
else
{
$PIPELINE_MSVC_VER=$InstalledMsvcVersions
}
Write-Host "##vso[task.setvariable variable=MSVC_VERSION;]$PIPELINE_MSVC_VER"

Просмотреть файл

@ -4019,8 +4019,8 @@
"Component": {
"Type": "NuGet",
"NuGet": {
"Name": "VisualCppTools.Community.VS2017Layout",
"Version": "14.11.25506"
"Name": "VisualCppTools.Internal.VS2017Layout",
"Version": "14.16.27034"
}
}
},

Просмотреть файл

@ -50,6 +50,10 @@ config({
repositories: importFile(f`config.microsoftInternal.dsc`).isMicrosoftInternal
? {
// If nuget resolver failed to download VisualCpp tool, then download it
// manually from "BuildXL.Selfhost" feed into some folder, and specify
// that folder as the value of "MyInternal" feed below.
// "MyInternal": "E:/BuildXLInternalRepos/NuGetInternal",
"BuildXL.Selfhost": "https://pkgs.dev.azure.com/cloudbuild/_packaging/BuildXL.Selfhost/nuget/v3/index.json",
// Note: From a compliance point of view it is important that MicrosoftInternal has a single feed.
// If you need to consume packages make sure they are upstreamed in that feed.
@ -165,9 +169,6 @@ config({
{ id: "NuGet.Versioning", version: "4.6.0" }, // Can't use the latest becuase nuget extracts to folder with metadata which we don't support yet.
{ id: "NuGet.Frameworks", version: "5.0.0"}, // needed for qtest on .net core
// Cpp Sdk
{ id: "VisualCppTools.Community.VS2017Layout", version: "14.11.25506", osSkip: [ "macOS", "unix" ] },
// ProjFS (virtual file system)
{ id: "Microsoft.Windows.ProjFS", version: "1.2.19351.1" },
@ -691,5 +692,11 @@ config({
toolPath: f`${Environment.getDirectoryValue("SystemRoot")}/system32/vsjitdebugger.exe`,
pathRegex: `.*${Environment.getStringValue("CommonProgramFiles").replace("\\", "\\\\")}\\\\Microsoft Shared\\\\VS7Debug\\\\.*`
},
// cl.exe may write temporary files under its working directory
{
name: "cl.exe",
toolPath: a`cl.exe`,
pathRegex: ".*.tmp"
}
]
});

Просмотреть файл

@ -64,6 +64,9 @@ export const pkgs = isMicrosoftInternal ? [
// Internal version of Redis
{ id: "Microsoft.Caching.Redis", version: "3.0.57",
dependentPackageIdsToSkip: [ "System.Runtime.CompilerServices.Unsafe", "System.IO.Pipelines", "System.Threading.Channels", "Pipelines.Sockets.Unofficial" ] },
// Cpp Sdk
{ id: "VisualCppTools.Internal.VS2017Layout", version: "14.16.27034", osSkip: [ "macOS", "unix" ] },
] : [
// Artifact packages and dependencies in OSS