From dd2c5b58c4fe77d7ce35f3abb6e1bb399560a2db Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 17 Jan 2021 13:54:57 +0300 Subject: GIANT CLUSTERFUCK OF A COMMIT OK, this is epic. I was basically just trying to a) support Clang and b) add more test coverage. _THREE MONTHS_ and a few hundred CI runs later, this is what I came up with. I don't know how it ended up being what it is, but here we go. Some highlights of the changes: 1) CI builds has been moved to GitHub Actions, 2) the entire notion of a toolchain has been reworked; it now supports Clang on all platforms. * .github: this directory contains the GitHub Actions workflow scripts/actions. In the process, I created like 6 external GitHub actions, but it's still pretty massive. An upside is that it covers much more platform/toolchain combinations _and_ check a lot of the expected post-conditions. TODO: .ci/Makefile is obsolete now, as well as .travis.yml and .appveyor.yml. * common.cmake: added Clang support. In the process, a great deal has been learned about how CMake works; in particular, static runtime support has been reworked to be more robust. * project: the entire notion of a "toolchain" has been reworked. Instead of a measly --mingw parameter, there's now a separate --toolset parameter, which allows you to choose between GCC, Clang, MSVC, etc. Both Boost and CMake build scripts were enhanced greatly to support Clang and other toolchains in a more robust way. --- .github/actions/check-runtime-library/action.yml | 161 +++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 .github/actions/check-runtime-library/action.yml (limited to '.github/actions/check-runtime-library/action.yml') diff --git a/.github/actions/check-runtime-library/action.yml b/.github/actions/check-runtime-library/action.yml new file mode 100644 index 0000000..3025334 --- /dev/null +++ b/.github/actions/check-runtime-library/action.yml @@ -0,0 +1,161 @@ +name: Verify runtime library linkage +description: Verify runtime library linkage (static or shared) +inputs: + path: + description: Installation directory + required: true +runs: + using: composite + steps: + - run: | + New-Variable path -Value '${{ inputs.path }}' -Option Constant + + function Parse-DllLine { + param( + [Parameter(Mandatory=$true)] + [string] $Line + ) + + if ($Line -match '^\s*DLL Name:\s*(?\S+)\s*$') { + $Matches.dll + } else { + throw "Line doesn't match the pattern: $Line" + } + } + + function Parse-PeHeaders { + param( + [Parameter(ValueFromPipeline)] + [string[]] $Output + ) + + process { + $Output | Select-String 'DLL Name:' -SimpleMatch -CaseSensitive | %{ + Parse-DllLine $_ + } + } + } + + function Parse-NeededLine { + param( + [Parameter(Mandatory=$true)] + [string] $Line + ) + + if ($Line -match '^\s*NEEDED\s*(?\S+)\s*$') { + $Matches.dll + } else { + throw "Line doesn't match the pattern: $Line" + } + } + + function Parse-ElfHeaders { + param( + [Parameter(ValueFromPipeline)] + [string[]] $Output + ) + + process { + $Output | Select-String 'NEEDED' -SimpleMatch -CaseSensitive | %{ + Parse-NeededLine $_ + } + } + } + + function Get-LinkedLibraries { + param( + [Parameter(Mandatory=$true)] + [string] $ExePath + ) + + $objdump = 'objdump' + if ($env:CI_HOST_WINDOWS) { + $objdump = 'C:\ProgramData\chocolatey\bin\objdump.exe' + } + + if ($env:CI_TARGET_PE) { + & $objdump -x $ExePath | Parse-PeHeaders | echo + } + if ($env:CI_TARGET_ELF) { + & $objdump -x $ExePath | Parse-ElfHeaders | echo + } + } + + function Do-ValidateLinkedLibraries { + param( + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string[]] $Actual, + + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string[]] $Required, + + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string[]] $Optional + ) + + echo 'Linked libraries:' + echo $Actual + + $missing = $Required | ?{$_ -notin $Actual} + + if ($missing.Count -gt 0) { + throw "Doesn't link to the following libraries: $($missing -join ', ')" + } + + $unexpected = $Actual | ?{$_ -notin $Required -and $_ -notin $Optional} + + if ($unexpected.Count -gt 0) { + throw "Links to the following unexpected libraries: $($unexpected -join ', ')" + } + } + + function Validate-LinkedLibraries { + param( + [Parameter(Mandatory=$true)] + [ValidateNotNull()] + [string[]] $Actual + ) + + $windows_required = @('KERNEL32.dll') + if ($env:CI_MINGW) { + $windows_required += 'msvcrt.dll' + } + # Linking libstdc++ statically on Cygwin is broken, see the + # cygwin_static_libstdc++.yml workflow. + $cygwin_required = $windows_required + @('cygwin1.dll','cygstdc++-6.dll') + $linux_required = @('libc.so.6') + + $windows_optional = @('baz.dll') + if ($env:CI_MINGW) { + $windows_optional = @('libbaz.dll','USER32.dll') + } + $cygwin_optional = @('cygbaz.dll') + $linux_optional = @('libbaz.so','ld-linux.so.2','ld-linux-x86-64.so.2','libm.so.6') + + if ($env:CI_TARGET_CYGWIN) { + Do-ValidateLinkedLibraries ` + -Actual $Actual ` + -Required $cygwin_required ` + -Optional $cygwin_optional + } elseif ($env:CI_TARGET_WINDOWS) { + Do-ValidateLinkedLibraries ` + -Actual $Actual ` + -Required $windows_required ` + -Optional $windows_optional + } elseif ($env:CI_TARGET_LINUX) { + Do-ValidateLinkedLibraries ` + -Actual $Actual ` + -Required $linux_required ` + -Optional $linux_optional + } else { + throw 'Where am I?' + } + } + + $exe_path = (Join-Path $path 'bin' 'foo') + $env:CI_EXE_EXT + $libraries = Get-LinkedLibraries $exe_path + Validate-LinkedLibraries $libraries + shell: pwsh -- cgit v1.2.3