diff --git a/README.md b/README.md index 71a195d6..e0894f7f 100644 --- a/README.md +++ b/README.md @@ -257,7 +257,7 @@ The extension's native app in `main.mm` is a thin adapter layer on top of the Qt You can examine the files in the `.github/workflows/` directory to see how continuous integration build environment has been set up for different operating systems. -### Ubuntu Linux +### Ubuntu Linux setup Install the dependencies required for building the project. @@ -278,88 +278,96 @@ sudo apt install \ libgtest-dev ``` -### Windows +### Linux Building and testing -- Download Visual Studio 2022 community installer from https://visualstudio.microsoft.com/ and install _Desktop C++ Development_ -- Install WIX toolset + git clone --recurse-submodules git@github.com:web-eid/web-eid-app.git + cd web-eid-app + ./build.sh + ./test.sh + ./build/src/app/web-eid -c get-signing-certificate '{"origin":"https://ria.ee"}' - dotnet tool install --global wix --version 6.0.2 - wix extension -g add WixToolset.UI.wixext/6.0.2 - wix extension -g add WixToolset.Util.wixext/6.0.2 - wix extension -g add WixToolset.Bal.wixext/6.0.2 +### Windows setup -- Download and install Git for Windows from https://git-scm.com/download/win -- Download and install CMake from https://cmake.org/download/ -- Install _vcpkg_ by running the following commands in Powershell: +- Download Visual Studio 2022 community installer from https://visualstudio.microsoft.com/ install _Visual Studio_ + with description "The most comprehensive IDE for .NET and C++ developers on Windows...". During installation choose components: - git clone https://github.com/microsoft/vcpkg.git C:\vcpkg - cd C:\vcpkg - .\bootstrap-vcpkg.bat - .\vcpkg integrate install + - NET desktop development + - Desktop development with C++ -- Install _Qt_ with the official [_Qt Online Installer_](https://www.qt.io/download-qt-installer), - choose _Custom installation > Qt 6.10.0 > MSVC 2022 64-bit_. +- After install has finished, open Developer Command Prompt for VS 2022 and run commands given below +- If Nuget does not contain api.nuget.org as source, please add (https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source#examples) -### macOS + dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org -- Install _Homebrew_ if not already installed: +- Open Powershell. Make sure git is in PATH. If it is not, then run: - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + $env:PATH += ";C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd" -- Install _CMake_, _Google Test_, _OpenSSL_ and _Qt_ with _Homebrew_: +- Install _vcpkg_ by running the following commands in Powershell: - brew install cmake web-eid/gtest/gtest openssl qt@6 node + git clone https://github.com/microsoft/vcpkg.git C:\vcpkg + cd C:\vcpkg + .\bootstrap-vcpkg.bat + .\vcpkg integrate install -- Create symlink to _OpenSSL_ location and setup environment variables required - by _CMake_: +- If you already have vcpkg installed, make sure you update it to latest - export OPENSSL_ROOT_DIR=/usr/local/opt/openssl@3.0 - export QT_DIR=/usr/local/opt/qt6/lib/cmake/Qt6 + cd C:\vcpkg + git pull + .\bootstrap-vcpkg.bat -## Building and testing +- Install _Qt_ with the official [_Qt Online Installer_](https://www.qt.io/download-qt-installer). + Installer requires you to create an account or log in with existing one. - git clone --recurse-submodules git@github.com:web-eid/web-eid-app.git - cd web-eid-app - ./build.sh - ./test.sh - ./build/src/app/web-eid -c get-signing-certificate '{"origin":"https://ria.ee"}' + Choose _Custom installation > Qt 6.11.0 > MSVC 2022 64-bit_. + Do not add cmake or ninja or any other component as they are already installed with Visual Studio 2022. -### Building and testing in Windows +### Windows building and testing Use _Powershell_ to run the following commands to build the project. -- Set the _Qt_ installation directory variable: +- To build the application (first run will install required dependencies and can take a bit longer), execute - $QT_ROOT = "C:\Qt\6.10.0\msvc2022_64" + ```shell + .\build.ps1 -clean + ``` -- Set the _vcpkg_ installation directory variable: +- To build the application installer, bundle and run all tests, execute - $VCPKG_ROOT = "C:\vcpkg" + ```shell + .\build.ps1 -clean -fullbuild + ``` -- Set the build type variable: +- To get help on parameters, execute - $BUILD_TYPE = "RelWithDebInfo" + ```shell + Get-Help .\build.ps1 -Detailed + ``` + or + ```shell + Get-Help .\build.ps1 -Full + ``` -- Run _CMake_: +### macOS setup - cmake -A x64 -B build -S . - "-DCMAKE_PREFIX_PATH=${QT_ROOT}" ` - "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" ` - "-DCMAKE_BUILD_TYPE=${BUILD_TYPE}" ` - "-DVCPKG_MANIFEST_DIR=lib/libelectronic-id" +- Install _Homebrew_ if not already installed: -- Run the build and installer build: + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - cmake --build build --config ${BUILD_TYPE} - cmake --build build --config ${BUILD_TYPE} --target installer +- Install _CMake_, _Google Test_, _OpenSSL_ and _Qt_ with _Homebrew_: -- Add _Qt_ binary directory to path: + brew install cmake web-eid/gtest/gtest openssl qt@6 node - $env:PATH += ";${QT_ROOT}\bin" +- Create symlink to _OpenSSL_ location and setup environment variables required + by _CMake_: -- Run tests: +### macOS building and testing - ctest -V -C ${BUILD_TYPE} --test-dir build + git clone --recurse-submodules git@github.com:web-eid/web-eid-app.git + cd web-eid-app + ./build.zsh clean + ./test.sh + ./build/src/app/web-eid.app/Contents/MacOS/web-eid -c get-signing-certificate '{"origin":"https://ria.ee"}' ## Adding and updating translations diff --git a/build.ps1 b/build.ps1 index 9b8315d1..5b24d516 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,10 +1,104 @@ +<# +.SYNOPSIS + Builds the web-eid-app project in Windows + +.PARAMETER clean + Clean build directory before building. + +.PARAMETER cmake + Path to cmake.exe. Default C:\Program Files\CMake\bin\cmake.exe or auto-detected to use the one installed by Microsoft Visual Studio. + +.PARAMETER vcpkgroot + Path to vcpkg installation directory. Default C:\vcpkg. + +.PARAMETER qtdir + Path to Qt installation directory. Default C:\Qt\6.10.0\msvc2022_64. + +.PARAMETER buildtype + Sets CMAKE_BUILD_TYPE. Default RelWithDebInfo. + +.PARAMETER arch + Default x64. + +.PARAMETER fullbuild + Also run target installer, bundle and tests. + +.OUTPUTS + Built artifacts will be in dir build/windows. + +.EXAMPLE + .\build.ps1 -clean + +.EXAMPLE + .\build.ps1 -clean -qtdir "C:\Qt\6.11.0\msvc2022_64" + Use Qt version other than default. +#> param( + [switch]$clean, [string]$cmake = "C:\Program Files\CMake\bin\cmake.exe", [string]$vcpkgroot = "C:\vcpkg", [string]$qtdir = "C:\Qt\6.10.0\msvc2022_64", [string]$buildtype = "RelWithDebInfo", [string]$arch = "x64" + [switch]$fullbuild ) & $cmake -S . -B build\windows -A $arch -DCMAKE_BUILD_TYPE=$buildtype "-DCMAKE_PREFIX_PATH=$qtdir" "-DCMAKE_TOOLCHAIN_FILE=$vcpkgroot\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_MANIFEST_DIR=lib/libelectronic-id" & $cmake --build build\windows --config $buildtype +$vsPath = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath + +# fix error WIX0150: Undefined preprocessor variable '$(env.VisualStudioVersion)' etc. +if (-not $env:VisualStudioVersion) { + $vsDevCmd = "$vsPath\Common7\Tools\VsDevCmd.bat" + cmd /c "`"$vsDevCmd`" -arch=$arch && set" | ForEach-Object { + if ($_ -match "^([^=]+)=(.*)$") { + [System.Environment]::SetEnvironmentVariable($matches[1], $matches[2], "Process") + } + } +} + +if (-not (Test-Path $cmake)) { + $vsCmake = "$vsPath\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" + if (Test-Path $vsCmake) { + $cmake = $vsCmake + Write-Host "Found cmake at path $cmake" + } else { + Write-Error "Visual Studio CMake component not found, please provide -cmake parameter with full path to cmake.exe" + } +} + +if (-not (Test-Path $qtdir)) { + Write-Error "Qt installation directory $qtdir not found, use parameter -qtdir " + exit 1 +} + +if (-not (Get-Command wix -ErrorAction SilentlyContinue)) { + Write-Host "Installing WiX Toolset..." + + dotnet tool install --global wix --version 6.0.2 + if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to install WiX Toolset" + exit $LASTEXITCODE + } + + wix extension -g add WixToolset.UI.wixext/6.0.2 + wix extension -g add WixToolset.Util.wixext/6.0.2 + wix extension -g add WixToolset.BootstrapperApplications.wixext/6.0.2 +} + +if ($clean) { + & $cmake --build build --target clean +} + +& $cmake -S . -B build\windows -A $arch -DCMAKE_BUILD_TYPE=$buildtype "-DCMAKE_PREFIX_PATH=$qtdir" "-DCMAKE_TOOLCHAIN_FILE=$vcpkgroot\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_MANIFEST_DIR=lib/libelectronic-id" +& $cmake --build build\windows --config $buildtype + +if ($fullbuild) { + & $cmake --build build\windows --config $buildtype --target installer + & $cmake --build build\windows --config $buildtype --target bundle + + if (-not (Get-Command qmake -ErrorAction SilentlyContinue)) { + $env:PATH += ";$qtdir\bin" + } + & ctest -V -C $buildtype --test-dir build/windows +} diff --git a/build.sh b/build.sh index 94389f6c..6d68c44e 100755 --- a/build.sh +++ b/build.sh @@ -3,5 +3,14 @@ set -e set -u -cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build -S . -cmake --build build # -- VERBOSE=1 +export QT_QPA_PLATFORM=offscreen +export DEBIAN_FRONTEND=noninteractive + +if [[ ${1:-} == 'clean' ]]; then + echo -n Cleaning... + cmake --build build --target clean + echo DONE +fi + +cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -B build -S . +cmake --build build --config RelWithDebInfo --target installer # -- VERBOSE=1 diff --git a/build.zsh b/build.zsh new file mode 100755 index 00000000..25ce8574 --- /dev/null +++ b/build.zsh @@ -0,0 +1,39 @@ +#!zsh + +set -e +set -u + +BUILD_TYPE=RelWithDebInfo +BUILD_DIR=build +BUILD_NUMBER=1234 +OPENSSL_ROOT_DIR=$(brew --prefix openssl@3) +GTest_ROOT=$(brew --prefix gtest) +CMAKE_BUILD_PARALLEL_LEVEL=3 +QT_QPA_PLATFORM=offscreen +MACOSX_DEPLOYMENT_TARGET=12.0 + +# For creating installers, you need to use signing certificates issued by Apple +# SIGNCERT= + +if [[ ${1:-} == 'clean' ]]; then + echo -n Cleaning... + cmake --build build --target clean + echo DONE +fi + +if [[ -n "$SIGNCERT" ]]; then + cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -B ${BUILD_DIR} -DSIGNCERT="${SIGNCERT}" -S . +else + cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -B ${BUILD_DIR} -S . +fi + +cmake --build ${BUILD_DIR} --config ${BUILD_TYPE} # -- VERBOSE=1 + +# Uncomment in case SIGNCERT is set and you want to create installers +# To create web-eid installer for MacOS: build/src/app/web-eid*.dmg +# To create web-eid-webextension installer for firefox and chrome: build/src/app/web-eid*.pkg +# cmake --build ${BUILD_DIR} --config ${BUILD_TYPE} --target installer + +# To create web-eid-webextension installer for safari build/src/mac/web-eid-safari_*.pkg +# cmake --build ${BUILD_DIR} --config ${BUILD_TYPE} --target installer-safari +