@@ -15,23 +15,26 @@ param(
15
15
[switch ]$GetPackageVersion ,
16
16
[switch ]$SkipLinkCheck ,
17
17
[switch ]$UseX64MakeAppx ,
18
- [switch ]$UseCratesIO ,
18
+ [switch ]$UseCFS ,
19
19
[switch ]$UpdateLockFile ,
20
20
[switch ]$Audit ,
21
21
[switch ]$UseCFSAuth ,
22
22
[switch ]$Clean ,
23
23
[switch ]$Verbose
24
24
)
25
25
26
- $env: RUSTC_LOG = $null
27
- $env: RUSTFLAGS = ' -Dwarnings'
28
- $usingADO = ($null -ne $env: TF_BUILD )
29
-
30
26
trap {
31
27
Write-Error " An error occurred: $ ( $_ | Out-String ) "
32
28
exit 1
33
29
}
34
30
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
+
35
38
if ($Verbose ) {
36
39
$env: RUSTC_LOG = ' rustc_codegen_ssa::back::link=info'
37
40
}
@@ -177,6 +180,39 @@ if ($null -ne (Get-Command msrustup -CommandType Application -ErrorAction Ignore
177
180
if ($null -ne $packageType ) {
178
181
$SkipBuild = $true
179
182
} else {
183
+ if ($UseCFS ) {
184
+ Write-Host " Using CFS for cargo source replacement"
185
+ ${env: CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
186
+ $env: CARGO_REGISTRIES_CRATESIO_INDEX = $null
187
+
188
+ if ($UseCFSAuth ) {
189
+ if ($null -eq (Get-Command ' az' - ErrorAction Ignore)) {
190
+ throw " Azure CLI not found"
191
+ }
192
+
193
+ if ($null -ne (Get-Command az - ErrorAction Ignore)) {
194
+ Write-Host " Getting token"
195
+ $accessToken = az account get-access - token -- query accessToken -- resource 499b84ac- 1321 - 427f - aa17- 267ca6975798 - o tsv
196
+ if ($LASTEXITCODE -ne 0 ) {
197
+ Write-Warning " Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
198
+ } else {
199
+ $header = " Bearer $accessToken "
200
+ $env: CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
201
+ $env: CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = ' cargo:token'
202
+ $env: CARGO_REGISTRIES_POWERSHELL_INDEX = " sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/"
203
+ }
204
+ }
205
+ else {
206
+ Write-Warning " Azure CLI not found, proceeding with anonymous access."
207
+ }
208
+ }
209
+ } else {
210
+ # this will override the config.toml
211
+ Write-Host " Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
212
+ ${env: CARGO_SOURCE_crates-io_REPLACE_WITH} = ' CRATESIO'
213
+ $env: CARGO_REGISTRIES_CRATESIO_INDEX = ' sparse+https://index.crates.io/'
214
+ }
215
+
180
216
# # Test if Rust is installed
181
217
if (! $usingADO -and ! (Get-Command ' cargo' - ErrorAction Ignore)) {
182
218
Write-Verbose - Verbose " Rust not found, installing..."
@@ -235,7 +271,11 @@ if ($null -ne $packageType) {
235
271
# # Test if tree-sitter is installed
236
272
if ($null -eq (Get-Command tree- sitter - ErrorAction Ignore)) {
237
273
Write-Verbose - Verbose " tree-sitter not found, installing..."
238
- cargo install tree- sitter- cli -- config .cargo/ config.toml
274
+ if ($UseCFS ) {
275
+ cargo install tree- sitter- cli -- config .cargo/ config.toml
276
+ } else {
277
+ cargo install tree- sitter- cli
278
+ }
239
279
if ($LASTEXITCODE -ne 0 ) {
240
280
throw " Failed to install tree-sitter-cli"
241
281
}
@@ -296,39 +336,6 @@ if (!$SkipBuild) {
296
336
}
297
337
New-Item - ItemType Directory $target - ErrorAction Ignore > $null
298
338
299
- if ($UseCratesIO ) {
300
- # this will override the config.toml
301
- Write-Host " Setting CARGO_SOURCE_crates-io_REPLACE_WITH to 'crates-io'"
302
- ${env: CARGO_SOURCE_crates-io_REPLACE_WITH} = ' CRATESIO'
303
- $env: CARGO_REGISTRIES_CRATESIO_INDEX = ' sparse+https://index.crates.io/'
304
- } else {
305
- Write-Host " Using CFS for cargo source replacement"
306
- ${env: CARGO_SOURCE_crates-io_REPLACE_WITH} = $null
307
- $env: CARGO_REGISTRIES_CRATESIO_INDEX = $null
308
-
309
- if ($UseCFSAuth ) {
310
- if ($null -eq (Get-Command ' az' - ErrorAction Ignore)) {
311
- throw " Azure CLI not found"
312
- }
313
-
314
- if ($null -ne (Get-Command az - ErrorAction Ignore)) {
315
- Write-Host " Getting token"
316
- $accessToken = az account get-access - token -- query accessToken -- resource 499b84ac- 1321 - 427f - aa17- 267ca6975798 - o tsv
317
- if ($LASTEXITCODE -ne 0 ) {
318
- Write-Warning " Failed to get access token, use 'az login' first, or use '-useCratesIO' to use crates.io. Proceeding with anonymous access."
319
- } else {
320
- $header = " Bearer $accessToken "
321
- $env: CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
322
- $env: CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = ' cargo:token'
323
- $env: CARGO_REGISTRIES_POWERSHELL_INDEX = " sparse+https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell~force-auth/Cargo/index/"
324
- }
325
- }
326
- else {
327
- Write-Warning " Azure CLI not found, proceeding with anonymous access."
328
- }
329
- }
330
- }
331
-
332
339
# make sure dependencies are built first so clippy runs correctly
333
340
$windows_projects = @ (" pal" , " registry_lib" , " registry" , " reboot_pending" , " wmi-adapter" , " configurations/windows" , " extensions/appx" , " extensions/powershell/secret" )
334
341
$macOS_projects = @ (" resources/brew" , " extensions/powershell/secret" )
@@ -386,7 +393,11 @@ if (!$SkipBuild) {
386
393
else {
387
394
if ($Audit ) {
388
395
if ($null -eq (Get-Command cargo- audit - ErrorAction Ignore)) {
389
- cargo install cargo- audit -- features= fix -- config .cargo/ config.toml
396
+ if ($UseCFS ) {
397
+ cargo install cargo- audit -- features= fix -- config .cargo/ config.toml
398
+ } else {
399
+ cargo install cargo- audit -- features= fix
400
+ }
390
401
}
391
402
392
403
cargo audit fix
@@ -419,7 +430,11 @@ if (!$SkipBuild) {
419
430
else {
420
431
if ($Audit ) {
421
432
if ($null -eq (Get-Command cargo- audit - ErrorAction Ignore)) {
422
- cargo install cargo- audit -- features= fix -- config .cargo/ config.toml
433
+ if ($UseCFS ) {
434
+ cargo install cargo- audit -- features= fix -- config .cargo/ config.toml
435
+ } else {
436
+ cargo install cargo- audit -- features= fix
437
+ }
423
438
}
424
439
425
440
cargo audit fix
0 commit comments