Skip to content

Commit 12e351e

Browse files
committed
utils: add SBoM to Windows toolchain builds
This adds an additional bit of tooling to `build.ps1` to generate a SBoM in SPDX (JSON) and cyclone (XML) formats. We also simultaneously preserve the syft format for additional metadata. This is done in preparation to ensure that we are able to track content beyond just the manifest over time.
1 parent 5264dd5 commit 12e351e

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

utils/build-windows-toolchain.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ powershell.exe -ExecutionPolicy RemoteSigned -File %~dp0build.ps1 ^
8484
%WindowsSDKsArg% ^
8585
%TestArg% ^
8686
-Stage %PackageRoot% ^
87+
-IncludeSBoM ^
8788
-Summary || (exit /b 1)
8889

8990
:: Clean up the module cache

utils/build.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
601625
function 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()
@@ -3755,6 +3785,29 @@ if (-not $IsCrossCompiling) {
37553785
}
37563786
}
37573787

3788+
if ($IncludeSBoM) {
3789+
Invoke-IsolatingEnvVars {
3790+
$env:SYFT_FILE_METADATA_SELECTION = "all"
3791+
$env:SYFT_FILE_CONTENT_GLOBS = "**\*.h"
3792+
$env:SYFT_FILE_METADATA_DIGESTS = "sha256"
3793+
Invoke-Program (Get-Syft).Path -- `
3794+
--base-path $BinaryCache `
3795+
--source-name Swift `
3796+
--source-version $ProductVersion `
3797+
-o spdx-json=$ToolchainIdentifier-sbom.spdx.json `
3798+
-o syft-json=$ToolchainIdentifier-sbom.syft.json `
3799+
-o cyclonedx-xml=$ToolchainIdentifier-sbom.cyclone.xml `
3800+
-o syft-table `
3801+
dir:$(Get-InstallDir $HostPlatform)
3802+
3803+
if ($Stage) {
3804+
Copy-File $ToolchainIdentifier-sbom.spdx.json $Stage
3805+
Copy-File $ToolchainIdentifier-sbom.syft.json $Stage
3806+
Copy-File $ToolchainIdentifier-sbom.cyclone.xml $Stage
3807+
}
3808+
}
3809+
}
3810+
37583811
# Custom exception printing for more detailed exception information
37593812
} catch {
37603813
function Write-ErrorLines($Text, $Indent = 0) {

0 commit comments

Comments
 (0)