@@ -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-
3026trap {
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+
3538if ($Verbose ) {
3639 $env: RUSTC_LOG = ' rustc_codegen_ssa::back::link=info'
3740}
@@ -177,6 +180,39 @@ if ($null -ne (Get-Command msrustup -CommandType Application -ErrorAction Ignore
177180if ($null -ne $packageType ) {
178181 $SkipBuild = $true
179182} 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+
180216 # # Test if Rust is installed
181217 if (! $usingADO -and ! (Get-Command ' cargo' - ErrorAction Ignore)) {
182218 Write-Verbose - Verbose " Rust not found, installing..."
@@ -235,7 +271,11 @@ if ($null -ne $packageType) {
235271 # # Test if tree-sitter is installed
236272 if ($null -eq (Get-Command tree- sitter - ErrorAction Ignore)) {
237273 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+ }
239279 if ($LASTEXITCODE -ne 0 ) {
240280 throw " Failed to install tree-sitter-cli"
241281 }
@@ -296,39 +336,6 @@ if (!$SkipBuild) {
296336 }
297337 New-Item - ItemType Directory $target - ErrorAction Ignore > $null
298338
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-
332339 # make sure dependencies are built first so clippy runs correctly
333340 $windows_projects = @ (" pal" , " registry_lib" , " registry" , " reboot_pending" , " wmi-adapter" , " configurations/windows" , " extensions/appx" , " extensions/powershell/secret" )
334341 $macOS_projects = @ (" resources/brew" , " extensions/powershell/secret" )
@@ -386,7 +393,11 @@ if (!$SkipBuild) {
386393 else {
387394 if ($Audit ) {
388395 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+ }
390401 }
391402
392403 cargo audit fix
@@ -419,7 +430,11 @@ if (!$SkipBuild) {
419430 else {
420431 if ($Audit ) {
421432 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+ }
423438 }
424439
425440 cargo audit fix
0 commit comments