Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for osx-arm64 #756

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions docs/building-from-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ dotnet run --project src/Microsoft.Sbom.Tool generate -b <drop path> -bc <build

## Building on ARM based devices running OSX

The sbom-tool targets both .NET 6 and .NET 8 therefore it is possible to produce binaries for both. We have seen issues when attempting to run the tool using the .NET 6 binaries ([#223](https://github.com/microsoft/sbom-tool/issues/223)) so for these scenarios we recommend targeting .NET 8. You can do this by following these steps:
The tool provides an osx-arm64 version of the tool. If you need to build one locally, you can build it as follows:

The following command will produce a dll that can be executed on ARM based devices running OSX and can be modified to suit your needs:

```
dotnet publish src/Microsoft.Sbom.Tool/Microsoft.Sbom.Tool.csproj --configuration Release --output bin --runtime osx-arm64 -p:TargetFramework=net8.0 -p:SelfContained=true -p:OFFICIAL_BUILD=true -p:MinVerVersionOverride=1.8.0 -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:IncludeAllContentForSelfExtract=true -p:DebugType=None -p:DebugSymbols=false
dotnet publish src/Microsoft.Sbom.Tool/Microsoft.Sbom.Tool.csproj --configuration Release --output bin --runtime osx-arm64 -p:TargetFramework=net8.0 -p:SelfContained=true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:IncludeAllContentForSelfExtract=true -p:DebugType=None
```

After running this command you can execute the tool like this:
Expand All @@ -63,14 +63,6 @@ After running this command you can execute the tool like this:
./bin/Microsoft.Sbom.Tool generate -b ~/tmp/sbom-tool/ -bc ~/tmp/sbom-tool/ -pn TestProject -pv 1.2.3 -ps Microsoft
```

## Using Dotnet Publish

Because of our multi-targeting, a target framework must be specified when using the dotnet publish command:

```
dotnet publish -f net8.0
```

## Building using Codespaces

After accessing [GitHub Codespaces](https://docs.github.com/en/free-pro-team@latest/github/developing-online-with-codespaces/about-codespaces), select the `Code` button from the [repository homepage](https://github.com/microsoft/sbom-tool), then select `Open with Codespaces`. That's it! Users will then have a full developer environment that supports debugging, testing, auto complete, jump to definitions, and everything that one would expect.
Expand Down
52 changes: 52 additions & 0 deletions pipelines/sbom-tool-main-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ variables:
ForceSigning: 'false'
WindowsNetRuntime: 'win-x64'
MacOSNetRuntime: 'osx-x64'
MacOSArm64NetRuntime: 'osx-arm64'
LinuxNetRuntime: 'linux-x64'
BinaryNameWindows: 'sbom-tool-win-x64.exe'
BinaryNameMacOS: 'sbom-tool-osx-x64'
BinaryNameMacOSArm64: 'sbom-tool-osx-arm64'
BinaryNameLinux: 'sbom-tool-linux-x64'

extends:
Expand Down Expand Up @@ -297,3 +299,53 @@ extends:
Move-Item -Path $(Build.ArtifactStagingDirectory)/osx/$(BinaryNameMacOS) -Destination $(Build.ArtifactStagingDirectory)/bin/$(BinaryNameMacOS)
Remove-Item $(Build.ArtifactStagingDirectory)/osx -Recurse
displayName: 'Restructure Artifact'

- job: Job_4
displayName: 'Build (macOS-arm64)'
templateContext:
outputs:
- output: pipelineArtifact
targetPath: $(Build.ArtifactStagingDirectory)
artifactName: '$(OutputArtifactName)-macOS-arm64'
pool:
name: Azure Pipelines
image: macos-latest
os: macOS
steps:
- task: UseDotNet@2
displayName: 'Use .NET Core'
inputs:
useGlobalJson: true

- task: DotNetCoreCLI@2
displayName: 'Restore solution'
inputs:
command: restore
feedsToUse: config
nugetConfigPath: nuget.config
verbosityRestore: Normal

- task: DotNetCoreCLI@2
displayName: Build
inputs:
arguments: '-c $(BuildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'Build self-contained binary'
inputs:
command: publish
publishWebProjects: false
projects: src/Microsoft.Sbom.Tool/Microsoft.Sbom.Tool.csproj
arguments: '-c $(BuildConfiguration) --no-restore --output $(Build.ArtifactStagingDirectory)/osx-arm64 --self-contained --runtime $(MacOSArm64NetRuntime) -p:PublishSingleFile=true -p:DebugType=None -f net8.0'
zipAfterPublish: false
modifyOutputPath: false

- powershell: 'Rename-Item -Path $(Build.ArtifactStagingDirectory)\osx-arm64\Microsoft.Sbom.Tool -NewName $(BinaryNameMacOSArm64)'
displayName: 'Rename binaries'

- powershell: |
del $(Build.ArtifactStagingDirectory)/CodeSignSummary-*.md
mkdir $(Build.ArtifactStagingDirectory)/bin
Move-Item -Path $(Build.ArtifactStagingDirectory)/osx-arm64/$(BinaryNameMacOSArm64) -Destination $(Build.ArtifactStagingDirectory)/bin/$(BinaryNameMacOSArm64)
Remove-Item $(Build.ArtifactStagingDirectory)/osx-arm64 -Recurse
displayName: 'Restructure Artifact'
2 changes: 1 addition & 1 deletion src/Microsoft.Sbom.Tool/Microsoft.Sbom.Tool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<AssemblyName>Microsoft.Sbom.Tool</AssemblyName>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x64;osx-x64;osx-arm64;linux-x64</RuntimeIdentifiers>
<IsPublishable>true</IsPublishable>
<GenerateRuntimeConfigDevFile>true</GenerateRuntimeConfigDevFile>
<Description>Highly scalable and enterprise ready tool to create SBOMs for any variety of artifacts.</Description>
Expand Down