name: Verify runtime library linkage description: Verify runtime library linkage (static or shared) inputs: install_dir: description: Installation directory required: true runs: using: composite steps: - env: ARG_INSTALL_DIR: ${{ inputs.install_dir }} run: | $install_dir = (Get-ChildItem env:ARG_INSTALL_DIR).Value 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-Objdump { $objdump = Get-Command 'objdump' -ErrorAction SilentlyContinue if ($objdump) { return $objdump.Path } $objdump = 'C:\ProgramData\chocolatey\bin\objdump.exe' if (Test-Path $objdump -Type Leaf) { return $objdump } $objdump = 'C:\mingw64\bin\objdump.exe' if (Test-Path $objdump -Type Leaf) { return $objdump } return 'objdump' } function Get-LinkedLibraries { param( [Parameter(Mandatory=$true)] [string] $ExePath ) $objdump = 'objdump' if ((Get-ChildItem env:CI_HOST_WINDOWS).Value) { $objdump = Get-Objdump } if ((Get-ChildItem env:CI_TARGET_PE).Value) { & $objdump -x $ExePath | Parse-PeHeaders | echo } if ((Get-ChildItem env:CI_TARGET_ELF).Value) { & $objdump -x $ExePath | Parse-ElfHeaders | echo } } function Do-ValidateLinkedLibraries { param( [Parameter(Mandatory=$true)] [ValidateNotNull()] [string[]] $Actual, [ValidateNotNull()] [string[]] $Forbidden ) echo 'Linked libraries:' echo $Actual $unexpected = $Actual | ?{$_ -in $Forbidden} 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_forbidden = @('msvcrt.dll') if ((Get-ChildItem env:CI_MINGW).Value) { if (!(Get-ChildItem env:CI_HOST_WINDOWS).Value) { $windows_forbidden = @() } } $linux_forbidden = @() if ((Get-ChildItem env:CI_TARGET_WINDOWS).Value) { Do-ValidateLinkedLibraries ` -Actual $Actual ` -Forbidden $windows_forbidden } elseif ((Get-ChildItem env:CI_TARGET_LINUX).Value) { Do-ValidateLinkedLibraries ` -Actual $Actual ` -Forbidden $linux_forbidden } else { throw 'Where am I?' } } $name = 'foo' + (Get-ChildItem env:CI_EXE_EXT).Value $path = Join-Path $install_dir 'bin' $name $libraries = Get-LinkedLibraries $path Validate-LinkedLibraries $libraries shell: pwsh