@@ -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
}
@@ -171,6 +174,39 @@ if ($null -ne (Get-Command msrustup -CommandType Application -ErrorAction Ignore
171
174
if ($null -ne $packageType ) {
172
175
$SkipBuild = $true
173
176
} 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
+
174
210
# # Test if Rust is installed
175
211
if (! $usingADO -and ! (Get-Command ' cargo' - ErrorAction Ignore)) {
176
212
Write-Verbose - Verbose " Rust not found, installing..."
@@ -229,7 +265,11 @@ if ($null -ne $packageType) {
229
265
# # Test if tree-sitter is installed
230
266
if ($null -eq (Get-Command tree- sitter - ErrorAction Ignore)) {
231
267
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
+ }
233
273
if ($LASTEXITCODE -ne 0 ) {
234
274
throw " Failed to install tree-sitter-cli"
235
275
}
@@ -290,39 +330,6 @@ if (!$SkipBuild) {
290
330
}
291
331
New-Item - ItemType Directory $target - ErrorAction Ignore > $null
292
332
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
-
326
333
# make sure dependencies are built first so clippy runs correctly
327
334
$windows_projects = @ (" pal" , " registry_lib" , " registry" , " reboot_pending" , " wmi-adapter" , " configurations/windows" , ' extensions/appx' )
328
335
$macOS_projects = @ (" resources/brew" )
@@ -380,7 +387,11 @@ if (!$SkipBuild) {
380
387
else {
381
388
if ($Audit ) {
382
389
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
+ }
384
395
}
385
396
386
397
cargo audit fix
@@ -413,7 +424,11 @@ if (!$SkipBuild) {
413
424
else {
414
425
if ($Audit ) {
415
426
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
+ }
417
432
}
418
433
419
434
cargo audit fix
0 commit comments