Skip to content

Manifests should install dependencies earlier in build process, before the CustomBuild target #20830

@aggieNick02

Description

@aggieNick02

Describe the bug
Manifests should install dependencies before the CustomBuild target because their failure to do so means custom build tool items in a project cannot reliably use vcpkg installed dependencies.

This bug/issue is motivated by tools such as grpc and protobuf, which provide code generation tools to generate .h,.cpp.,.py files and more. A typical way to use them is to add a .proto file to your project and provide a custom build action that invokes protoc.exe or one of the grpc tools, generating files that are also part of the project.

grpc and protobuf are both ports in vcpkg, so vcpkg is a natural way to obtain them. Then the custom build action can just point to their tools in the vcpkg installed directory, e.g., "$(_ZVcpkgCurrentInstalledDir)tools\protobuf\protoc.exe"

The problem comes when using manifest mode. The targets in vcpkg.targets are specified with BeforeTargets=ClCompile, which means that the manifest dependencies are installed after any files with custom build tools specified are processed. That is, in a clean setup where vcpkg has not installed anything, a .proto file will fail to be processed by the protobuf or grpc tools that are specified, because those tools do not have a chance to be installed until after the .proto file is compiled

Simply changing VcpkgInstallManifestDependencies and VcpkgTripletSelection in vcpkg.targets to have BeforeTargets="CustomBuild" BeforeTargets="CustomBuild;ClCompile"addresses the issue. Note: I updated from the strikethrough to include both ClCompile and CustomBuild, since not specifying ClCompile breaks the most common usage :-P . But even this isn't great, as it doesn't cover other build actions, e.g., CudaBuild as hit by @dahubley in #20884 .

Is there any reason to not make this change in vcpkg.targets? I'm happy to submit the PR, but I'm not an expert in msbuild and the targets, so I'm not 100% sure that won't have any side effects.

Environment

  • OS: Windows
  • Compiler: Visual Studio 2019

To Reproduce
Steps to reproduce the behavior:

  1. .Get vcpkg and run .\bootstrap_vcpkg.bat, and then .\vcpkg.exe integrate install
  2. Create a new console app project and solution.
  3. Set the new project to use manifests in the vcpkg project properties.
  4. Create a vcpkg.json manifest next to the solution with the contents:
{
    "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json",
    "name": "sample-manifest",
    "version": "0.1",
    "dependencies": [
        {
            "name": "presentmon",
            "features": ["tools"]
        }
    ]
}
  1. Add a text file to your project. Right click on the text file and choose properties. Change the item type to "Custom Build Tool." Hit ok.
  2. Right click on the text file and choose to compile. When it completes, notice that there is not yet a vcpkg_installed\x86-windows\... hierarchy next to vcpkg.json or any mention in the compile output about vcpkg installing dependencies. This is the bug/issue - because custom build tool items don't cause vcpkg dependencies to install, they can't reliably use them.
  3. Right click on the console application cpp file and choose to compile. Notice the vcpkg manifest dependencies are now installed.

Expected behavior
Install manifest dependencies before any custom build items run

Failure logs
N/A

Additional context
N/A

Metadata

Metadata

Labels

category:vcpkg-featureThe issue is a new capability of the tool that doesn’t already exist and we haven’t committedinfo:manifestsThis PR or Issue pertains to the Manifests feature

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions