From fb8a06bc8414a7c3d13ae1e0f941f46bc64babd7 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Wed, 3 Jul 2024 17:44:31 -0700 Subject: [PATCH 1/3] Change build to have `-UseCFS` switch otherwise uses crates-io --- .cargo/config.toml | 8 ++++++++ .pipelines/DSC-Official.yml | 37 ++++--------------------------------- build.ps1 | 13 ++++++++++++- 3 files changed, 24 insertions(+), 34 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 3985801ea..53507e627 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -4,6 +4,10 @@ registry-auth = true [registries] powershell = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" } +cratesio = { index = "sparse+https://index.crates.io/"} + +[registry] +global-credential-providers = ["cargo:token"] # Enable Control Flow Guard (needed for OneBranch's post-build analysis). [target.x86_64-pc-windows-msvc] @@ -11,3 +15,7 @@ rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-arg [target.aarch64-windows-msvc] rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE"] + +# The following is only needed for release builds +[source.crates-io] +replace-with = "powershell" diff --git a/.pipelines/DSC-Official.yml b/.pipelines/DSC-Official.yml index e8100299e..a071b8051 100644 --- a/.pipelines/DSC-Official.yml +++ b/.pipelines/DSC-Official.yml @@ -141,13 +141,7 @@ extends: 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"' - Add-Content -Path "./.cargo/config.toml" -Value '[registry]' - Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]' - - ./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck + ./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck -UseCFS displayName: 'Build $(buildName)' env: ob_restore_phase: true @@ -279,13 +273,7 @@ extends: 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"' - Add-Content -Path "./.cargo/config.toml" -Value '[registry]' - Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]' - - ./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu + ./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu -UseCFS ./build.ps1 -PackageType tgz -Architecture x86_64-unknown-linux-gnu -Release Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)" displayName: 'Build x86_64-unknown-linux-gnu' @@ -325,13 +313,7 @@ extends: 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"' - Add-Content -Path "./.cargo/config.toml" -Value '[registry]' - Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]' - - ./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu + ./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu -UseCFS ./build.ps1 -PackageType tgz -Architecture aarch64-unknown-linux-gnu -Release Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)" displayName: 'Build aarch64-unknown-linux-gnu' @@ -379,18 +361,7 @@ extends: 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"' - Add-Content -Path "./.cargo/config.toml" -Value '[registry]' - Add-Content -Path "./.cargo/config.toml" -Value 'global-credential-providers = ["cargo:token"]' - - $c = get-content "./.cargo/config.toml" | Out-String - Write-Host $c - - $env:CARGO_HTTP_DEBUG=true - $env:CARGO_LOG='network=trace' - ./build.ps1 -Release -Architecture $(buildName) + ./build.ps1 -Release -Architecture $(buildName) -UseCFS ./build.ps1 -PackageType tgz -Architecture $(buildName) -Release Copy-Item ./bin/*.tar.gz "$(ob_outputDirectory)" Write-Host "##vso[artifact.upload containerfolder=release;artifactname=release]$(ob_outputDirectory)/DSC-$(PackageVersion)-$(buildName).tar.gz" diff --git a/build.ps1 b/build.ps1 index 7e32916f0..b944ab393 100644 --- a/build.ps1 +++ b/build.ps1 @@ -12,7 +12,8 @@ param( [switch]$Test, [switch]$GetPackageVersion, [switch]$SkipLinkCheck, - [switch]$UseX64MakeAppx + [switch]$UseX64MakeAppx, + [switch]$UseCFS ) if ($GetPackageVersion) { @@ -171,6 +172,15 @@ if (!$SkipBuild) { } New-Item -ItemType Directory $target -ErrorAction Ignore > $null + if (!$UseCFS) { + # this will override the config.toml + Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'" + ${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'cratesio' + } else { + Write-Host "Using CFS for cargo source replacement" + ${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null + } + # make sure dependencies are built first so clippy runs correctly $windows_projects = @("pal", "registry", "reboot_pending", "wmi-adapter") @@ -240,6 +250,7 @@ if (!$SkipBuild) { if ($LASTEXITCODE -ne 0) { $failed = $true + break } $binary = Split-Path $project -Leaf From 883cb27927db4c19a60d7e897041d9dfb8c1b141 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Thu, 4 Jul 2024 08:06:07 -0700 Subject: [PATCH 2/3] remove unnecessary config.toml --- archive/registry/.cargo/config.toml | 4 ---- dsc/.cargo/config.toml | 4 ---- dsc_lib/.cargo/config.toml | 4 ---- osinfo/.cargo/config.toml | 4 ---- process/.cargo/config.toml | 4 ---- tools/dsctest/.cargo/config.toml | 4 ---- tools/test_group_resource/.cargo/config.toml | 4 ---- y2j/.cargo/config.toml | 4 ---- 8 files changed, 32 deletions(-) delete mode 100644 archive/registry/.cargo/config.toml delete mode 100644 dsc/.cargo/config.toml delete mode 100644 dsc_lib/.cargo/config.toml delete mode 100644 osinfo/.cargo/config.toml delete mode 100644 process/.cargo/config.toml delete mode 100644 tools/dsctest/.cargo/config.toml delete mode 100644 tools/test_group_resource/.cargo/config.toml delete mode 100644 y2j/.cargo/config.toml diff --git a/archive/registry/.cargo/config.toml b/archive/registry/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/archive/registry/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file diff --git a/dsc/.cargo/config.toml b/dsc/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/dsc/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file diff --git a/dsc_lib/.cargo/config.toml b/dsc_lib/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/dsc_lib/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file diff --git a/osinfo/.cargo/config.toml b/osinfo/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/osinfo/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file diff --git a/process/.cargo/config.toml b/process/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/process/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file diff --git a/tools/dsctest/.cargo/config.toml b/tools/dsctest/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/tools/dsctest/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file diff --git a/tools/test_group_resource/.cargo/config.toml b/tools/test_group_resource/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/tools/test_group_resource/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file diff --git a/y2j/.cargo/config.toml b/y2j/.cargo/config.toml deleted file mode 100644 index af6c07317..000000000 --- a/y2j/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[target.x86_64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] -[target.aarch64-pc-windows-msvc] -rustflags = ["-C", "target-feature=+crt-static"] \ No newline at end of file From 0f79ebfbf66e73d58b12670b2f47d7ff7dc7e975 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL HE/HIM) (from Dev Box)" Date: Mon, 8 Jul 2024 15:38:51 -0700 Subject: [PATCH 3/3] move cratesio definition to env var --- .cargo/config.toml | 1 - build.ps1 | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 53507e627..016d5f408 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -4,7 +4,6 @@ registry-auth = true [registries] powershell = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" } -cratesio = { index = "sparse+https://index.crates.io/"} [registry] global-credential-providers = ["cargo:token"] diff --git a/build.ps1 b/build.ps1 index b944ab393..19456183b 100644 --- a/build.ps1 +++ b/build.ps1 @@ -175,10 +175,12 @@ if (!$SkipBuild) { if (!$UseCFS) { # this will override the config.toml Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'" - ${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'cratesio' + ${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO' + $env:CARGO_REGISTRIES_CRATESIO_INDEX = 'sparse+https://index.crates.io/' } else { Write-Host "Using CFS for cargo source replacement" ${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null + $env:CARGO_REGISTRIES_CRATESIO_INDEX = $null } # make sure dependencies are built first so clippy runs correctly