Skip to content

Commit

Permalink
refactor(ci): Simplify the azure windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Dec 23, 2023
1 parent aebc0c2 commit 7ac9c0d
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 188 deletions.
334 changes: 147 additions & 187 deletions tools/azure-devops/win/build.ps1
Original file line number Diff line number Diff line change
@@ -1,193 +1,153 @@
Write-Host -ForegroundColor Green "`n## Build Path $env:Build_Repository_LocalPath #####`n"

try {
$build_encryption = "MBEDTLS"

if ($env:CC_SHORTNAME -eq "vs2008" -or $env:CC_SHORTNAME -eq "vs2013") {
# on VS2008 mbedtls can not be built since it includes stdint.h which is not available there
$build_encryption = "OFF"
Write-Host -ForegroundColor Green "`n## Building without encryption on VS2008 or VS2013 #####`n"
}

Write-Host -ForegroundColor Green "`n## Build Path $env:Build_Repository_LocalPath #####`n"

$vcpkg_toolchain = ""
$vcpkg_triplet = ""

if ($env:CC_SHORTNAME -eq "vs2008" -or $env:CC_SHORTNAME -eq "vs2013") {
# on VS2008 mbedtls can not be built since it includes stdint.h which is not available there
$build_encryption = "OFF"
Write-Host -ForegroundColor Green "`n## Building without encryption on VS2008 or VS2013 #####`n"
} else {
$build_encryption = "MBEDTLS"
}

if ($env:CC_SHORTNAME -eq "mingw" -or $env:CC_SHORTNAME -eq "clang-mingw") {
# Workaround for CMake not wanting sh.exe on PATH for MinGW (necessary for CMake 3.12.2)
$env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\bin' }) -join ';'
$env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\usr\bin' }) -join ';'
# Add mingw to path so that CMake finds e.g. clang
$env:PATH = "$env:MSYS2_ROOT\mingw64\bin;$env:PATH"
[System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')
}

if ($env:CC_SHORTNAME -eq "mingw") {

} elseif ($env:CC_SHORTNAME -eq "clang-mingw") {
# Setup clang
$env:CC = "clang --target=x86_64-w64-mingw32"
$env:CXX = "clang++ --target=x86_64-w64-mingw32"
clang --version
} else {
$vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake"'
$vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
# since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
# vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
New-Item -Force -ItemType directory -Path "C:/vcpkg/installed/x86-windows-static"
}

$cmake_cnf="$vcpkg_toolchain", "$vcpkg_triplet", "-G`"$env:GENERATOR`""

# Collect files for .zip packing
New-Item -ItemType directory -Path pack
Copy-Item LICENSE pack
Copy-Item AUTHORS pack
Copy-Item README.md pack

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=OFF `
-DCMAKE_BUILD_TYPE=Debug `
-DUA_BUILD_EXAMPLES=OFF `
-DUA_BUILD_UNIT_TESTS=ON `
-DUA_ENABLE_DA=ON `
-DUA_ENABLE_DISCOVERY=ON `
-DUA_ENABLE_ENCRYPTION:STRING=$build_encryption `
-DUA_ENABLE_JSON_ENCODING:BOOL=ON `
-DUA_ENABLE_PUBSUB:BOOL=ON `
-DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
-DUA_ENABLE_PUBSUB_MONITORING:BOOL=ON `
-DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON `
-DUA_FORCE_WERROR=ON `
..
& cmake --build . --config Debug
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
exit $LASTEXITCODE
}
& cmake --build . --target test-verbose --config Debug -j 1
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Building $env:CC_NAME examples without amalgamation #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=OFF `
-DCMAKE_BUILD_TYPE=RelWithDebInfo `
-DCMAKE_INSTALL_PREFIX="$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static" `
-DUA_BUILD_EXAMPLES:BOOL=ON `
-DUA_ENABLE_AMALGAMATION:BOOL=OFF `
-DUA_FORCE_WERROR=ON `
..
& cmake --build . --target install --config RelWithDebInfo
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
{
Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
& 7z a -tzip "$env:Build_ArtifactStagingDirectory/open62541-$env:CC_SHORTNAME-static.zip" "$env:Build_Repository_LocalPath\pack\*" "$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static\*"
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
{
Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
exit $LASTEXITCODE
}
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DCMAKE_BUILD_TYPE=RelWithDebInfo `
-DUA_BUILD_EXAMPLES:BOOL=OFF `
-DUA_ENABLE_AMALGAMATION:BOOL=ON `
-DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON `
-DUA_ENABLE_ENCRYPTION:STRING=$build_encryption `
-DUA_FORCE_WERROR=ON `
..
& cmake --build . --config RelWithDebInfo
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
get-content D:\a\1\s\build\open62541.c
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
New-Item -ItemType directory -Path "build"
cd build
# Use build type Debug here, to force `-Werror`
& cmake $cmake_cnf `
-DCMAKE_BUILD_TYPE=Debug `
-DUA_BUILD_EXAMPLES:BOOL=ON `
-DUA_ENABLE_DA:BOOL=ON `
-DUA_ENABLE_JSON_ENCODING:BOOL=ON `
-DUA_ENABLE_PUBSUB:BOOL=ON `
-DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
-DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON `
-DUA_FORCE_WERROR=ON `
-DUA_NAMESPACE_ZERO:STRING=FULL `
..
& cmake --build . --config Debug
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME (.dll) #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=ON `
-DCMAKE_BUILD_TYPE=RelWithDebInfo `
-DCMAKE_INSTALL_PREFIX="$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-dynamic" `
-DUA_BUILD_EXAMPLES:BOOL=ON `
-DUA_ENABLE_AMALGAMATION:BOOL=OFF `
-DUA_FORCE_WERROR=ON `
..
& cmake --build . --target install --config RelWithDebInfo
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
{
Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
& 7z a -tzip "$env:Build_ArtifactStagingDirectory/open62541-$env:CC_SHORTNAME-dynamic.zip" "$env:Build_Repository_LocalPath\pack\*" "$env:Build_Repository_LocalPath-$env:CC_SHORTNAME-static\*"
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0)
{
Write-Host -ForegroundColor Red "`n`n*** Zipping failed. Exiting ... ***"
exit $LASTEXITCODE
}
Remove-Item -Path build -Recurse -Force

if ($env:CC_SHORTNAME -eq "mingw" -or $env:CC_SHORTNAME -eq "clang-mingw") {
# Workaround for CMake not wanting sh.exe on PATH for MinGW (necessary for CMake 3.12.2)
$env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\bin' }) -join ';'
$env:PATH = ($env:PATH.Split(';') | Where-Object { $_ -ne 'C:\Program Files\Git\usr\bin' }) -join ';'
# Add mingw to path so that CMake finds e.g. clang
$env:PATH = "$env:MSYS2_ROOT\mingw64\bin;$env:PATH"
[System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')
}

# # do not cache log
# Remove-Item -Path c:\miktex\texmfs\data\miktex\log -Recurse -Force
$vcpkg_toolchain = ""
$vcpkg_triplet = ""

if ($env:CC_SHORTNAME -eq "mingw") {

} elseif ($env:CC_SHORTNAME -eq "clang-mingw") {
# Setup clang
$env:CC = "clang --target=x86_64-w64-mingw32"
$env:CXX = "clang++ --target=x86_64-w64-mingw32"
clang --version
} else {
$vcpkg_toolchain = '-DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake"'
$vcpkg_triplet = '-DVCPKG_TARGET_TRIPLET="x86-windows-static"'
# since https://github.com/Microsoft/vcpkg/commit/0334365f516c5f229ff4fcf038c7d0190979a38a#diff-464a170117fa96bf98b2f8d224bf503c
# vcpkg need to have "C:\Tools\vcpkg\installed\x86-windows-static"
New-Item -Force -ItemType directory -Path "C:/vcpkg/installed/x86-windows-static"
}

} catch {
# Print a detailed error message
$FullException = ($_.Exception|format-list -force) | Out-String
Write-Host -ForegroundColor Red "`n------------------ Exception ------------------`n$FullException`n"
[Console]::Out.Flush()
# Wait a bit to make sure appveyor shows the error message
Start-Sleep 10
throw
$cmake_cnf="$vcpkg_toolchain", "$vcpkg_triplet", "-G`"$env:GENERATOR`""

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with unit tests #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=OFF `
-DCMAKE_BUILD_TYPE=Debug `
-DUA_BUILD_EXAMPLES=OFF `
-DUA_BUILD_UNIT_TESTS=ON `
-DUA_ENABLE_DA=ON `
-DUA_ENABLE_DISCOVERY=ON `
-DUA_ENABLE_ENCRYPTION:STRING=$build_encryption `
-DUA_ENABLE_JSON_ENCODING:BOOL=ON `
-DUA_ENABLE_PUBSUB:BOOL=ON `
-DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
-DUA_ENABLE_PUBSUB_MONITORING:BOOL=ON `
-DUA_ENABLE_UNIT_TESTS_MEMCHECK=ON `
-DUA_FORCE_WERROR=ON `
..
& cmake --build .
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
exit $LASTEXITCODE
}
& cmake --build . --target test-verbose -j 1
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Test failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Building $env:CC_NAME examples #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=OFF `
-DCMAKE_BUILD_TYPE=Debug `
-DUA_BUILD_EXAMPLES:BOOL=ON `
-DUA_ENABLE_AMALGAMATION:BOOL=OFF `
-DUA_FORCE_WERROR=ON `
..
& cmake --build .
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with amalgamation #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=OFF `
-DCMAKE_BUILD_TYPE=Debug `
-DUA_BUILD_EXAMPLES:BOOL=OFF `
-DUA_ENABLE_AMALGAMATION:BOOL=ON `
-DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON `
-DUA_ENABLE_ENCRYPTION:STRING=$build_encryption `
-DUA_FORCE_WERROR=ON `
..
& cmake --build .
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME with full NS0 #####`n"
New-Item -ItemType directory -Path "build"
cd build
# Use build type Debug here, to force `-Werror`
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=OFF `
-DCMAKE_BUILD_TYPE=Debug `
-DUA_ENABLE_DA:BOOL=ON `
-DUA_ENABLE_JSON_ENCODING:BOOL=ON `
-DUA_ENABLE_PUBSUB:BOOL=ON `
-DUA_ENABLE_PUBSUB_INFORMATIONMODEL:BOOL=ON `
-DUA_ENABLE_SUBSCRIPTIONS_EVENTS:BOOL=ON `
-DUA_FORCE_WERROR=ON `
-DUA_NAMESPACE_ZERO:STRING=FULL `
..
& cmake --build .
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force

Write-Host -ForegroundColor Green "`n###################################################################"
Write-Host -ForegroundColor Green "`n##### Testing $env:CC_NAME (.dll) #####`n"
New-Item -ItemType directory -Path "build"
cd build
& cmake $cmake_cnf `
-DBUILD_SHARED_LIBS:BOOL=ON `
-DCMAKE_BUILD_TYPE=Debug`
-DUA_BUILD_EXAMPLES:BOOL=ON `
-DUA_ENABLE_AMALGAMATION:BOOL=OFF `
-DUA_FORCE_WERROR=ON `
..
& cmake --build .
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Make install failed. Exiting ... ***"
exit $LASTEXITCODE
}
cd ..
Remove-Item -Path build -Recurse -Force
7 changes: 6 additions & 1 deletion tools/azure-devops/win/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ try {
Write-Host -ForegroundColor Green "`n### Installing mbedtls via PacMan ###`n"
& C:\msys64\usr\bin\pacman --noconfirm --needed -S mingw-w64-x86_64-mbedtls
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Install failed. Exiting ... ***"
Write-Host -ForegroundColor Red "`n`n*** Install of mbedTLS failed. Exiting ... ***"
exit $LASTEXITCODE
}

& C:\msys64\usr\bin\pacman --noconfirm --needed -S mingw-w64-x86_64-check
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
Write-Host -ForegroundColor Red "`n`n*** Install of check failed. Exiting ... ***"
exit $LASTEXITCODE
}
} else {
Write-Host -ForegroundColor Green "`n### Installing mbedtls via vcpkg ###`n"
& vcpkg install mbedtls:x86-windows-static
Expand Down

0 comments on commit 7ac9c0d

Please sign in to comment.