From 8c750290c0d4a5304ba3b5900a6f3f3799df3364 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Mon, 12 Feb 2024 10:59:28 +0200 Subject: [PATCH] Split Windows X86 and X64 installers IB-7921 Signed-off-by: Raul Metsma --- .github/workflows/build.yml | 33 +-- build.ps1 | 77 ++---- libdigidocpp.wxs | 259 +++++++----------- patches/vcpkg-triplets/x64-windows-v142.cmake | 4 - patches/vcpkg-triplets/x64-windows-v143.cmake | 4 - patches/vcpkg-triplets/x86-windows-v142.cmake | 4 - patches/vcpkg-triplets/x86-windows-v143.cmake | 4 - prepare_win_build_environment.ps1 | 5 +- src/crypto/Connect.cpp | 30 +- src/crypto/Connect.h | 6 +- vcpkg.json | 1 - 11 files changed, 164 insertions(+), 263 deletions(-) delete mode 100644 patches/vcpkg-triplets/x64-windows-v142.cmake delete mode 100644 patches/vcpkg-triplets/x64-windows-v143.cmake delete mode 100644 patches/vcpkg-triplets/x86-windows-v142.cmake delete mode 100644 patches/vcpkg-triplets/x86-windows-v143.cmake diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34439a2a9..03a0c1377 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -145,6 +145,7 @@ jobs: strategy: matrix: toolset: [143, 142] + platform: [x86, x64] include: - toolset: 143 image: windows-2022 @@ -160,47 +161,35 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive - - uses: mad9000/actions-find-and-replace-string@3 - id: path - with: - source: ${{ github.workspace }} - find: '\' - replace: '/' - replaceAll: true - - name: Prepare vcpkg X64 + - name: Prepare vcpkg uses: lukka/run-vcpkg@v11 with: vcpkgGitCommitId: 18b028fe785e707265fa0e35590b7537ae1d12ea - vcpkgJsonGlob: ${{ steps.path.outputs.value }}/vcpkg.json + vcpkgJsonGlob: ./vcpkg.json runVcpkgInstall: true runVcpkgFormatString: "[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`, `--x-feature`, `tests`]" env: - VCPKG_DEFAULT_TRIPLET: x64-windows-v${{ matrix.toolset }} - VCPKG_INSTALLED_DIR: ${{ github.workspace }}/vcpkg_installed - - name: Prepare vcpkg X86 - uses: lukka/run-vcpkg@v11 - with: - vcpkgGitCommitId: 18b028fe785e707265fa0e35590b7537ae1d12ea - vcpkgJsonGlob: ${{ steps.path.outputs.value }}/vcpkg.json - runVcpkgInstall: true - runVcpkgFormatString: "[`install`, `--recurse`, `--clean-after-build`, `--x-install-root`, `$[env.VCPKG_INSTALLED_DIR]`, `--triplet`, `$[env.VCPKG_DEFAULT_TRIPLET]`, `--x-feature`, `tests`]" - env: - VCPKG_DEFAULT_TRIPLET: x86-windows-v${{ matrix.toolset }} + VCPKG_DEFAULT_TRIPLET: ${{ matrix.platform }}-windows VCPKG_INSTALLED_DIR: ${{ github.workspace }}/vcpkg_installed - name: Install dependencies run: choco install doxygen.install swig -y > $null - uses: actions/setup-python@v4 with: python-version: 3.11 - architecture: x86 + architecture: ${{ matrix.platform }} - name: Build xsd run: .\prepare_win_build_environment.ps1 -xsd + - name: Setup dev env + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.platform }} - name: Build run: | & .\build.ps1 ` -msiversion $env:VERSION ` - -toolset ${{ matrix.toolset }} ` + -vcpkg_installed ${{ github.workspace }}/vcpkg_installed ` -vcvars "${{ matrix.vcvars }}" ` + -platform ${{ matrix.platform }} ` -swig C:/ProgramData/chocolatey/bin/swig.exe ` -doxygen "C:/Program files/doxygen/bin/doxygen.exe" ` -boost diff --git a/build.ps1 b/build.ps1 index 08c55514c..d70bcea53 100644 --- a/build.ps1 +++ b/build.ps1 @@ -6,83 +6,60 @@ param( [string]$vcpkg_installed = $libdigidocpp, [string]$buildver = "0", [string]$msiversion = "3.18.0.$buildver", - [string]$msi_name = "libdigidocpp-$msiversion$env:VER_SUFFIX.msi", + [string]$platform = "x64", + [string]$msi_name = "libdigidocpp-$msiversion$env:VER_SUFFIX.$platform.msi", [string]$cmake = "cmake.exe", [string]$generator = "NMake Makefiles", - [string]$toolset = "142", - [string]$vcvars = $null, - [string]$vcver = "", - [string]$heat = "$env:WIX\bin\heat.exe", - [string]$candle = "$env:WIX\bin\candle.exe", - [string]$light = "$env:WIX\bin\light.exe", + [string]$vcvars = "vcvarsall", + [string]$wix = "$env:WIX", + [string]$heat = "$wix\bin\heat.exe", + [string]$candle = "$wix\bin\candle.exe", + [string]$light = "$wix\bin\light.exe", [string]$swig = $null, [string]$doxygen = $null, [switch]$boost = $false, [string]$xsd = "$libdigidocpp\xsd", - [string]$sign = $null, - [string]$crosssign = $null, - [switch]$source = $false + [string]$sign = $null ) -if (!$vcvars) { - switch ($toolset) { - '142' { $vcvars = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" } - '143' { $vcvars = "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" } - } -} -if ($vcver) { - $vcver = "-vcvars_ver=$vcver" -} - $cmakeext = @() $candleext = @() $lightext = @() +$target = @("all") if($swig) { $cmakeext += "-DSWIG_EXECUTABLE=$swig" $candleext += "-dswig=$swig" } if($doxygen) { $cmakeext += "-DDOXYGEN_EXECUTABLE=$doxygen" - $candleext += "-ddocLocation=x86/share/doc/libdigidocpp", "DocFilesFragment.wxs" + $candleext += "-ddocLocation=$platform/share/doc/libdigidocpp", "DocFilesFragment.wxs" $lightext += "DocFilesFragment.wixobj" } if($boost) { $cmakeext += "-DVCPKG_MANIFEST_FEATURES=tests" -} -if($source) { - Remove-Item source -Force -Recurse - New-Item -ItemType directory -Path source > $null - Get-ChildItem -Path $libdigidocpp | % { Copy-Item $_.fullname source -Recurse -Force -Exclude build,doc,.git } - & $heat dir source -nologo -cg Source -gg -scom -sreg -sfrag -srd -dr SourceFolder -var var.sourceLocation -out SourceFilesFragment.wxs - $candleext += "-dsourceLocation=source", "SourceFilesFragment.wxs" - $lightext += "SourceFilesFragment.wixobj" + $target += "check" } -foreach($platform in @("x86", "x64")) { - foreach($type in @("Debug", "RelWithDebInfo")) { - $buildpath = $platform+$type - Remove-Item $buildpath -Force -Recurse -ErrorAction Ignore - & $vcvars $platform $vcver "&&" $cmake -B $buildpath -S $libdigidocpp "-G$generator" ` - "-DCMAKE_BUILD_TYPE=$type" ` - "-DCMAKE_INSTALL_PREFIX=$platform" ` - "-DCMAKE_INSTALL_LIBDIR=bin" ` - "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_dir/scripts/buildsystems/vcpkg.cmake" ` - "-DVCPKG_TARGET_TRIPLET=$platform-windows-v$toolset" ` - "-DVCPKG_INSTALLED_DIR=$vcpkg_installed\vcpkg_installed_$platform" ` - "-DXSD_ROOT=$xsd" ` - "-DSIGNCERT=$sign" ` - "-DCROSSSIGNCERT=$crosssign" ` - $cmakeext "&&" $cmake --build $buildpath --target check "&&" $cmake --build $buildpath --target install - } +foreach($type in @("Debug", "RelWithDebInfo")) { + $buildpath = $platform+$type + & $vcvars $platform "&&" $cmake --fresh -B $buildpath -S $libdigidocpp "-G$generator" ` + "-DCMAKE_BUILD_TYPE=$type" ` + "-DCMAKE_INSTALL_PREFIX=$platform" ` + "-DCMAKE_INSTALL_LIBDIR=bin" ` + "-DCMAKE_TOOLCHAIN_FILE=$vcpkg_dir/scripts/buildsystems/vcpkg.cmake" ` + "-DVCPKG_INSTALLED_DIR=$vcpkg_installed\vcpkg_installed_$platform" ` + "-DXSD_ROOT=$xsd" ` + "-DSIGNCERT=$sign" ` + $cmakeext "&&" $cmake --build $buildpath --target $target "&&" $cmake --install $buildpath } if($doxygen) { - & $heat dir x86/share/doc/libdigidocpp -nologo -cg Documentation -gg -scom -sreg -sfrag -srd -dr DocumentationFolder -var var.docLocation -out DocFilesFragment.wxs + & $heat dir $platform/share/doc/libdigidocpp -nologo -cg Documentation -gg -scom -sreg -sfrag -srd -dr DocumentationFolder -var var.docLocation -out DocFilesFragment.wxs } -& $heat dir x86/include -nologo -cg Headers -gg -scom -sreg -sfrag -srd -dr HeadersFolder -var var.headersLocation -out HeadersFragment.wxs -& $vcvars x86 "&&" $candle -nologo "-dICON=$libdigidocpp/cmake/modules/ID.ico" "-dMSI_VERSION=$msiversion" ` - "-dvcpkg_x86=$vcpkg_installed\vcpkg_installed_x86\x86-windows-v$toolset" "-dvcpkg_x64=$vcpkg_installed\vcpkg_installed_x64\x64-windows-v$toolset" ` - "-dheadersLocation=x86/include" "-dlibdigidocpp=." $candleext $libdigidocpp\libdigidocpp.wxs HeadersFragment.wxs +& $heat dir $platform/include -nologo -cg Headers -gg -scom -sreg -sfrag -srd -dr HeadersFolder -var var.headersLocation -out HeadersFragment.wxs +& $candle -nologo -arch $platform "-dICON=$libdigidocpp/cmake/modules/ID.ico" "-dMSI_VERSION=$msiversion" ` + "-dvcpkg=$vcpkg_installed\vcpkg_installed_$platform\$platform-windows" "-dheadersLocation=$platform/include" ` + "-dlibdigidocpp=$platform" $candleext $libdigidocpp\libdigidocpp.wxs HeadersFragment.wxs & $light -nologo -out $msi_name -ext WixUIExtension ` "-dWixUIBannerBmp=$libdigidocpp/cmake/modules/banner.bmp" ` "-dWixUIDialogBmp=$libdigidocpp/cmake/modules/dlgbmp.bmp" ` diff --git a/libdigidocpp.wxs b/libdigidocpp.wxs index ef72d1a4d..0b49336f6 100644 --- a/libdigidocpp.wxs +++ b/libdigidocpp.wxs @@ -1,18 +1,34 @@ + + + + + + + + + + + + + + + + - - - - + + + + - - + + @@ -25,175 +41,102 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - + - - + - - - + + + + + - - - - - - - - - - - - - - - - diff --git a/patches/vcpkg-triplets/x64-windows-v142.cmake b/patches/vcpkg-triplets/x64-windows-v142.cmake deleted file mode 100644 index 8aa046dd0..000000000 --- a/patches/vcpkg-triplets/x64-windows-v142.cmake +++ /dev/null @@ -1,4 +0,0 @@ -set(VCPKG_TARGET_ARCHITECTURE x64) -set(VCPKG_CRT_LINKAGE dynamic) -set(VCPKG_LIBRARY_LINKAGE dynamic) -set(VCPKG_PLATFORM_TOOLSET v142) diff --git a/patches/vcpkg-triplets/x64-windows-v143.cmake b/patches/vcpkg-triplets/x64-windows-v143.cmake deleted file mode 100644 index 0924eea16..000000000 --- a/patches/vcpkg-triplets/x64-windows-v143.cmake +++ /dev/null @@ -1,4 +0,0 @@ -set(VCPKG_TARGET_ARCHITECTURE x64) -set(VCPKG_CRT_LINKAGE dynamic) -set(VCPKG_LIBRARY_LINKAGE dynamic) -set(VCPKG_PLATFORM_TOOLSET v143) diff --git a/patches/vcpkg-triplets/x86-windows-v142.cmake b/patches/vcpkg-triplets/x86-windows-v142.cmake deleted file mode 100644 index e6d0d412f..000000000 --- a/patches/vcpkg-triplets/x86-windows-v142.cmake +++ /dev/null @@ -1,4 +0,0 @@ -set(VCPKG_TARGET_ARCHITECTURE x86) -set(VCPKG_CRT_LINKAGE dynamic) -set(VCPKG_LIBRARY_LINKAGE dynamic) -set(VCPKG_PLATFORM_TOOLSET v142) diff --git a/patches/vcpkg-triplets/x86-windows-v143.cmake b/patches/vcpkg-triplets/x86-windows-v143.cmake deleted file mode 100644 index 8d5afb28f..000000000 --- a/patches/vcpkg-triplets/x86-windows-v143.cmake +++ /dev/null @@ -1,4 +0,0 @@ -set(VCPKG_TARGET_ARCHITECTURE x86) -set(VCPKG_CRT_LINKAGE dynamic) -set(VCPKG_LIBRARY_LINKAGE dynamic) -set(VCPKG_PLATFORM_TOOLSET v143) diff --git a/prepare_win_build_environment.ps1 b/prepare_win_build_environment.ps1 index eecc4b8f0..76de9cf75 100644 --- a/prepare_win_build_environment.ps1 +++ b/prepare_win_build_environment.ps1 @@ -2,7 +2,6 @@ param( [string]$vcpkg = "vcpkg\vcpkg.exe", [string]$git = "git.exe", - [string]$toolset = "142", [switch]$xsd = $false, [switch]$dependencies = $false ) @@ -28,8 +27,8 @@ if($dependencies) { & $git clone --depth 1 https://github.com/microsoft/vcpkg $vcpkg_dir & $vcpkg_dir\bootstrap-vcpkg.bat } - & $vcpkg install --clean-after-build --triplet x86-windows-v$toolset --x-feature=tests --x-install-root=vcpkg_installed_x86 - & $vcpkg install --clean-after-build --triplet x64-windows-v$toolset --x-feature=tests --x-install-root=vcpkg_installed_x64 + & $vcpkg install --clean-after-build --triplet x86-windows --x-feature=tests --x-install-root=vcpkg_installed_x86 + & $vcpkg install --clean-after-build --triplet x64-windows --x-feature=tests --x-install-root=vcpkg_installed_x64 } if(!$xsd -and !$dependencies) { diff --git a/src/crypto/Connect.cpp b/src/crypto/Connect.cpp index 67a659c5c..5978e6c29 100644 --- a/src/crypto/Connect.cpp +++ b/src/crypto/Connect.cpp @@ -37,6 +37,16 @@ #include #endif +#if defined(__aarch64__) || defined(__ARM64__) || defined(_M_ARM64) +#define TARGET_ARCH "arm64" +#elif defined(__arm__) || defined(_M_ARM) +#define TARGET_ARCH "arm" +#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) +#define TARGET_ARCH "x86_64" +#else +#define TARGET_ARCH "x86" +#endif + using namespace digidoc; using namespace std; @@ -73,7 +83,7 @@ Connect::Connect(const string &_url, const string &method, int timeout, const ve baseurl = url.substr(0, pos); } - string hostname = host + ":" + port; + string hostname = host + ':' + port; Conf *c = Conf::instance(); if(!c->proxyHost().empty() && !c->proxyPort().empty()) { @@ -106,7 +116,7 @@ Connect::Connect(const string &_url, const string &method, int timeout, const ve if(!c->proxyHost().empty() && (CONF(proxyTunnelSSL))) { BIO_printf(d, "CONNECT %s:%s HTTP/1.0\r\n", host.c_str(), port.c_str()); - addHeader("Host", host + ":" + port); + addHeader("Host", host + ':' + port); sendProxyAuth(); doProxyConnect = true; Result r = exec(); @@ -166,9 +176,9 @@ Connect::Connect(const string &_url, const string &method, int timeout, const ve if(port == "80" || port == "443") addHeader("Host", host); else - addHeader("Host", host + ":" + port); + addHeader("Host", host + ':' + port); if(!userAgent().empty()) - addHeader("User-Agent", "LIB libdigidocpp/" + string(FILE_VER_STR) + " APP " + userAgent()); + addHeader("User-Agent", "LIB libdigidocpp/" FILE_VER_STR " (" TARGET_ARCH ") APP " + userAgent()); if(usessl == 0) sendProxyAuth(); } @@ -179,9 +189,9 @@ Connect::~Connect() BIO_free_all(d); } -void Connect::addHeader(const string &key, const string &value) +void Connect::addHeader(string_view key, string_view value) { - BIO_printf(d, "%s: %s\r\n", key.c_str(), value.c_str()); + BIO_printf(d, "%.*s: %.*s\r\n", int(key.size()), key.data(), int(value.size()), value.data()); } string Connect::decompress(const string &encoding, const string &data) @@ -225,17 +235,17 @@ string Connect::decompress(const string &encoding, const string &data) return out; } -Connect::Result Connect::exec(initializer_list> headers, +Connect::Result Connect::exec(initializer_list> headers, const vector &data) { return exec(headers, data.data(), data.size()); } -Connect::Result Connect::exec(initializer_list> headers, +Connect::Result Connect::exec(initializer_list> headers, const unsigned char *data, size_t size) { - for(const pair &it: headers) - addHeader(it.first, it.second); + for(const auto &[key, value]: headers) + addHeader(key, value); if(size != 0) { diff --git a/src/crypto/Connect.h b/src/crypto/Connect.h index 4d8edeadb..58d738ebb 100644 --- a/src/crypto/Connect.h +++ b/src/crypto/Connect.h @@ -62,15 +62,15 @@ class Connect Connect(const std::string &url, const std::string &method = "POST", int timeout = 0, const std::vector &certs = {}); ~Connect(); - Result exec(std::initializer_list> headers, + Result exec(std::initializer_list> headers, const std::vector &data); - Result exec(std::initializer_list> headers = {}, + Result exec(std::initializer_list> headers = {}, const unsigned char *data = nullptr, size_t size = 0); private: DISABLE_COPY(Connect); - void addHeader(const std::string &key, const std::string &value); + void addHeader(std::string_view key, std::string_view value); void sendProxyAuth(); static std::string decompress(const std::string &encoding, const std::string &data) ; void waitReadWrite(bool read) const; diff --git a/vcpkg.json b/vcpkg.json index f2c15846c..6c877372a 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -10,7 +10,6 @@ }, "builtin-baseline": "18b028fe785e707265fa0e35590b7537ae1d12ea", "vcpkg-configuration": { - "overlay-triplets": ["./patches/vcpkg-triplets"], "overlay-ports": [ "patches/vcpkg-ports/openssl", "patches/vcpkg-ports/xml-security-c"