microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.18k stars 6.16k forks source link

VS/MSBuild per-project integration that "just works" #23366

Open davidmatson opened 2 years ago

davidmatson commented 2 years ago

Is your feature request related to a problem? Please describe. I want to be able use vcpkg as a submodule and enable vcpkg in a vcxproj in Visual Studio without having to add any per-user prerequisites or extra per-repo setup steps.

Proposed solution Update the vcpkg targets to support bootstrapping.

Describe alternatives you've considered Requiring users to bootstrap manually, but that makes our repo harder-to-use than before. Using the generated NuGet package via "integrate", but that adds a dependency on NuGet, which we're trying to minimize, and is not recommended via the docs.

Additional context Here's an example workaround:

vcpkg_workaround.targets:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="VcpkgBootstrap" BeforeTargets="ClCompile"
            Condition="'$(VcpkgEnabled)' == 'true'"
            Inputs="$(_ZVcpkgRoot)bootstrap-vcpkg.bat"
            Outputs="$(_ZVcpkgExecutable)">
        <Message Text="Bootstrapping vcpkg" Importance="High" />
        <Exec Command="%22$(_ZVcpkgRoot)bootstrap-vcpkg.bat%22" StandardOutputImportance="High" />
    </Target>

    <Import Project="$(MSBuildThisFileDirectory)\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets" />
</Project>

And then each project just something like:

    <Import Project="$..\vcpkg_workaround.targets" />

I imagine this question has come up before, but I couldn't find a current open issue tracking. Overall, my hope is that for folks who use VS without CMake, there can be a way to keep the repo self-contained and still "just work" when the project is opened/built for the first time.

JackBoosY commented 2 years ago

Not likely. Since some settings such as triplet and is_static are common to the solution, we always set all configurations to the solution instead of the projects.

davidmatson commented 2 years ago

It says here the triplet can set in the project: https://github.com/microsoft/vcpkg/blob/2777eada3f0608c337eced841c0023ab405e03d8/docs/users/integration.md

To override the automatically chosen triplet, you can specify the MSBuild property VcpkgTriplet in your .vcxproj.

I assume the same is true for VcpkgUseStatic.

JackBoosY commented 2 years ago

@BillyONeal What do you think about ?

JulZimmermann commented 1 year ago

Hey. I kind of have the same problem. I want to integrate vcpkg into our MSBuild solution in such a way, that my colleagues don't have to perform any additional steps to build the solution.

The documented "Import .props and .targets" approach from https://vcpkg.io/en/docs/users/buildsystems/msbuild-integration.html seems like a good way in combination with a git submodule of the vcpkg repo. (This approach is even mentioned on the documentation site.)

Unfortunately, this doesn't work, because (unlike with the CMake integration) the bootstrap script isn't called automatically.

A solution-wide (not per project) integration would be fine for me, but it's not clear to me how to set this up.

BillyONeal commented 1 year ago

@ras0219 @ras0219-msft indicates that this was not an intentional omission.

ras0219-msft commented 1 year ago

Some comments on the posted blob that should be considered before merging into vcpkg:

davidmatson commented 1 year ago

We should ensure that it (bootstrap-vcpkg.bat) is safe to call in parallel

Yes. We've been using the above blob and found that in practice that it (bootstrap-vcpkg.bat) is not safe to call in parallel. I suspect some kind of lock file or other concurrency control mechanism would be needed.

JulZimmermann commented 1 year ago

We should ensure that it (bootstrap-vcpkg.bat) is safe to call in parallel

Yes. We've been using the above blob and found that in practice that it (bootstrap-vcpkg.bat) is not safe to call in parallel. I suspect some kind of lock file or other concurrency control mechanism would be needed.

The CMake integration (via toolchain file) does call bootstrap automatically in manifest mode. So maybe a locking mechanism is implemented there already, that could be reused? Or maybe it is missing there also?

BillyONeal commented 1 year ago

So maybe a locking mechanism is implemented there already, that could be reused?

There is not. There is one CMake configure step for a whole build ever, there are many many MSBuild invocations (for each .vcxproj)

JulZimmermann commented 1 year ago

Hi, is there some progress on auto-bootstrap with MSBuild?

Thanks!

BillyONeal commented 1 year ago

Hi, is there some progress on auto-bootstrap with MSBuild?

I don't believe we plan to implement this.

However we are planning on bundling vcpkg with Visual Studio so you won't need to bootstrap at all there, at least for manifest mode.

github-actions[bot] commented 10 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

davidmatson commented 10 months ago

/keep-alive

github-actions[bot] commented 9 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

davidmatson commented 9 months ago

/keep-alive

github-actions[bot] commented 8 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

davidmatson commented 7 months ago

/keep-alive