diff --git a/.cargo/config.toml b/.cargo/config.toml index 3985801ea..016d5f408 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,9 +5,16 @@ registry-auth = true [registries] powershell = { index = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/Cargo/index/" } +[registry] +global-credential-providers = ["cargo:token"] + # Enable Control Flow Guard (needed for OneBranch's post-build analysis). [target.x86_64-pc-windows-msvc] rustflags = ["-Ccontrol-flow-guard", "-Ctarget-feature=+crt-static", "-Clink-args=/DYNAMICBASE /CETCOMPAT"] [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/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/build.ps1 b/build.ps1 index 7e32916f0..19456183b 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,17 @@ 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' + $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 $windows_projects = @("pal", "registry", "reboot_pending", "wmi-adapter") @@ -240,6 +252,7 @@ if (!$SkipBuild) { if ($LASTEXITCODE -ne 0) { $failed = $true + break } $binary = Split-Path $project -Leaf 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