@@ -138,6 +138,7 @@ param
138
138
[switch ] $SkipBuild = $false ,
139
139
[switch ] $SkipPackaging = $false ,
140
140
[switch ] $IncludeDS2 = $false ,
141
+ [switch ] $IncludeSBoM = $false ,
141
142
[string []] $Test = @ (),
142
143
[string ] $Stage = " " ,
143
144
[ValidateSet (" AMD64" , " ARM64" )]
@@ -147,6 +148,7 @@ param
147
148
[switch ] $DebugInfo ,
148
149
[ValidatePattern (' ^\d+(\.\d+)*$' )]
149
150
[string ] $SCCacheVersion = " 0.10.0" ,
151
+ [string ] $SyftVersion = " 1.29.1" ,
150
152
[switch ] $EnableCaching ,
151
153
[ValidateSet (" debug" , " release" )]
152
154
[string ] $FoundationTestConfiguration = " debug" ,
@@ -417,6 +419,16 @@ $KnownSCCache = @{
417
419
}
418
420
}
419
421
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
+
420
432
$BuildArchName = if ($env: PROCESSOR_ARCHITEW6432 ) { $env: PROCESSOR_ARCHITEW6432 } else { $env: PROCESSOR_ARCHITECTURE }
421
433
# TODO: Support other cross-compilation scenarios.
422
434
$BuildOS = [OS ]::Windows
@@ -598,6 +610,18 @@ function Get-PythonScriptsPath {
598
610
return [IO.Path ]::Combine((Get-PythonPath $BuildPlatform ), " tools" , " Scripts" )
599
611
}
600
612
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
+
601
625
function Get-InstallDir ([Hashtable ] $Platform ) {
602
626
if ($Platform -eq $HostPlatform ) {
603
627
return [IO.Path ]::Combine(" $ImageRoot \" , " Program Files" , " Swift" )
@@ -1028,6 +1052,12 @@ function Get-Dependencies {
1028
1052
}
1029
1053
}
1030
1054
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
+
1031
1061
if ($SkipBuild -and $SkipPackaging ) { return }
1032
1062
1033
1063
$Stopwatch = [Diagnostics.Stopwatch ]::StartNew()
@@ -3739,6 +3769,29 @@ if (-not $IsCrossCompiling) {
3739
3769
}
3740
3770
}
3741
3771
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
+
3742
3795
# Custom exception printing for more detailed exception information
3743
3796
} catch {
3744
3797
function Write-ErrorLines ($Text , $Indent = 0 ) {
0 commit comments