@@ -138,6 +138,7 @@ param
138138 [switch ] $SkipBuild = $false ,
139139 [switch ] $SkipPackaging = $false ,
140140 [switch ] $IncludeDS2 = $false ,
141+ [switch ] $IncludeSBoM = $false ,
141142 [string []] $Test = @ (),
142143 [string ] $Stage = " " ,
143144 [ValidateSet (" AMD64" , " ARM64" )]
@@ -147,6 +148,7 @@ param
147148 [switch ] $DebugInfo ,
148149 [ValidatePattern (' ^\d+(\.\d+)*$' )]
149150 [string ] $SCCacheVersion = " 0.10.0" ,
151+ [string ] $SyftVersion = " 1.29.1" ,
150152 [switch ] $EnableCaching ,
151153 [ValidateSet (" debug" , " release" )]
152154 [string ] $FoundationTestConfiguration = " debug" ,
@@ -417,6 +419,16 @@ $KnownSCCache = @{
417419 }
418420}
419421
422+ $KnownSyft = @ {
423+ " 1.29.1" = @ {
424+ AMD64 = @ {
425+ URL = " https://github.com/anchore/syft/releases/download/v1.29.1/syft_1.29.1_windows_amd64.zip"
426+ SHA256 = " 3C67CD9AF40CDCC7FFCE041C8349B4A77F33810184820C05DF23440C8E0AA1D7"
427+ Path = [IO.Path ]::Combine(" $BinaryCache \syft-1.29.1" , " syft.exe" )
428+ }
429+ }
430+ }
431+
420432$BuildArchName = if ($env: PROCESSOR_ARCHITEW6432 ) { $env: PROCESSOR_ARCHITEW6432 } else { $env: PROCESSOR_ARCHITECTURE }
421433# TODO: Support other cross-compilation scenarios.
422434$BuildOS = [OS ]::Windows
@@ -598,6 +610,18 @@ function Get-PythonScriptsPath {
598610 return [IO.Path ]::Combine((Get-PythonPath $BuildPlatform ), " tools" , " Scripts" )
599611}
600612
613+ function Get-Syft {
614+ return $KnownSyft [$SyftVersion ][$BuildArchName ]
615+ }
616+
617+ function Get-SyftPath ([Hashtable ] $Platform ) {
618+ return [IO.Path ]::Combine(" $BinaryCache \" , " syft-$SyftVersion " )
619+ }
620+
621+ function Get-SyftExecutable {
622+ return [IO.Path ]::Combine((Get-SyftPath $BuildPlatform ), " syft.exe" )
623+ }
624+
601625function Get-InstallDir ([Hashtable ] $Platform ) {
602626 if ($Platform -eq $HostPlatform ) {
603627 return [IO.Path ]::Combine(" $ImageRoot \" , " Program Files" , " Swift" )
@@ -1028,6 +1052,12 @@ function Get-Dependencies {
10281052 }
10291053 }
10301054
1055+ if ($IncludeSBoM ) {
1056+ $syft = Get-Syft
1057+ DownloadAndVerify $syft.URL " $BinaryCache \syft-$SyftVersion .zip" $syft.SHA256
1058+ Expand-ZipFile syft- $SyftVersion.zip $BinaryCache syft- $SyftVersion
1059+ }
1060+
10311061 if ($SkipBuild -and $SkipPackaging ) { return }
10321062
10331063 $Stopwatch = [Diagnostics.Stopwatch ]::StartNew()
@@ -3739,6 +3769,29 @@ if (-not $IsCrossCompiling) {
37393769 }
37403770}
37413771
3772+ if ($IncludeSBoM ) {
3773+ Invoke-IsolatingEnvVars {
3774+ $env: SYFT_FILE_METADATA_SELECTION = " all"
3775+ $env: SYFT_FILE_CONTENT_GLOBS = " **\*.h"
3776+ $env: SYFT_FILE_METADATA_DIGESTS = " sha256"
3777+ Invoke-Program (Get-Syft ).Path -- `
3778+ -- base- path $BinaryCache `
3779+ -- source- name Swift `
3780+ -- source- version $ProductVersion `
3781+ - o spdx- json= $ToolchainIdentifier - sbom.spdx.json `
3782+ - o syft- json= $ToolchainIdentifier - sbom.syft.json `
3783+ - o cyclonedx- xml= $ToolchainIdentifier - sbom.cyclone.xml `
3784+ - o syft- table `
3785+ dir:$ (Get-InstallDir $HostPlatform )
3786+
3787+ if ($Stage ) {
3788+ Copy-File $ToolchainIdentifier - sbom.spdx.json $Stage
3789+ Copy-File $ToolchainIdentifier - sbom.syft.json $Stage
3790+ Copy-File $ToolchainIdentifier - sbom.cyclone.xml $Stage
3791+ }
3792+ }
3793+ }
3794+
37423795# Custom exception printing for more detailed exception information
37433796} catch {
37443797 function Write-ErrorLines ($Text , $Indent = 0 ) {
0 commit comments