From 0f4442d2ffc170e1693ab690e59637a916750f3c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 28 Nov 2017 18:29:18 +0100 Subject: [PATCH] vcxproj: automatically initialize the vcpkg system We just introduced a way to build Git for Windows with MSVC on the command line using vcpkg-generated, up-to-date dependencies. Let's bring that convenience to the Visual Studio project, too. (The previous method, fetching NuGet packages, is fraught with problems: as C++ libraries have to be built for every architecture and for every toolset, the NuGet packages which we would like to consume fell behind and are not up-to-date with the current versions of the libraries, e.g. cURL and OpenSSL. By using vcpkg we avoid that problem, always building the newest dependency versions.) The trick is to initialize the VCPKG system once, and then build Git's dependencies using it. We do that by attaching a pre-build event to the libgit project (which is now the base project on which all others depend, therefore no other project is built in paralleli, side-stepping issues with vcpkg being unprepared for being run in parallel). Signed-off-by: Johannes Schindelin --- config.mak.uname | 2 +- contrib/buildsystems/Generators/Vcxproj.pm | 89 +++++++++------------- contrib/buildsystems/engine.pl | 2 + 3 files changed, 37 insertions(+), 56 deletions(-) diff --git a/config.mak.uname b/config.mak.uname index dfaa447a87..19f795290f 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -470,7 +470,7 @@ vcxproj: # Make .vcxproj files and add them unset QUIET_GEN QUIET_BUILT_IN; \ perl contrib/buildsystems/generate -g Vcxproj - git add -f git.sln {*,*/lib,t/helper/*}/{packages.config,*.vcxproj} + git add -f git.sln {*,*/lib,t/helper/*}/*.vcxproj # Add command-list.h $(MAKE) MSVC=1 SKIP_VCPKG=1 prefix=/mingw64 command-list.h diff --git a/contrib/buildsystems/Generators/Vcxproj.pm b/contrib/buildsystems/Generators/Vcxproj.pm index 3b1e4c2f93..1849ae24f5 100644 --- a/contrib/buildsystems/Generators/Vcxproj.pm +++ b/contrib/buildsystems/Generators/Vcxproj.pm @@ -126,9 +126,12 @@ sub createProject { $cflags =~ s//>/g; - my $libs = ''; + my $libs_release = "\n "; + my $libs_debug = "\n "; if (!$static_library) { - $libs = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib|libcurl\.lib|libeay32\.lib|libiconv\.lib|ssleay32\.lib|zlib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}})); + $libs_release = join(";", sort(grep /^(?!libgit\.lib|xdiff\/lib\.lib|vcs-svn\/lib\.lib)/, @{$$build_structure{"$prefix${name}_LIBS"}})); + $libs_debug = $libs_release; + $libs_debug =~ s/zlib\.lib/zlibd\.lib/; } $defines =~ s/-D//g; @@ -138,45 +141,6 @@ sub createProject { die "Could not create the directory $target for $label project!\n" unless (-d "$target" || mkdir "$target"); - use File::Copy; - copy("$git_dir/compat/vcbuild/packages.config", "$target/packages.config"); - - my $needsCurl = grep(/libcurl.lib/, @{$$build_structure{"$prefix${name}_LIBS"}}); - my $targetsImport = ''; - my $targetsErrors = ''; - my $afterTargets = ''; - open F, "<$git_dir/compat/vcbuild/packages.config"; - while () { - if (/"; - } elsif ($needsCurl && $1 eq 'curl') { - # libcurl is only available targeting v100 and v110 - $libs .= ";$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.$2\\build\\native\\lib\\v110\\\$(Platform)\\Release\\dynamic\\libcurl.lib"; - $afterTargets .= "\n "; - } elsif ($needsCurl && $1 eq 'expat') { - # libexpat is only available targeting v100 and v110 - $libs .= ";$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.$2\\build\\native\\lib\\v110\\\$(Platform)\\Release\\dynamic\\utf8\\libexpat.lib"; - } elsif ($1 eq 'zlib') { - # zlib - $libs .= ";$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.v140.windesktop.msvcstl.dyn.rt-dyn.$2\\lib\\native\\v140\\windesktop\\msvcstl\\dyn\\rt-dyn\\x64\\RelWithDebInfo\\zlib.lib"; - } elsif ($1 eq 'openssl') { - # openssl - $libs .= ";$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.v140.windesktop.msvcstl.dyn.rt-dyn.x64.$2\\lib\\native\\v140\\windesktop\\msvcstl\\dyn\\rt-dyn\\x64\\release\\libeay32.lib"; - $libs .= ";$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.v140.windesktop.msvcstl.dyn.rt-dyn.x64.$2\\lib\\native\\v140\\windesktop\\msvcstl\\dyn\\rt-dyn\\x64\\release\\ssleay32.lib"; - } - next if ($1 =~ /^(zlib$|openssl(?!.*(x64|x86)$))/); - my $targetsFile = "$rel_dir\\compat\\vcbuild\\GEN.PKGS\\$1.$2\\build\\native\\$1.targets"; - $targetsImport .= "\n "; - $targetsErrors .= "\n "; - } - } - close F; - open F, ">$vcxproj" or die "Could not open $vcxproj for writing!\n"; binmode F, ":crlf :utf8"; print F chr(0xFEFF); @@ -204,6 +168,16 @@ sub createProject { $uuid Win32Proj + x86-windows + x64-windows + $cdup\\compat\\vcbuild\\vcpkg\\installed\\\$(VCPKGArch) + \$(VCPKGArchDirectory)\\debug\\bin + \$(VCPKGArchDirectory)\\debug\\lib + \$(VCPKGArchDirectory)\\bin + \$(VCPKGArchDirectory)\\lib + \$(VCPKGArchDirectory)\\include + $libs_debug + $libs_release @@ -237,7 +211,7 @@ sub createProject { $cflags %(AdditionalOptions) - $includes;%(AdditionalIncludeDirectories) + $cdup;$cdup\\compat;$cdup\\compat\\regex;$cdup\\compat\\win32;$cdup\\compat\\poll;$cdup\\compat\\vcbuild\\include;\$(VCPKGIncludeDirectory);%(AdditionalIncludeDirectories) true OnlyExplicitInline @@ -248,11 +222,22 @@ sub createProject { true - $libs;\$(AdditionalDependencies) + \$(VCPKGLibDirectory);%(AdditionalLibraryDirectories) + \$(VCPKGLibs);\$(AdditionalDependencies) invalidcontinue.obj %(AdditionalOptions) $cdup\\compat\\win32\\git.manifest Console +EOM + if ($target eq 'libgit') { + print F << "EOM"; + + Initialize VCPKG + call "$cdup\\compat\\vcbuild\\vcpkg_install.bat" + +EOM + } + print F << "EOM"; @@ -323,21 +308,15 @@ EOM EOM } print F << "EOM"; - - - - $targetsImport - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - $targetsErrors - EOM - if (!$static_library && $afterTargets ne '') { + if (!$static_library) { print F << "EOM"; - $afterTargets + + + + + EOM } diff --git a/contrib/buildsystems/engine.pl b/contrib/buildsystems/engine.pl index 9f4e7a2ccb..8bb07e8e25 100755 --- a/contrib/buildsystems/engine.pl +++ b/contrib/buildsystems/engine.pl @@ -347,6 +347,8 @@ sub handleLinkLine push(@libs, "ssleay32.lib"); } elsif ("$part" eq "-lcurl") { push(@libs, "libcurl.lib"); + } elsif ("$part" eq "-lexpat") { + push(@libs, "expat.lib"); } elsif ("$part" eq "-liconv") { push(@libs, "libiconv.lib"); } elsif ($part =~ /^[-\/]/) {