11param (
2- [string ]$vcpkg_root = $ (if ($env: VCPKG_ROOT ) { $env: VCPKG_ROOT } else { throw " -vcpkg_root=<path to vcpkg> is required, or set VCPKG_ROOT" }),
3- [ValidateSet (' x86' , ' x64' , ' ARM' , ' ARM64' , IgnoreCase = $false )]
4- [string []]$arch = @ ( " x86" , " x64" , " ARM" , " ARM64" ),
2+ [string ]$vcpkg_root ,
3+ # x86 and ARM are not offered: libvlc and webrtc declare "supports": "uwp & (x64 | arm64)", so a
4+ # manifest install for either fails before TDLib is reached, and the app has no such platform.
5+ [ValidateSet (' x64' , ' ARM64' , IgnoreCase = $false )]
6+ [string []]$arch = @ ( " x64" , " ARM64" ),
57 [string ]$mode = " all"
68)
79$ErrorActionPreference = " Stop"
810
9- $vcpkg_root = Resolve-Path $vcpkg_root
10-
11- $vcpkg_cmake = " ${vcpkg_root} \scripts\buildsystems\vcpkg.cmake"
1211$arch_list = $arch
12+
1313$td_root = Resolve-Path " ../tdlib"
1414
15- # TDLib and the app share one manifest and one installed tree , so that openssl and zlib cannot
16- # drift between the tdjson.dll we ship and the copies the app links against.
15+ # TDLib and the app share one manifest, so that openssl and zlib cannot drift between the
16+ # tdjson.dll we ship and the copies the app links against.
1717$manifest_root = Resolve-Path " ../.."
18- $installed_root = Join-Path $manifest_root " vcpkg_installed"
1918
2019function CheckLastExitCode {
2120 if ($LastExitCode -ne 0 ) {
@@ -27,6 +26,60 @@ CALLSTACK:$(Get-PSCallStack | Out-String)
2726 }
2827}
2928
29+ # Which vcpkg, where it installs and under which triplet are all decided in Directory.Build.props.
30+ # Evaluate it per platform rather than repeating any of that here: the installed tree in particular
31+ # is one root per triplet, and a build that guessed the layout would install beside the app's tree
32+ # instead of into it - or, sharing a root across triplets, purge it.
33+ function ResolveVcpkgPaths {
34+ param ([string ]$platform )
35+
36+ $installer = Join-Path ${env: ProgramFiles(x86)} " Microsoft Visual Studio\Installer"
37+ $vswhere = Join-Path $installer " vswhere.exe"
38+ if (-not (Test-Path $vswhere )) {
39+ throw " vswhere.exe not found at $vswhere "
40+ }
41+
42+ $vs = & $vswhere - latest - prerelease - products * - requires Microsoft.Component.MSBuild - property installationPath
43+ if (-not $vs ) {
44+ throw " No Visual Studio installation with MSBuild was found."
45+ }
46+
47+ $msbuild = Join-Path $vs " MSBuild\Current\Bin\amd64\MSBuild.exe"
48+ if (-not (Test-Path $msbuild )) {
49+ throw " MSBuild.exe not found at $msbuild "
50+ }
51+
52+ # -getProperty evaluates the project, it does not build it. The stub imports the props file on
53+ # its own, so none of the C++ targets are involved; TelegramUsesVcpkg is what gates the property
54+ # there, and an explicit -vcpkg_root arrives as the global property the chain checks first.
55+ $props = Join-Path $manifest_root " Directory.Build.props"
56+ $stub = Join-Path ([System.IO.Path ]::GetTempPath()) " tdjson-vcpkg-root-$PID .proj"
57+ Set-Content - LiteralPath $stub - Value " <Project><Import Project=`" $props `" /></Project>"
58+
59+ Try {
60+ $arguments = @ ($stub , " -nologo" , " -p:TelegramUsesVcpkg=true" , " -p:Platform=$platform " ,
61+ " -getProperty:VcpkgRoot,VcpkgInstalledDir,TelegramVcpkgTriplet" )
62+ if ($vcpkg_root ) {
63+ $arguments += " -p:VcpkgRoot=$ ( (Resolve-Path $vcpkg_root ).Path) "
64+ }
65+ $json = (& $msbuild @arguments | Out-String )
66+ CheckLastExitCode
67+ } Finally {
68+ Remove-Item $stub - Force - ErrorAction SilentlyContinue
69+ }
70+
71+ $resolved = ($json | ConvertFrom-Json ).Properties
72+
73+ if (-not $resolved.VcpkgRoot ) {
74+ throw " vcpkg was not found. Clone it next to this repository, install the vcpkg component in the Visual Studio installer, or set VCPKG_ROOT - see Documentation/Build-instructions.md."
75+ }
76+ if (-not $resolved.TelegramVcpkgTriplet ) {
77+ throw " The app defines no vcpkg triplet for platform $platform , so TDLib cannot be built against the tree it uses."
78+ }
79+
80+ return $resolved
81+ }
82+
3083function clean {
3184 Remove-Item build-* - Force - Recurse - ErrorAction SilentlyContinue
3285}
@@ -53,12 +106,12 @@ function config {
53106 New-Item - ItemType Directory - Force - Path $arch
54107 cd $arch
55108 echo " ${td_root} "
56- $fixed_arch = $arch
57- if ( $arch -eq " x86 " ) {
58- $fixed_arch = " win32 "
59- }
60- $triplet = " $ ( $arch .ToLower () ) -uwp "
61- cmake - A $fixed_arch - DCMAKE_SYSTEM_VERSION= " 10.0" - DCMAKE_SYSTEM_NAME= " WindowsStore" - DCMAKE_TOOLCHAIN_FILE= " $vcpkg_cmake " - DVCPKG_MANIFEST_DIR= " $manifest_root " - DVCPKG_INSTALLED_DIR= " $installed_root " - DVCPKG_TARGET_TRIPLET= " $triplet " - DTD_ENABLE_MULTI_PROCESSOR_COMPILATION= ON " $td_root "
109+ $vcpkg = ResolveVcpkgPaths $arch
110+ $vcpkg_cmake = Join-Path $vcpkg .VcpkgRoot " scripts\buildsystems\vcpkg.cmake "
111+ # Trailing backslashes are trimmed: cmake.exe parses \" as an escaped quote, and MSBuild hands
112+ # directory properties back with one.
113+ $installed_root = $vcpkg .VcpkgInstalledDir.TrimEnd ( ' \ ' )
114+ cmake - A $arch - DCMAKE_SYSTEM_VERSION= " 10.0" - DCMAKE_SYSTEM_NAME= " WindowsStore" - DCMAKE_TOOLCHAIN_FILE= " $vcpkg_cmake " - DVCPKG_MANIFEST_DIR= " $manifest_root " - DVCPKG_INSTALLED_DIR= " $installed_root " - DVCPKG_TARGET_TRIPLET= " $ ( $vcpkg .TelegramVcpkgTriplet ) " - DTD_ENABLE_MULTI_PROCESSOR_COMPILATION= ON " $td_root "
62115 CheckLastExitCode
63116 cd ..
64117 }
0 commit comments