Skip to content

Commit 4951c39

Browse files
committed
Address PR feedback: vcpkg auto-restore, build improvements
Build script improvements: - Add vcpkg install to Build.bat with vswhere-based vcpkg discovery - Add _RestoreVcpkgDependencies MSBuild target (modeled after official vcpkg VcpkgInstallManifestDependencies) that auto-runs vcpkg install on first VS/dotnet build — uses stamp file for incrementality - Scope vcpkg restore target to GVFS.Common to avoid parallel conflicts - Move vcpkg output from src/vcpkg_installed/ to out/vcpkg_installed/ - Declare overlay-ports and overlay-triplets in vcpkg-configuration.json - Restore explicit CI vcpkg step using preinstalled VCPKG_INSTALLATION_ROOT - Exclude GVFS.MSBuild from libgit2 Content items (IncludeBuildOutput=false) - Remove vcpkg_installed/ from .gitignore (no longer in git root) Code fix: - Update giterr_last P/Invoke to git_error_last (deprecated since libgit2 0.28) Assisted-by: Claude Opus 4.6 Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
1 parent 8f25747 commit 4951c39

7 files changed

Lines changed: 118 additions & 10 deletions

File tree

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ jobs:
208208
if: steps.skip.outputs.result != 'true'
209209
shell: cmd
210210
run: |
211-
"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows-static-aot --overlay-triplets=src\triplets --overlay-ports=src\overlays --x-install-root=src\vcpkg_installed\static --x-manifest-root=src || exit /b 1
212-
"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows-dynamic --overlay-triplets=src\triplets --overlay-ports=src\overlays --x-install-root=src\vcpkg_installed\dynamic --x-manifest-root=src || exit /b 1
211+
"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows-static-aot --x-install-root=out\vcpkg_installed\static --x-manifest-root=src || exit /b 1
212+
"%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" install --triplet x64-windows-dynamic --x-install-root=out\vcpkg_installed\dynamic --x-manifest-root=src || exit /b 1
213213
214214
- name: Build VFS for Git
215215
if: steps.skip.outputs.result != 'true'

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,4 @@ ModelManifest.xml
229229

230230
# ProjFS Kext Unit Test coverage results
231231
ProjFS.Mac/CoverageResult.txt
232-
# vcpkg build output (rebuilt locally via vcpkg install)
233-
vcpkg_installed/
232+

Directory.Build.props

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
See THIRD-PARTY-NOTICES.md for license details on these native libraries.
5656
-->
5757
<PropertyGroup Condition="'$(PublishAot)' == 'true'">
58-
<VcpkgInstalledDir>$(RepoSrcPath)vcpkg_installed\static\x64-windows-static-aot\</VcpkgInstalledDir>
58+
<VcpkgInstalledDir>$(RepoOutPath)vcpkg_installed\static\x64-windows-static-aot\</VcpkgInstalledDir>
5959
</PropertyGroup>
6060

6161
<!-- Set libgit2 library name unconditionally — all builds use vcpkg-sourced libgit2 -->
@@ -83,18 +83,18 @@
8383
Non-AOT projects (tests) need git2.dll for runtime P/Invoke.
8484
Copy from the vcpkg dynamic build output.
8585
-->
86-
<ItemGroup Condition="'$(PublishAot)' != 'true' and '$(MSBuildProjectExtension)' == '.csproj'">
87-
<Content Include="$(RepoSrcPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\git2.dll">
86+
<ItemGroup Condition="'$(PublishAot)' != 'true' and '$(MSBuildProjectExtension)' == '.csproj' and '$(IncludeBuildOutput)' != 'false'">
87+
<Content Include="$(RepoOutPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\git2.dll">
8888
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
8989
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
9090
<Link>git2.dll</Link>
9191
</Content>
92-
<Content Include="$(RepoSrcPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\pcre.dll">
92+
<Content Include="$(RepoOutPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\pcre.dll">
9393
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9494
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
9595
<Link>pcre.dll</Link>
9696
</Content>
97-
<Content Include="$(RepoSrcPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\z.dll">
97+
<Content Include="$(RepoOutPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\z.dll">
9898
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
9999
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
100100
<Link>z.dll</Link>

Directory.Build.targets

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,75 @@
1212
<!-- Include custom MSBuild targets/tasks -->
1313
<Import Project="$(MSBuildThisFileDirectory)GVFS\GVFS.MSBuild\GVFS.targets" />
1414

15+
<!--
16+
Auto-restore vcpkg native dependencies when missing.
17+
Modeled after vcpkg's official VcpkgInstallManifestDependencies target
18+
(scripts/buildsystems/msbuild/vcpkg.targets), adapted for .csproj projects
19+
and dual-triplet installs (static-aot + dynamic).
20+
21+
Key differences from official vcpkg.targets:
22+
- Hooks PrepareForBuild instead of ClCompile (which doesn't exist in csproj)
23+
- Installs two triplets (static for AOT linking, dynamic for runtime P/Invoke)
24+
- Outputs to out/vcpkg_installed/ instead of src/vcpkg_installed/
25+
- Discovers vcpkg via VCPKG_INSTALLATION_ROOT, VS-bundled path, or PATH
26+
27+
Stamp file pattern: the target uses Inputs/Outputs so MSBuild skips it entirely
28+
when the manifests haven't changed and the stamp file is up-to-date.
29+
Build.bat also runs vcpkg install upfront, making this a no-op for CLI builds.
30+
-->
31+
<PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
32+
<_VcpkgManifestFile>$(RepoSrcPath)vcpkg.json</_VcpkgManifestFile>
33+
<_VcpkgConfigFile>$(RepoSrcPath)vcpkg-configuration.json</_VcpkgConfigFile>
34+
<_VcpkgStampFile>$(RepoOutPath)vcpkg_installed\.msbuildstamp</_VcpkgStampFile>
35+
</PropertyGroup>
36+
37+
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
38+
<_VcpkgManifestInputs Include="$(_VcpkgManifestFile)" />
39+
<_VcpkgManifestInputs Include="$(_VcpkgConfigFile)" Condition="Exists('$(_VcpkgConfigFile)')" />
40+
</ItemGroup>
41+
42+
<Target Name="_RestoreVcpkgDependencies"
43+
BeforeTargets="PrepareForBuild;ComputeFilesToPublish"
44+
Condition="'$(MSBuildProjectName)' == 'GVFS.Common'"
45+
Inputs="@(_VcpkgManifestInputs)"
46+
Outputs="$(_VcpkgStampFile)">
47+
48+
<!-- Locate vcpkg: VCPKG_INSTALLATION_ROOT > VS-bundled > PATH -->
49+
<PropertyGroup>
50+
<_VcpkgExe Condition="Exists('$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe')">$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe</_VcpkgExe>
51+
<_VcpkgExe Condition="'$(_VcpkgExe)' == '' and Exists('$(VsInstallRoot)\VC\vcpkg\vcpkg.exe')">$(VsInstallRoot)\VC\vcpkg\vcpkg.exe</_VcpkgExe>
52+
<_VcpkgManifestArg>--x-manifest-root="$(RepoSrcPath.TrimEnd('\'))"</_VcpkgManifestArg>
53+
</PropertyGroup>
54+
55+
<!-- For dotnet build (no VsInstallRoot): find VS-bundled vcpkg via vswhere -->
56+
<Exec Command="&quot;$(MSBuildProgramFiles32)\Microsoft Visual Studio\Installer\vswhere.exe&quot; -latest -products * -property installationPath"
57+
ConsoleToMSBuild="true" IgnoreExitCode="true" StandardOutputImportance="low"
58+
Condition="'$(_VcpkgExe)' == ''">
59+
<Output TaskParameter="ConsoleOutput" PropertyName="_VsInstallPath" />
60+
</Exec>
61+
<PropertyGroup Condition="'$(_VcpkgExe)' == '' and '$(_VsInstallPath)' != '' and Exists('$(_VsInstallPath)\VC\vcpkg\vcpkg.exe')">
62+
<_VcpkgExe>$(_VsInstallPath)\VC\vcpkg\vcpkg.exe</_VcpkgExe>
63+
</PropertyGroup>
64+
65+
<!-- Final fallback: bare vcpkg on PATH -->
66+
<PropertyGroup Condition="'$(_VcpkgExe)' == ''">
67+
<_VcpkgExe>vcpkg</_VcpkgExe>
68+
</PropertyGroup>
69+
70+
<Message Importance="high" Text="[vcpkg] Installing native dependencies to $(RepoOutPath)vcpkg_installed\" />
71+
72+
<MakeDir Directories="$(RepoOutPath)vcpkg_installed\" />
73+
<Exec Command="&quot;$(_VcpkgExe)&quot; install --x-wait-for-lock --triplet x64-windows-static-aot --x-install-root=&quot;$(RepoOutPath)vcpkg_installed\static&quot; $(_VcpkgManifestArg)"
74+
StandardOutputImportance="High" StandardErrorImportance="High" />
75+
<Exec Command="&quot;$(_VcpkgExe)&quot; install --x-wait-for-lock --triplet x64-windows-dynamic --x-install-root=&quot;$(RepoOutPath)vcpkg_installed\dynamic&quot; $(_VcpkgManifestArg)"
76+
StandardOutputImportance="High" StandardErrorImportance="High" />
77+
78+
<Error Condition="!Exists('$(RepoOutPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\git2.dll')"
79+
Text="vcpkg install completed but expected output files are missing. Check vcpkg output above for errors." />
80+
81+
<Touch Files="$(_VcpkgStampFile)" AlwaysCreate="true" />
82+
</Target>
83+
1584
<!--
1685
Copy native C++ hook executables and managed peer executables to GVFS.exe
1786
output directory. In a production install all binaries are co-located in one

GVFS/GVFS.Common/Git/LibGit2Repo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ public static string GetLastError()
483483
return Marshal.PtrToStructure<GitError>(ptr).Message;
484484
}
485485

486-
[DllImport(Git2NativeLibName, EntryPoint = "giterr_last")]
486+
[DllImport(Git2NativeLibName, EntryPoint = "git_error_last")]
487487
private static extern IntPtr GetLastGitError();
488488

489489
[StructLayout(LayoutKind.Sequential)]

scripts/Build.bat

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,44 @@ dotnet restore "%VFS_SRCDIR%\GVFS.sln" ^
3232
/v:%VERBOSITY% ^
3333
/p:Configuration=%CONFIGURATION% || GOTO ERROR
3434

35+
ECHO ^*************************************
36+
ECHO ^* Installing vcpkg native libraries *
37+
ECHO ^*************************************
38+
IF EXIST "%VFS_OUTDIR%\vcpkg_installed\dynamic\x64-windows-dynamic\bin\git2.dll" (
39+
ECHO INFO: vcpkg native libraries already present, skipping install.
40+
GOTO :VCPKG_DONE
41+
)
42+
SET VCPKG_EXEC=
43+
IF DEFINED VCPKG_INSTALLATION_ROOT (
44+
IF EXIST "%VCPKG_INSTALLATION_ROOT%\vcpkg.exe" (
45+
SET "VCPKG_EXEC=%VCPKG_INSTALLATION_ROOT%\vcpkg.exe"
46+
GOTO :FOUND_VCPKG
47+
)
48+
)
49+
FOR /F "tokens=* USEBACKQ" %%F IN (`where vcpkg.exe 2^>nul`) DO (
50+
SET "VCPKG_EXEC=%%F"
51+
GOTO :FOUND_VCPKG
52+
)
53+
REM Try VS-bundled vcpkg via vswhere
54+
SET VSWHERE_VCPKG="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
55+
IF EXIST %VSWHERE_VCPKG% (
56+
FOR /F "tokens=* USEBACKQ" %%F IN (`%VSWHERE_VCPKG% -latest -products * -property installationPath`) DO (
57+
IF EXIST "%%F\VC\vcpkg\vcpkg.exe" (
58+
SET "VCPKG_EXEC=%%F\VC\vcpkg\vcpkg.exe"
59+
GOTO :FOUND_VCPKG
60+
)
61+
)
62+
)
63+
ECHO ERROR: vcpkg.exe not found. Install vcpkg or set VCPKG_INSTALLATION_ROOT.
64+
ECHO See https://learn.microsoft.com/en-us/vcpkg/get-started/get-started
65+
EXIT /B 1
66+
67+
:FOUND_VCPKG
68+
ECHO INFO: Using vcpkg at '%VCPKG_EXEC%'
69+
"%VCPKG_EXEC%" install --triplet x64-windows-static-aot --x-install-root="%VFS_OUTDIR%\vcpkg_installed\static" --x-manifest-root="%VFS_SRCDIR%" || GOTO ERROR
70+
"%VCPKG_EXEC%" install --triplet x64-windows-dynamic --x-install-root="%VFS_OUTDIR%\vcpkg_installed\dynamic" --x-manifest-root="%VFS_SRCDIR%" || GOTO ERROR
71+
:VCPKG_DONE
72+
3573
ECHO ^**************************
3674
ECHO ^* Building C++ Projects *
3775
ECHO ^**************************

vcpkg-configuration.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"$comment": "Pin the vcpkg default registry to a known baseline for reproducible builds.",
3+
"overlay-ports": ["./overlays"],
4+
"overlay-triplets": ["./triplets"],
35
"default-registry": {
46
"kind": "git",
57
"repository": "https://github.com/microsoft/vcpkg",

0 commit comments

Comments
 (0)