Skip to content

Commit 4745ad2

Browse files
authored
Merge pull request #513 from SteveL-MSFT/publish-token
Default build to using CFS and include musl
2 parents 45789c5 + b9540a9 commit 4745ad2

File tree

25 files changed

+1791
-2327
lines changed

25 files changed

+1791
-2327
lines changed

.cargo/config.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
registry-auth = true
44

55
[registries]
6-
powershell = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" }
6+
POWERSHELL = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" }
77

88
[registry]
99
global-credential-providers = ["cargo:token"]
@@ -17,4 +17,10 @@ rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-arg
1717

1818
# The following is only needed for release builds
1919
[source.crates-io]
20-
replace-with = "powershell"
20+
replace-with = "POWERSHELL"
21+
22+
[target.aarch64-unknown-linux-gnu]
23+
linker = "aarch64-linux-gnu-gcc"
24+
25+
[target.aarch64-unknown-linux-musl]
26+
linker = "aarch64-linux-musl-gcc"

.github/workflows/rust.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ jobs:
2828
shell: pwsh
2929
run: ./build.ps1 -test
3030

31+
build-musl:
32+
33+
runs-on: ubuntu-latest
34+
35+
steps:
36+
- uses: actions/checkout@v3
37+
- run: rustup target add x86_64-unknown-linux-musl
38+
- name: Install musl build tools
39+
run: sudo apt update && sudo apt install musl-tools -y
40+
- name: Build
41+
shell: pwsh
42+
run: ./build.ps1 -clippy -target x86_64-unknown-linux-musl
43+
- name: Run tests
44+
shell: pwsh
45+
run: ./build.ps1 -test -target x86_64-unknown-linux-musl
46+
3147
build-windows:
3248

3349
runs-on: windows-latest

.pipelines/DSC-Official.yml

Lines changed: 76 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
name: DSC-Release-$(Build.BuildId)
22
trigger: none
33

4-
parameters:
5-
- name: 'debugConsole'
6-
displayName: 'Enable debug console'
7-
type: boolean
8-
default: false
9-
104
pr:
115
branches:
126
include:
@@ -16,8 +10,9 @@ pr:
1610
variables:
1711
BuildConfiguration: 'release'
1812
PackageRoot: '$(System.ArtifactsDirectory)/Packages'
19-
LinuxContainerImage: 'mcr.microsoft.com/onebranch/cbl-mariner/build:2.0'
20-
WindowsContainerImage: onebranch.azurecr.io/windows/ltsc2019/vse2022:latest
13+
# LinuxContainerImage: 'mcr.microsoft.com/onebranch/cbl-mariner/build:2.0'
14+
LinuxContainerImage: 'onebranch.azurecr.io/linux/ubuntu-2204:latest'
15+
WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2022/vse2022:latest'
2116

2217
resources:
2318
repositories:
@@ -30,7 +25,9 @@ extends:
3025
template: v2/OneBranch.Official.CrossPlat.yml@onebranchTemplates
3126
parameters:
3227
featureFlags:
33-
debugConsole: ${{ parameters.debugConsole }}
28+
WindowsHostVersion:
29+
Disk: Large
30+
Version: 2022
3431
customTags: 'ES365AIMigrationTooling'
3532
globalSdl:
3633
disableLegacyManifest: true
@@ -60,6 +57,7 @@ extends:
6057
displayName: Set PackageVersion
6158
pool:
6259
type: windows
60+
vmImage: windows-latest
6361
variables:
6462
repoRoot: $(Build.SourcesDirectory)\DSC
6563
ob_sdl_tsa_configFile: $(Build.SourcesDirectory)\DSC\.config\tsaoptions.json
@@ -124,24 +122,15 @@ extends:
124122
displayName: Install Rust
125123
env:
126124
ob_restore_phase: true
127-
- task: AzureCLI@2
128-
inputs:
129-
azureSubscription: az-PowerShell-feed-ingestion
130-
scriptType: 'pscore'
131-
scriptLocation: 'inlineScript'
132-
inlineScript: |
133-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
134-
135-
# Set the access token as a secret, so it doesn't get leaked in the logs
136-
Write-Host "##vso[task.setsecret]$accessToken"
137-
$header = "Bearer $accessToken"
138-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
139-
displayName: 'Get Azure DevOps Token'
140-
env:
141-
ob_restore_phase: true
142125
- pwsh: |
143126
Set-Location "$(Build.SourcesDirectory)/DSC"
144-
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck -UseCFS
127+
$LLVMBIN = "$($env:PROGRAMFILES)\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\bin"
128+
if (!(Test-Path $LLVMBIN)) {
129+
throw "LLVM path '$LLVMBIN' does not exist"
130+
}
131+
$env:PATH += ";$LLVMBIN"
132+
write-verbose -verbose (gcm clang.exe | out-string)
133+
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck
145134
displayName: 'Build $(buildName)'
146135
env:
147136
ob_restore_phase: true
@@ -257,23 +246,8 @@ extends:
257246
displayName: Install Rust
258247
env:
259248
ob_restore_phase: true
260-
- task: AzureCLI@2
261-
inputs:
262-
azureSubscription: az-PowerShell-feed-ingestion
263-
scriptType: 'pscore'
264-
scriptLocation: 'inlineScript'
265-
inlineScript: |
266-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
267-
268-
# Set the access token as a secret, so it doesn't get leaked in the logs
269-
Write-Host "##vso[task.setsecret]$accessToken"
270-
$header = "Bearer $accessToken"
271-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
272-
displayName: 'Get Azure DevOps Token'
273-
env:
274-
ob_restore_phase: true
275249
- pwsh: |
276-
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu -UseCFS
250+
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu
277251
./build.ps1 -PackageType tgz -Architecture x86_64-unknown-linux-gnu -Release
278252
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
279253
displayName: 'Build x86_64-unknown-linux-gnu'
@@ -287,7 +261,6 @@ extends:
287261
displayName: Linux-ARM64-gnu
288262
pool:
289263
type: linux
290-
hostArchitecture: arm64
291264
steps:
292265
- task: RustInstaller@1
293266
inputs:
@@ -297,26 +270,69 @@ extends:
297270
displayName: Install Rust
298271
env:
299272
ob_restore_phase: true
300-
- task: AzureCLI@2
273+
- pwsh: |
274+
apt -y install gcc-aarch64-linux-gnu
275+
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu
276+
./build.ps1 -PackageType tgz -Architecture aarch64-unknown-linux-gnu -Release
277+
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
278+
displayName: 'Build aarch64-unknown-linux-gnu'
279+
condition: succeeded()
280+
281+
- job: BuildLinuxMusl
282+
dependsOn: SetPackageVersion
283+
variables:
284+
PackageVersion: $[ dependencies.SetPackageVersion.outputs['Package.Version'] ]
285+
ob_outputDirectory: '$(Build.ArtifactStagingDirectory)'
286+
displayName: Linux-x64-musl
287+
pool:
288+
type: linux
289+
steps:
290+
- task: RustInstaller@1
301291
inputs:
302-
azureSubscription: az-PowerShell-feed-ingestion
303-
scriptType: 'pscore'
304-
scriptLocation: 'inlineScript'
305-
inlineScript: |
306-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
292+
rustVersion: ms-stable
293+
toolchainFeed: https://pkgs.dev.azure.com/mscodehub/Rust/_packaging/Rust/nuget/v3/index.json
294+
additionalTargets: x86_64-unknown-linux-musl
295+
displayName: Install Rust
296+
env:
297+
ob_restore_phase: true
298+
- pwsh: |
299+
apt -y install musl-tools
300+
./build.ps1 -Release -Architecture x86_64-unknown-linux-musl
301+
./build.ps1 -PackageType tgz -Architecture x86_64-unknown-linux-musl -Release
302+
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
303+
displayName: 'Build x86_64-unknown-linux-musl'
304+
condition: succeeded()
307305
308-
# Set the access token as a secret, so it doesn't get leaked in the logs
309-
Write-Host "##vso[task.setsecret]$accessToken"
310-
$header = "Bearer $accessToken"
311-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
312-
displayName: 'Get Azure DevOps Token'
306+
- job: BuildLinuxArm64Musl
307+
dependsOn: SetPackageVersion
308+
variables:
309+
PackageVersion: $[ dependencies.SetPackageVersion.outputs['Package.Version'] ]
310+
ob_outputDirectory: '$(Build.ArtifactStagingDirectory)'
311+
displayName: Linux-ARM64-musl
312+
pool:
313+
type: linux
314+
steps:
315+
- task: RustInstaller@1
316+
inputs:
317+
rustVersion: ms-stable
318+
toolchainFeed: https://pkgs.dev.azure.com/mscodehub/Rust/_packaging/Rust/nuget/v3/index.json
319+
additionalTargets: aarch64-unknown-linux-musl
320+
displayName: Install Rust
313321
env:
314322
ob_restore_phase: true
315323
- pwsh: |
316-
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu -UseCFS
317-
./build.ps1 -PackageType tgz -Architecture aarch64-unknown-linux-gnu -Release
324+
$env:CC_aarch64_unknown_linux_musl='clang'
325+
$env:AR_aarch64_unknown_linux_musl='llvm-ar'
326+
$env:CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"
327+
apt -y install clang
328+
apt -y install llvm
329+
apt -y install musl-tools
330+
apt -y install gcc-multilib
331+
rustup default stable-aarch64-unknown-linux-musl
332+
./build.ps1 -Release -Architecture aarch64-unknown-linux-musl
333+
./build.ps1 -PackageType tgz -Architecture aarch64-unknown-linux-musl -Release
318334
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
319-
displayName: 'Build aarch64-unknown-linux-gnu'
335+
displayName: 'Build aarch64-unknown-linux-musl'
320336
condition: succeeded()
321337
322338
- job: BuildMac
@@ -345,23 +361,8 @@ extends:
345361
displayName: Install Rust
346362
env:
347363
ob_restore_phase: true
348-
- task: AzureCLI@2
349-
inputs:
350-
azureSubscription: az-PowerShell-feed-ingestion
351-
scriptType: 'pscore'
352-
scriptLocation: 'inlineScript'
353-
inlineScript: |
354-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
355-
356-
# Set the access token as a secret, so it doesn't get leaked in the logs
357-
Write-Host "##vso[task.setsecret]$accessToken"
358-
$header = "Bearer $accessToken"
359-
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
360-
displayName: 'Get Azure DevOps Token'
361-
env:
362-
ob_restore_phase: true
363364
- pwsh: |
364-
./build.ps1 -Release -Architecture $(buildName) -UseCFS
365+
./build.ps1 -Release -Architecture $(buildName)
365366
./build.ps1 -PackageType tgz -Architecture $(buildName) -Release
366367
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
367368
Write-Host "##vso[artifact.upload containerfolder=release;artifactname=release]$(ob_outputDirectory)/DSC-$(PackageVersion)-$(buildName).tar.gz"
@@ -372,6 +373,9 @@ extends:
372373
dependsOn: BuildAndSign
373374
variables:
374375
PackageVersion: $[ dependencies.SetPackageVersion.outputs['Package.Version'] ]
376+
ob_sdl_sbom_enabled: false
377+
ob_signing_setup_enabled: false
378+
ob_sdl_codeql_compiled_enabled: false
375379
drop: $(Pipeline.Workspace)/drop_build_main
376380
jobs:
377381
- job: Validation

build.ps1

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ param(
1313
[switch]$GetPackageVersion,
1414
[switch]$SkipLinkCheck,
1515
[switch]$UseX64MakeAppx,
16-
[switch]$UseCFS
16+
[switch]$UseCratesIO
1717
)
1818

1919
if ($GetPackageVersion) {
@@ -168,7 +168,7 @@ if (!$SkipBuild) {
168168
}
169169
New-Item -ItemType Directory $target -ErrorAction Ignore > $null
170170

171-
if (!$UseCFS) {
171+
if ($UseCratesIO) {
172172
# this will override the config.toml
173173
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
174174
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
@@ -177,11 +177,28 @@ if (!$SkipBuild) {
177177
Write-Host "Using CFS for cargo source replacement"
178178
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
179179
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
180+
181+
if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) {
182+
throw "Azure CLI not found"
183+
}
184+
185+
if ($null -ne $env:CARGO_REGISTRIES_POWERSHELL_TOKEN) {
186+
Write-Host "Using existing token"
187+
} else {
188+
Write-Host "Getting token"
189+
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
190+
if ($LASTEXITCODE -ne 0) {
191+
Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
192+
} else {
193+
$header = "Bearer $accessToken"
194+
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
195+
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
196+
}
197+
}
180198
}
181199

182200
# make sure dependencies are built first so clippy runs correctly
183201
$windows_projects = @("pal", "registry", "reboot_pending", "wmi-adapter")
184-
185202
$macOS_projects = @("resources/brew")
186203
$linux_projects = @("resources/apt")
187204

0 commit comments

Comments
 (0)