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 custom central feed service to builds #425

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# CFS/ADO crate feed is currently only working with unstable features.
[unstable]
registry-auth = true

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

# Enable Control Flow Guard (needed for OneBranch's post-build analysis).
[target.'cfg(target_os = "windows")']
rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE /CETCOMPAT"]

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-msft-linux-gcc"
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Cargo.lock
target
bin/
.DS_Store
Expand All @@ -10,4 +9,3 @@ node_modules/
tree-sitter-dscexpression/bindings/
tree-sitter-dscexpression/src/
tree-sitter-dscexpression/parser.*
tree-sitter-dscexpression/binding.gyp
125 changes: 118 additions & 7 deletions .pipelines/DSC-Official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ extends:
repoRoot: $(Build.SourcesDirectory)\DSC
ob_sdl_tsa_configFile: $(Build.SourcesDirectory)\DSC\.config\tsaoptions.json
ob_outputDirectory: '$(Build.ArtifactStagingDirectory)'
ob_sdl_sbom_enabled: false
ob_signing_setup_enabled: false
ob_sdl_codeql_compiled_enabled: false
steps:
- checkout: self
- pwsh: |
Expand Down Expand Up @@ -92,37 +95,64 @@ extends:
signSrcPath: '$(Build.SourcesDirectory)\out'
ob_sdl_sbom_enabled: true
ob_signing_setup_enabled: true
ob_sdl_codeql_compiled_enabled: false
ob_sdl_codeql_compiled_enabled: true
pool:
type: windows
displayName: BuildWin
steps:
- checkout: self
env:
env:
ob_restore_phase: true
- task: CodeQL3000Init@0 # Add CodeQL Init task right before your 'Build' step.
inputs:
Enabled: true
AnalyzeInPipeline: true
Language: rust
env:
env:
ob_restore_phase: true
- pwsh: |
$tmpdir = "$(Agent.TempDirectory)"
Write-Host "##vso[task.setvariable variable=CARGO_TARGET_DIR;]$tmpdir"
displayName: 🛠️ Workaround for the LoadLibrary ACCESS_VIOLATION OneBranch issue
env:
env:
ob_restore_phase: true
- task: RustInstaller@1
inputs:
rustVersion: ms-stable
toolchainFeed: https://pkgs.dev.azure.com/mscodehub/Rust/_packaging/Rust/nuget/v3/index.json
cratesIoFeedOverride: sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/
additionalTargets: $(buildName)
displayName: Install Rust
env:
ob_restore_phase: true
- task: AzureCLI@2
inputs:
azureSubscription: az-PowerShell-feed-ingestion
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv

# Set the access token as a secret, so it doesn't get leaked in the logs
Write-Host "##vso[task.setsecret]$accessToken"
$header = "Bearer $accessToken"
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
displayName: 'Get Azure DevOps Token'
env:
ob_restore_phase: true
- pwsh: |
Set-Location "$(Build.SourcesDirectory)/DSC"
Write-Host "Use 'powershell' CFS"
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck
displayName: 'Build $(buildName)'
env:
env:
ob_restore_phase: true
condition: succeeded()
- task: CodeQL3000Finalize@0 # Add CodeQL Finalize task right after your 'Build' step.
condition: always()
env:
env:
ob_restore_phase: true
- pwsh: |
$null = New-Item -ItemType Directory -Path "$(PackageRoot)" -ErrorAction Ignore
Expand All @@ -137,7 +167,7 @@ extends:
write-host 'Binaries in $(signSrcPath)'
dir -r "$(signSrcPath)"
displayName: Copy built binaries
env:
env:
ob_restore_phase: true
condition: succeeded()
- task: onebranch.pipeline.signing@1
Expand Down Expand Up @@ -220,7 +250,34 @@ extends:
pool:
type: linux
steps:
- task: RustInstaller@1
inputs:
rustVersion: ms-stable
toolchainFeed: https://pkgs.dev.azure.com/mscodehub/Rust/_packaging/Rust/nuget/v3/index.json
cratesIoFeedOverride: sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/
additionalTargets: x86_64-unknown-linux-gnu
displayName: Install Rust
env:
ob_restore_phase: true
- task: AzureCLI@2
inputs:
azureSubscription: az-PowerShell-feed-ingestion
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv

# Set the access token as a secret, so it doesn't get leaked in the logs
Write-Host "##vso[task.setsecret]$accessToken"
$header = "Bearer $accessToken"
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
displayName: 'Get Azure DevOps Token'
env:
ob_restore_phase: true
- pwsh: |
Write-Host "Use 'powershell' CFS"
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu
./build.ps1 -PackageType tgz -Architecture x86_64-unknown-linux-gnu -Release
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
Expand All @@ -237,7 +294,34 @@ extends:
type: linux
hostArchitecture: arm64
steps:
- task: RustInstaller@1
inputs:
rustVersion: ms-stable
toolchainFeed: https://pkgs.dev.azure.com/mscodehub/Rust/_packaging/Rust/nuget/v3/index.json
cratesIoFeedOverride: sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/
additionalTargets: aarch64-unknown-linux-gnu
displayName: Install Rust
env:
ob_restore_phase: true
- task: AzureCLI@2
inputs:
azureSubscription: az-PowerShell-feed-ingestion
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv

# Set the access token as a secret, so it doesn't get leaked in the logs
Write-Host "##vso[task.setsecret]$accessToken"
$header = "Bearer $accessToken"
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
displayName: 'Get Azure DevOps Token'
env:
ob_restore_phase: true
- pwsh: |
Write-Host "Use 'powershell' CFS"
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu
./build.ps1 -PackageType tgz -Architecture aarch64-unknown-linux-gnu -Release
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
Expand All @@ -262,7 +346,34 @@ extends:
macOS arm64:
buildName: aarch64-apple-darwin
steps:
- task: RustInstaller@1
inputs:
rustVersion: ms-stable
toolchainFeed: https://pkgs.dev.azure.com/mscodehub/Rust/_packaging/Rust/nuget/v3/index.json
cratesIoFeedOverride: sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/
additionalTargets: $(buildName)
displayName: Install Rust
env:
ob_restore_phase: true
- task: AzureCLI@2
inputs:
azureSubscription: az-PowerShell-feed-ingestion
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv

# Set the access token as a secret, so it doesn't get leaked in the logs
Write-Host "##vso[task.setsecret]$accessToken"
$header = "Bearer $accessToken"
Write-Host "##vso[task.setvariable variable=CARGO_REGISTRIES_POWERSHELL_TOKEN]$header"
displayName: 'Get Azure DevOps Token'
env:
ob_restore_phase: true
- pwsh: |
Write-Host "Use 'powershell' CFS"
Add-Content -Path "./.cargo/config.toml" -Value '[source.crates-io]'
Add-Content -Path "./.cargo/config.toml" -Value 'replace-with = "powershell"'
./build.ps1 -Release -Architecture $(buildName)
./build.ps1 -PackageType tgz -Architecture $(buildName) -Release
Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)"
Expand Down
10 changes: 8 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ function Find-LinkExe {
}
}

if ($null -ne (Get-Command rustup -ErrorAction Ignore)) {
$rustup = 'rustup'
} else {
$rustup = 'echo'
}

if ($null -ne $packageType) {
$SkipBuild = $true
} else {
Expand All @@ -112,7 +118,7 @@ if ($null -ne $packageType) {

$BuildToolsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"

rustup default stable
& $rustup default stable
}

if (!$SkipBuild -and !$SkipLinkCheck -and $IsWindows -and !(Get-Command 'link.exe' -ErrorAction Ignore)) {
Expand Down Expand Up @@ -153,7 +159,7 @@ if ($architecture -eq 'current') {
$target = Join-Path $PSScriptRoot 'bin' $configuration
}
else {
rustup target add $architecture
& $rustup target add $architecture
$flags += '--target'
$flags += $architecture
$path = ".\target\$architecture\$configuration"
Expand Down