Skip to content

Commit

Permalink
Merge pull request #25 from negrutiu/feature/GH-21-vcpkg-caching2
Browse files Browse the repository at this point in the history
Perfected vcpkg caching by the GH workflow
  • Loading branch information
negrutiu authored Jun 7, 2024
2 parents 357b187 + 3d188cd commit 5952660
Show file tree
Hide file tree
Showing 76 changed files with 117 additions and 86 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ jobs:
working-directory: src/nscurl
run: py -3 _set_version.py --version=${{steps.version.outputs.version}}

- name: Checkout vcpkg
uses: actions/checkout@v4
with:
repository: 'Microsoft/vcpkg'
path: vcpkg/clone

- name: Setup vcpkg cache
uses: actions/cache@v4
with:
path: vcpkg/archives
key: ${{runner.os}}-${{matrix.arch}}-${{matrix.charset}}-${{hashFiles('vcpkg/overlay_*', 'vcpkg/clone/ports/curl', 'vcpkg/clone/ports/openssl', 'vcpkg/clone/ports/nghttp2', 'vcpkg/clone/ports/zlib', 'vcpkg/clone/ports/brotli', 'vcpkg/clone/ports/zstd')}}

- name: Build
run: _build.bat mingw release ${{matrix.arch}} ${{matrix.charset}}

Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
/tests/*.exe
/tests/_*

/vcpkg

/Debug-*
/Release-*
/ipch
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<VcpkgTriplet Condition="'$(VcpkgTriplet)'=='' And '$(Platform)'=='Win32'">x86-windows-static</VcpkgTriplet>
<VcpkgTriplet Condition="'$(VcpkgTriplet)'=='' And '$(Platform)'=='x64'">x64-windows-static</VcpkgTriplet>
<VcpkgRootDir Condition="'$(VcpkgRootDir)'==''">$(SolutionDir)vcpkg\$(VcpkgTriplet)\</VcpkgRootDir>
<VcpkgRootDir Condition="'$(VcpkgRootDir)'==''">$(SolutionDir)vcpkg\clone\</VcpkgRootDir>
<VcpkgInstalledDir Condition="'$(VcpkgInstalledDir)'==''">$(VcpkgRootDir)installed\$(VcpkgTriplet)\</VcpkgInstalledDir>

<NsisPlatform Condition="'$(Platform)'=='Win32'">x86</NsisPlatform>
Expand Down
16 changes: 8 additions & 8 deletions _build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ rmdir /s /q %outdir% 2> nul

call :copy README.md %outdir%\README.md
call :copy LICENSE.md %outdir%\LICENSE.md
call :copy vcpkg\%triplet%\installed\%triplet%\share\brotli\copyright %outdir%\LICENSE.brotli.md
call :copy vcpkg\%triplet%\installed\%triplet%\share\curl\copyright %outdir%\LICENSE.curl.md
call :copy vcpkg\%triplet%\installed\%triplet%\share\nghttp2\copyright %outdir%\LICENSE.nghttp2.md
call :copy vcpkg\%triplet%\installed\%triplet%\share\openssl\copyright %outdir%\LICENSE.openssl.md
call :copy vcpkg\%triplet%\installed\%triplet%\share\zlib\copyright %outdir%\LICENSE.zlib.md
call :copy vcpkg\%triplet%\installed\%triplet%\share\zstd\copyright %outdir%\LICENSE.zstd.md
call :copy vcpkg\clone\installed\%triplet%\share\brotli\copyright %outdir%\LICENSE.brotli.md
call :copy vcpkg\clone\installed\%triplet%\share\curl\copyright %outdir%\LICENSE.curl.md
call :copy vcpkg\clone\installed\%triplet%\share\nghttp2\copyright %outdir%\LICENSE.nghttp2.md
call :copy vcpkg\clone\installed\%triplet%\share\openssl\copyright %outdir%\LICENSE.openssl.md
call :copy vcpkg\clone\installed\%triplet%\share\zlib\copyright %outdir%\LICENSE.zlib.md
call :copy vcpkg\clone\installed\%triplet%\share\zstd\copyright %outdir%\LICENSE.zstd.md

call :copy Release-%compiler%-%platform_nsis%-%charset%\NScurl.dll %outdir%\Plugins\%platform_nsis%-%charset%\

Expand All @@ -142,7 +142,7 @@ call :copy tests\NScurl-Test-build.bat %outdir%\Examples\NScurl\
if /i "%charset%" neq "unicode" goto :end_curl_package
echo.
set outdir=packages\%configuration%-%compiler%-%platform_nsis%-curl
call :copy vcpkg\%triplet%\installed\%triplet%\tools\curl\curl.exe %outdir%\
call :copy vcpkg\clone\installed\%triplet%\tools\curl\curl.exe %outdir%\
call :copy src\nscurl\curl-ca-bundle.crt %outdir%\
:end_curl_package

Expand All @@ -156,7 +156,7 @@ powershell -C "(Get-Item 'Release-%compiler%-%platform_nsis%-%charset%\NScurl.dl

echo.
echo curl.exe
vcpkg\%triplet%\installed\%triplet%\tools\curl\curl.exe -V
vcpkg\clone\installed\%triplet%\tools\curl\curl.exe -V

echo.
echo curl-ca-bundle.crt
Expand Down
46 changes: 20 additions & 26 deletions _build_package.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ goto :file_end
exit /b
:file_end

call :file %workdir%\Plugins\amd64-unicode\NScurl.dll Release-mingw-amd64-unicode\NScurl.dll
call :file %workdir%\Plugins\x86-unicode\NScurl.dll Release-mingw-x86-unicode\NScurl.dll
call :file %workdir%\Plugins\x86-ansi\NScurl.dll Release-mingw-x86-ansi\NScurl.dll
call :file %workdir%\Examples\NScurl\NScurl-Test.nsi tests\NScurl-Test.nsi
call :file %workdir%\Examples\NScurl\NScurl-Test-build.bat tests\NScurl-Test-build.bat
call :file %workdir%\Docs\NScurl\NScurl.readme.md src\nscurl\NScurl.readme.md
call :file %workdir%\README.md README.md
call :file %workdir%\LICENSE.md LICENSE.md
call :file %workdir%\LICENSE.brotli.md vcpkg\x86-mingw-static\installed\x86-mingw-static\share\brotli\copyright
call :file %workdir%\LICENSE.curl.md vcpkg\x86-mingw-static\installed\x86-mingw-static\share\curl\copyright
call :file %workdir%\LICENSE.nghttp2.md vcpkg\x86-mingw-static\installed\x86-mingw-static\share\nghttp2\copyright
call :file %workdir%\LICENSE.openssl.md vcpkg\x86-mingw-static\installed\x86-mingw-static\share\openssl\copyright
call :file %workdir%\LICENSE.zlib.md vcpkg\x86-mingw-static\installed\x86-mingw-static\share\zlib\copyright
call :file %workdir%\LICENSE.zstd.md vcpkg\x86-mingw-static\installed\x86-mingw-static\share\zstd\copyright
call :file %workdir%\Plugins\amd64-unicode\NScurl.dll packages\Release-mingw-amd64-unicode\Plugins\amd64-unicode\NScurl.dll
call :file %workdir%\Plugins\x86-unicode\NScurl.dll packages\Release-mingw-x86-unicode\Plugins\x86-unicode\NScurl.dll
call :file %workdir%\Plugins\x86-ansi\NScurl.dll packages\Release-mingw-x86-ansi\Plugins\x86-ansi\NScurl.dll
call :file %workdir%\Examples\NScurl\NScurl-Test.nsi packages\Release-mingw-x86-unicode\Examples\NScurl\NScurl-Test.nsi
call :file %workdir%\Examples\NScurl\NScurl-Test-build.bat packages\Release-mingw-x86-unicode\Examples\NScurl\NScurl-Test-build.bat
call :file %workdir%\Docs\NScurl\NScurl.readme.md packages\Release-mingw-x86-unicode\Docs\NScurl\NScurl.readme.md
call :file %workdir%\README.md packages\Release-mingw-x86-unicode\README.md
call :file %workdir%\LICENSE.md packages\Release-mingw-x86-unicode\LICENSE.md
call :file %workdir%\LICENSE.brotli.md packages\Release-mingw-x86-unicode\LICENSE.brotli.md
call :file %workdir%\LICENSE.curl.md packages\Release-mingw-x86-unicode\LICENSE.curl.md
call :file %workdir%\LICENSE.nghttp2.md packages\Release-mingw-x86-unicode\LICENSE.nghttp2.md
call :file %workdir%\LICENSE.openssl.md packages\Release-mingw-x86-unicode\LICENSE.openssl.md
call :file %workdir%\LICENSE.zlib.md packages\Release-mingw-x86-unicode\LICENSE.zlib.md
call :file %workdir%\LICENSE.zstd.md packages\Release-mingw-x86-unicode\LICENSE.zstd.md

mkdir %outdir% 2> nul
pushd %workdir%
Expand All @@ -46,22 +46,16 @@ echo.
echo -------------------------------------------------
REM -- curl packages

pushd vcpkg\x86-mingw-static\installed\x86-mingw-static\tools\curl
7z a "%~dp0%outdir%\curl-x86.zip" curl.exe || pause && exit /b !errorlevel!
pushd packages\Release-mingw-x86-curl
7z a "%~dp0%outdir%\curl-x86.zip" * || pause && exit /b !errorlevel!
popd

echo -------------------------------------------------

pushd vcpkg\x64-mingw-static\installed\x64-mingw-static\tools\curl
7z a "%~dp0%outdir%\curl-amd64.zip" curl.exe || pause && exit /b !errorlevel!
pushd packages\Release-mingw-amd64-curl
7z a "%~dp0%outdir%\curl-amd64.zip" * || pause && exit /b !errorlevel!
popd

echo -------------------------------------------------

pushd src\nscurl
7z a "%~dp0%outdir%\curl-x86.zip" curl-ca-bundle.crt || pause && exit /b !errorlevel!
7z a "%~dp0%outdir%\curl-amd64.zip" curl-ca-bundle.crt || pause && exit /b !errorlevel!
popd

echo.
echo *************************************************
Expand All @@ -72,10 +66,10 @@ echo.> "%versions%"
echo NScurl/%version%>> "%versions%"

echo.>> "%versions%"
"%~dp0\vcpkg\x86-mingw-static\installed\x86-mingw-static\tools\curl\curl.exe" -V>> "%versions%"
packages\Release-mingw-x86-curl\curl.exe -V>> "%versions%"

echo.>> "%versions%"
"%~dp0\vcpkg\x64-mingw-static\installed\x64-mingw-static\tools\curl\curl.exe" -V>> "%versions%"
packages\Release-mingw-amd64-curl\curl.exe -V>> "%versions%"

echo.>> "%versions%"
echo curl-ca-bundle.crt>> "%versions%"
Expand Down
24 changes: 14 additions & 10 deletions _cleanup.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ echo.

cd /d "%~dp0"

call "%cd%\tests\cleanup.bat"
call tests\cleanup.bat
call vcpkg\cleanup.bat

call :CLEANUP
call :CLEANUP
call :CLEANUP
goto :EOF
call :clean
call :clean
call :clean

exit /b

:CLEANUP

:clean
rd /S /Q .vs
rd /S /Q ipch

for /D %%a in (Debug*) do rd /S /Q "%%a"
for /D %%a in (Release*) do rd /S /Q "%%a"

rd /Q /S "vcpkg"
for /D %%a in (Debug-*) do rd /S /Q "%%~a"
for /D %%a in (Release-*) do rd /S /Q "%%~a"

rd /Q /S "src\nscurl\nsis"
del /Q "src\nscurl\curl-ca-bundle.crt"

rd /Q /S "packages\current"
for /D %%a in (packages\Debug-*) do rd /S /Q "%%~a"
for /D %%a in (packages\Release-*) do rd /S /Q "%%~a"

del *.aps
del *.bak
Expand All @@ -33,3 +36,4 @@ del *.ncb
del /AH *.suo
del *.sdf
del *.VC.db
exit /b
28 changes: 1 addition & 27 deletions _compare_vcpkg_overlays.bat
Original file line number Diff line number Diff line change
@@ -1,27 +1 @@
@echo off

REM | Manually compare our custom overlay ports with the latest vcpkg ports from GitHub

set vcpkg_dir=%~dp0vcpkg\latest
mkdir "%vcpkg_dir%" > nul 2> nul

if exist "%vcpkg_dir%\.gitignore" (
pushd "%vcpkg_dir%"
echo Pulling latest vcpkg.git . . .&& echo.
git pull --verbose || exit /b !errorlevel!
popd
) else (
pushd "%vcpkg_dir%\.."
git clone https://github.com/Microsoft/vcpkg.git "%vcpkg_dir%" || exit /b !errorlevel!
popd
)

echo.

for /d %%d in (%~dp0\vcpkg_overlay_ports\*) do (
echo Comparing %%~nxd . . .
"%ProgramFiles%\WinMerge\WinMergeU.exe" "%vcpkg_dir%\ports\%%~nxd" "%~dp0\vcpkg_overlay_ports\%%~nxd"
)

echo Comparing triplets . . .
"%ProgramFiles%\WinMerge\WinMergeU.exe" "%vcpkg_dir%\triplets\community" "%~dp0\vcpkg_overlay_triplets"
@call "%~dp0vcpkg\compare_overlays.bat"
4 changes: 2 additions & 2 deletions src/nscurl/Makefile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ STATIC = $(OUTDIR)/lib$(PROJECT).a

# vcpkg
VCPKG_TRIPLET = $(_arch)-mingw-static
VCPKG_INSTALLED = ../../vcpkg/$(VCPKG_TRIPLET)/installed/$(VCPKG_TRIPLET)
VCPKG_INSTALLED = ../../vcpkg/clone/installed/$(VCPKG_TRIPLET)

INC += -I$(VCPKG_INSTALLED)/include -I$(VCPKG_INSTALLED)/include/openssl
ifeq ($(_config), debug)
Expand Down Expand Up @@ -137,7 +137,7 @@ curl-ca-bundle:
py -3 _get_curl-ca-bundle.py

vcpkg-install:
cmd /c call ..\..\_install_vcpkg.bat $(_arch) mingw static
cmd /c call ..\..\vcpkg\build.bat $(_arch) mingw static

# Link
$(_BIN): $(_OBJ)
Expand Down
8 changes: 4 additions & 4 deletions src/nscurl/NScurl.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<AdditionalDependencies>version.lib;libcurl-d.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlibd.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)vcpkg\build.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -105,7 +105,7 @@
<AdditionalDependencies>version.lib;libcurl-d.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlibd.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)vcpkg\build.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -125,7 +125,7 @@
<AdditionalDependencies>version.lib;libcurl.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlib.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)vcpkg\build.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand All @@ -144,7 +144,7 @@
<AdditionalDependencies>version.lib;libcurl.lib;libcrypto.lib;libssl.lib;nghttp2.lib;zlib.lib;zstd.lib;brotlicommon.lib;brotlidec.lib;ws2_32.lib;Wldap32.lib;Crypt32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)_install_vcpkg.bat" $(Platform) msbuild static
<Command>call py -3 _get_nsis_sdk.py &amp;&amp; py -3 _get_curl-ca-bundle.py &amp;&amp; call "$(SolutionDir)vcpkg\build.bat" $(Platform) msbuild static
</Command>
</PreBuildEvent>
</ItemDefinitionGroup>
Expand Down
2 changes: 1 addition & 1 deletion tests/NScurl-Debug.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Section "github.com/get (Encoding)"
DetailPrint '=====[ ${__SECTION__} ]==============================='

!insertmacro STACK_VERIFY_START
!define /redef LINK "https://raw.githubusercontent.com/negrutiu/nsis-nscurl/master/curl.c"
!define /redef LINK "https://raw.githubusercontent.com/negrutiu/nsis-nscurl/master/src/nscurl/curl.c"
!define /redef FILE "$EXEDIR\_curl.c"
DetailPrint 'NScurl::http "${LINK}" "${FILE}"'

Expand Down
2 changes: 1 addition & 1 deletion tests/NScurl-Test.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ Section "github.com/get (Encoding)"
SectionIn ${INSTTYPE_MOST}
DetailPrint '=====[ ${__SECTION__} ]==============================='

!define /redef LINK "https://raw.githubusercontent.com/negrutiu/nsis-nscurl/master/curl.c"
!define /redef LINK "https://raw.githubusercontent.com/negrutiu/nsis-nscurl/master/src/nscurl/curl.c"
!define /redef FILE "$EXEDIR\_curl.c"
DetailPrint 'NScurl::http "${LINK}" "${FILE}"'

Expand Down
3 changes: 3 additions & 0 deletions vcpkg/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/archives/
/clone/
/latest/
4 changes: 2 additions & 2 deletions _install_vcpkg.bat → vcpkg/build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ if /i "%compiler%" equ "mingw" set vcpkg_triplet=%arch%-mingw-%runtime%
if /i "%compiler%" equ "msbuild" if /i "%runtime%" equ "static" set vcpkg_triplet=%arch%-windows-%runtime%
if /i "%compiler%" equ "msbuild" if /i "%runtime%" equ "dynamic" set vcpkg_triplet=%arch%-windows

set vcpkg_dir=%~dp0vcpkg\%vcpkg_triplet%
set vcpkg_dir=%~dp0clone

REM | -------------------------------------------------------------------------

Expand Down Expand Up @@ -61,7 +61,7 @@ set vcpkg_downloads=%vcpkg_dir%\downloads
set vcpkg_buildtrees=%vcpkg_dir%\buildtrees
set vcpkg_packages=%vcpkg_dir%\packages
REM set vcpkg_archives=%vcpkg_dir%\archives
set vcpkg_archives=%~dp0vcpkg\archives
set vcpkg_archives=%~dp0archives

echo -------------------------------------------------------------------------
echo Build ^& install vcpkg ...
Expand Down
19 changes: 19 additions & 0 deletions vcpkg/cleanup.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

@echo off

call :clean
call :clean
call :clean
exit /b


:clean
echo.
pushd "%~dp0"

rd /q /s archives
rd /q /s clone
rd /q /s latest

popd
exit /b
27 changes: 27 additions & 0 deletions vcpkg/compare_overlays.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@echo off

REM | Manually compare our custom overlay ports with the latest vcpkg ports from GitHub

set vcpkg_dir=%~dp0latest
mkdir "%vcpkg_dir%" > nul 2> nul

if exist "%vcpkg_dir%\.gitignore" (
pushd "%vcpkg_dir%"
echo Pulling latest vcpkg.git . . .&& echo.
git pull --verbose || exit /b !errorlevel!
popd
) else (
pushd "%vcpkg_dir%\.."
git clone https://github.com/Microsoft/vcpkg.git "%vcpkg_dir%" || exit /b !errorlevel!
popd
)

echo.

for /d %%d in (%~dp0\overlay_ports\*) do (
echo Comparing %%~nxd . . .
"%ProgramFiles%\WinMerge\WinMergeU.exe" "%vcpkg_dir%\ports\%%~nxd" "%~dp0\overlay_ports\%%~nxd"
)

echo Comparing triplets . . .
"%ProgramFiles%\WinMerge\WinMergeU.exe" "%vcpkg_dir%\triplets\community" "%~dp0\overlay_triplets"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions vcpkg.json → vcpkg/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}
],
"vcpkg-configuration": {
"overlay-ports": [ "vcpkg_overlay_ports" ],
"overlay-triplets": [ "vcpkg_overlay_triplets" ]
"overlay-ports": [ "overlay_ports" ],
"overlay-triplets": [ "overlay_triplets" ]
}
}

0 comments on commit 5952660

Please sign in to comment.