Skip to content

Commit 1f01635

Browse files
authored
Merge pull request #1076 from SteveL-MSFT/default-cratesio
Default build to crates.io
2 parents 86c3ef6 + 2a82283 commit 1f01635

File tree

1 file changed

+56
-41
lines changed

1 file changed

+56
-41
lines changed

build.ps1

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ param(
1515
[switch]$GetPackageVersion,
1616
[switch]$SkipLinkCheck,
1717
[switch]$UseX64MakeAppx,
18-
[switch]$UseCratesIO,
18+
[switch]$UseCFS,
1919
[switch]$UpdateLockFile,
2020
[switch]$Audit,
2121
[switch]$UseCFSAuth,
2222
[switch]$Clean,
2323
[switch]$Verbose
2424
)
2525

26-
$env:RUSTC_LOG=$null
27-
$env:RUSTFLAGS='-Dwarnings'
28-
$usingADO = ($null -ne $env:TF_BUILD)
29-
3026
trap {
3127
Write-Error "An error occurred: $($_ | Out-String)"
3228
exit 1
3329
}
3430

31+
$env:RUSTC_LOG=$null
32+
$env:RUSTFLAGS='-Dwarnings'
33+
$usingADO = ($null -ne $env:TF_BUILD)
34+
if ($usingADO -or $UseCFSAuth) {
35+
$UseCFS = $true
36+
}
37+
3538
if ($Verbose) {
3639
$env:RUSTC_LOG='rustc_codegen_ssa::back::link=info'
3740
}
@@ -171,6 +174,39 @@ if ($null -ne (Get-Command msrustup -CommandType Application -ErrorAction Ignore
171174
if ($null -ne $packageType) {
172175
$SkipBuild = $true
173176
} else {
177+
if ($UseCFS) {
178+
Write-Host "Using CFS for cargo source replacement"
179+
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
180+
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
181+
182+
if ($UseCFSAuth) {
183+
if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) {
184+
throw "Azure CLI not found"
185+
}
186+
187+
if ($null -ne (Get-Command az -ErrorAction Ignore)) {
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+
$env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/"
197+
}
198+
}
199+
else {
200+
Write-Warning "Azure CLI not found, proceeding with anonymous access."
201+
}
202+
}
203+
} else {
204+
# this will override the config.toml
205+
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
206+
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
207+
$env:CARGO_REGISTRIES_CRATESIO_INDEX = 'sparse+https://index.crates.io/'
208+
}
209+
174210
## Test if Rust is installed
175211
if (!$usingADO -and !(Get-Command 'cargo' -ErrorAction Ignore)) {
176212
Write-Verbose -Verbose "Rust not found, installing..."
@@ -229,7 +265,11 @@ if ($null -ne $packageType) {
229265
## Test if tree-sitter is installed
230266
if ($null -eq (Get-Command tree-sitter -ErrorAction Ignore)) {
231267
Write-Verbose -Verbose "tree-sitter not found, installing..."
232-
cargo install tree-sitter-cli --config .cargo/config.toml
268+
if ($UseCFS) {
269+
cargo install tree-sitter-cli --config .cargo/config.toml
270+
} else {
271+
cargo install tree-sitter-cli
272+
}
233273
if ($LASTEXITCODE -ne 0) {
234274
throw "Failed to install tree-sitter-cli"
235275
}
@@ -290,39 +330,6 @@ if (!$SkipBuild) {
290330
}
291331
New-Item -ItemType Directory $target -ErrorAction Ignore > $null
292332

293-
if ($UseCratesIO) {
294-
# this will override the config.toml
295-
Write-Host "Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
296-
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = 'CRATESIO'
297-
$env:CARGO_REGISTRIES_CRATESIO_INDEX = 'sparse+https://index.crates.io/'
298-
} else {
299-
Write-Host "Using CFS for cargo source replacement"
300-
${env:CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
301-
$env:CARGO_REGISTRIES_CRATESIO_INDEX = $null
302-
303-
if ($UseCFSAuth) {
304-
if ($null -eq (Get-Command 'az' -ErrorAction Ignore)) {
305-
throw "Azure CLI not found"
306-
}
307-
308-
if ($null -ne (Get-Command az -ErrorAction Ignore)) {
309-
Write-Host "Getting token"
310-
$accessToken = az account get-access-token --query accessToken --resource 499b84ac-1321-427f-aa17-267ca6975798 -o tsv
311-
if ($LASTEXITCODE -ne 0) {
312-
Write-Warning "Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
313-
} else {
314-
$header = "Bearer $accessToken"
315-
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
316-
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
317-
$env:CARGO_REGISTRIES_POWERSHELL_INDEX = "sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/"
318-
}
319-
}
320-
else {
321-
Write-Warning "Azure CLI not found, proceeding with anonymous access."
322-
}
323-
}
324-
}
325-
326333
# make sure dependencies are built first so clippy runs correctly
327334
$windows_projects = @("pal", "registry_lib", "registry", "reboot_pending", "wmi-adapter", "configurations/windows", 'extensions/appx')
328335
$macOS_projects = @("resources/brew")
@@ -380,7 +387,11 @@ if (!$SkipBuild) {
380387
else {
381388
if ($Audit) {
382389
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
383-
cargo install cargo-audit --features=fix --config .cargo/config.toml
390+
if ($UseCFS) {
391+
cargo install cargo-audit --features=fix --config .cargo/config.toml
392+
} else {
393+
cargo install cargo-audit --features=fix
394+
}
384395
}
385396

386397
cargo audit fix
@@ -413,7 +424,11 @@ if (!$SkipBuild) {
413424
else {
414425
if ($Audit) {
415426
if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) {
416-
cargo install cargo-audit --features=fix --config .cargo/config.toml
427+
if ($UseCFS) {
428+
cargo install cargo-audit --features=fix --config .cargo/config.toml
429+
} else {
430+
cargo install cargo-audit --features=fix
431+
}
417432
}
418433

419434
cargo audit fix

0 commit comments

Comments
 (0)