From 2e37be2160f2dc65a4cfa8a0f16ab6e9165f2c55 Mon Sep 17 00:00:00 2001 From: Connor Peet Date: Sun, 8 Oct 2023 17:18:22 -0700 Subject: [PATCH] Adopt Terrapin / msrustup for the CLI (#188732) * cli: use terrapin for cli builds * update rust to 1.70 to allow ado artifacts feed on windows * apparently manaul cargo login is required * use msrustup * rustup is no longer user * update to 1.73 * add rust oss install --- .../cli/install-rust-posix.yml | 19 ++++++++++++++++--- .../cli/install-rust-win32.yml | 19 ++++++++++++++++--- build/azure-pipelines/product-build-pr.yml | 2 ++ build/azure-pipelines/product-build.yml | 6 ++++++ cli/src/auth.rs | 6 +++--- cli/src/bin/code/legacy_args.rs | 10 +++++----- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/build/azure-pipelines/cli/install-rust-posix.yml b/build/azure-pipelines/cli/install-rust-posix.yml index d6022a44f7a..00e3ecbdc51 100644 --- a/build/azure-pipelines/cli/install-rust-posix.yml +++ b/build/azure-pipelines/cli/install-rust-posix.yml @@ -1,7 +1,7 @@ parameters: - name: channel type: string - default: 1.71.0 + default: 1.73.0 - name: targets default: [] type: object @@ -9,13 +9,25 @@ parameters: # Todo: use 1ES pipeline once extension is installed in ADO steps: + - task: RustInstaller@1 + inputs: + rustVersion: ms-${{ parameters.channel }} + cratesIoFeedOverride: $(CARGO_REGISTRY) + additionalTargets: ${{ join(' ', parameters.targets) }} + toolchainFeed: https://pkgs.dev.azure.com/monacotools/Monaco/_packaging/vscode/nuget/v3/index.json + default: true + addToPath: true + displayName: Install MSFT Rust + condition: and(succeeded(), ne(variables['CARGO_REGISTRY'], 'none')) + - script: | set -e curl https://sh.rustup.rs -sSf | sh -s -- -y --profile minimal --default-toolchain $RUSTUP_TOOLCHAIN echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin" env: RUSTUP_TOOLCHAIN: ${{ parameters.channel }} - displayName: "Install Rust" + displayName: Install OSS Rust + condition: and(succeeded(), eq(variables['CARGO_REGISTRY'], 'none')) - script: | set -e @@ -24,14 +36,15 @@ steps: env: RUSTUP_TOOLCHAIN: ${{ parameters.channel }} displayName: "Set Rust version" + condition: and(succeeded(), eq(variables['CARGO_REGISTRY'], 'none')) - ${{ each target in parameters.targets }}: - script: rustup target add ${{ target }} displayName: "Adding Rust target '${{ target }}'" + condition: and(succeeded(), eq(variables['CARGO_REGISTRY'], 'none')) - script: | set -e rustc --version cargo --version - rustup --version displayName: "Check Rust versions" diff --git a/build/azure-pipelines/cli/install-rust-win32.yml b/build/azure-pipelines/cli/install-rust-win32.yml index 373c41dd95f..3c88d9adc86 100644 --- a/build/azure-pipelines/cli/install-rust-win32.yml +++ b/build/azure-pipelines/cli/install-rust-win32.yml @@ -1,7 +1,7 @@ parameters: - name: channel type: string - default: 1.71.0 + default: 1.73.0 - name: targets default: [] type: object @@ -9,6 +9,17 @@ parameters: # Todo: use 1ES pipeline once extension is installed in ADO steps: + - task: RustInstaller@1 + inputs: + rustVersion: ms-${{ parameters.channel }} + cratesIoFeedOverride: $(CARGO_REGISTRY) + additionalTargets: ${{ join(' ', parameters.targets) }} + toolchainFeed: https://pkgs.dev.azure.com/monacotools/Monaco/_packaging/vscode/nuget/v3/index.json + default: true + addToPath: true + displayName: Install MSFT Rust + condition: and(succeeded(), ne(variables['CARGO_REGISTRY'], 'none')) + - powershell: | . build/azure-pipelines/win32/exec.ps1 Invoke-WebRequest -Uri "https://win.rustup.rs" -Outfile $(Build.ArtifactStagingDirectory)/rustup-init.exe @@ -16,7 +27,8 @@ steps: echo "##vso[task.prependpath]$env:USERPROFILE\.cargo\bin" env: RUSTUP_TOOLCHAIN: ${{ parameters.channel }} - displayName: "Install Rust" + displayName: Install OSS Rust + condition: and(succeeded(), eq(variables['CARGO_REGISTRY'], 'none')) - powershell: | . build/azure-pipelines/win32/exec.ps1 @@ -25,14 +37,15 @@ steps: env: RUSTUP_TOOLCHAIN: ${{ parameters.channel }} displayName: "Set Rust version" + condition: and(succeeded(), eq(variables['CARGO_REGISTRY'], 'none')) - ${{ each target in parameters.targets }}: - script: rustup target add ${{ target }} displayName: "Adding Rust target '${{ target }}'" + condition: and(succeeded(), eq(variables['CARGO_REGISTRY'], 'none')) - powershell: | . build/azure-pipelines/win32/exec.ps1 exec { rustc --version } exec { cargo --version } - exec { rustup --version } displayName: "Check Rust versions" diff --git a/build/azure-pipelines/product-build-pr.yml b/build/azure-pipelines/product-build-pr.yml index 90f85c5817f..b5036070730 100644 --- a/build/azure-pipelines/product-build-pr.yml +++ b/build/azure-pipelines/product-build-pr.yml @@ -13,6 +13,8 @@ variables: value: true - name: NPM_REGISTRY value: "none" + - name: CARGO_REGISTRY + value: "none" - name: VSCODE_CIBUILD value: ${{ in(variables['Build.Reason'], 'IndividualCI', 'BatchedCI') }} - name: VSCODE_QUALITY diff --git a/build/azure-pipelines/product-build.yml b/build/azure-pipelines/product-build.yml index 2d4ad8aa84a..383fa1576bc 100644 --- a/build/azure-pipelines/product-build.yml +++ b/build/azure-pipelines/product-build.yml @@ -24,6 +24,10 @@ parameters: displayName: "Custom NPM Registry" type: string default: 'https://pkgs.dev.azure.com/monacotools/Monaco/_packaging/vscode/npm/registry/' + - name: CARGO_REGISTRY + displayName: "Custom Cargo Registry" + type: string + default: 'sparse+https://pkgs.dev.azure.com/monacotools/Monaco/_packaging/vscode/Cargo/index/' - name: VSCODE_BUILD_WIN32 displayName: "🎯 Windows x64" type: boolean @@ -98,6 +102,8 @@ variables: value: ${{ ne(variables['Build.Repository.Uri'], 'https://github.com/microsoft/vscode.git') }} - name: NPM_REGISTRY value: ${{ parameters.NPM_REGISTRY }} + - name: CARGO_REGISTRY + value: ${{ parameters.CARGO_REGISTRY }} - name: VSCODE_QUALITY value: ${{ parameters.VSCODE_QUALITY }} - name: VSCODE_BUILD_STAGE_WINDOWS diff --git a/cli/src/auth.rs b/cli/src/auth.rs index 5a62753fae5..0214b335247 100644 --- a/cli/src/auth.rs +++ b/cli/src/auth.rs @@ -622,11 +622,11 @@ impl Auth { return Ok(StoredCredential::from_response(body, provider)); } - return Err(Auth::handle_grant_error( + Err(Auth::handle_grant_error( provider.grant_uri(), status_code, body, - )); + )) } /// GH doesn't have a refresh token, but does limit to the 10 most recently @@ -772,7 +772,7 @@ impl Auth { error!(this.log, "failed to keep token alive: {:?}", e); return Err(e.into()); } - Err(e) if matches!(e, AnyError::RefreshTokenNotAvailableError(_)) => { + Err(AnyError::RefreshTokenNotAvailableError(_)) => { return Ok(()); } Err(e) => { diff --git a/cli/src/bin/code/legacy_args.rs b/cli/src/bin/code/legacy_args.rs index 808b4aa30a8..6a533426608 100644 --- a/cli/src/bin/code/legacy_args.rs +++ b/cli/src/bin/code/legacy_args.rs @@ -118,7 +118,7 @@ mod tests { "themes", "--show-versions", ]; - let cli = try_parse_legacy(args.into_iter()).unwrap(); + let cli = try_parse_legacy(args).unwrap(); if let Some(Commands::Extension(extension_args)) = cli.subcommand { if let ExtensionSubcommand::List(list_args) = extension_args.subcommand { @@ -145,7 +145,7 @@ mod tests { "--pre-release", "--force", ]; - let cli = try_parse_legacy(args.into_iter()).unwrap(); + let cli = try_parse_legacy(args).unwrap(); if let Some(Commands::Extension(extension_args)) = cli.subcommand { if let ExtensionSubcommand::Install(install_args) = extension_args.subcommand { @@ -169,7 +169,7 @@ mod tests { #[test] fn test_parses_uninstall_extension() { let args = vec!["code", "--uninstall-extension", "connor4312.codesong"]; - let cli = try_parse_legacy(args.into_iter()).unwrap(); + let cli = try_parse_legacy(args).unwrap(); if let Some(Commands::Extension(extension_args)) = cli.subcommand { if let ExtensionSubcommand::Uninstall(uninstall_args) = extension_args.subcommand { @@ -196,7 +196,7 @@ mod tests { "--extensions-dir", "bar", ]; - let cli = try_parse_legacy(args.into_iter()).unwrap(); + let cli = try_parse_legacy(args).unwrap(); if let Some(Commands::Extension(extension_args)) = cli.subcommand { assert_eq!( @@ -223,7 +223,7 @@ mod tests { #[test] fn test_status() { let args = vec!["code", "--status"]; - let cli = try_parse_legacy(args.into_iter()).unwrap(); + let cli = try_parse_legacy(args).unwrap(); if let Some(Commands::Status) = cli.subcommand { // no-op