Skip to content

Cargo build SDK: MSRustup scenario fixes#673

Open
wheelv5 wants to merge 1 commit into
microsoft:mainfrom
wheelv5:u/wheelv5/msrustup_usage_fixes
Open

Cargo build SDK: MSRustup scenario fixes#673
wheelv5 wants to merge 1 commit into
microsoft:mainfrom
wheelv5:u/wheelv5/msrustup_usage_fixes

Conversation

@wheelv5

@wheelv5 wheelv5 commented Jun 17, 2026

Copy link
Copy Markdown

Targeted fixes to MSRustup usage scenarios, avoiding large-scale refactoring.

Additional toolchain install configuration for MSRustup scenarios

Auto-skip the public Rust toolchain install

While the public Rust toolchain and MS-internal MSRustup can coexist, build scenarios using MSRustup will only use MSRustup. Previously, even when the SDK detected MSRustup usage, it still attempted to install the public Rust toolchain before MSRustup, which would fail in network-isolated build environments.

New tri-state MSBuild property SkipPublicRustUpInstall allows for control over the public Rust toolchain install:

  • (default) => Auto-detect; skip the public Rust toolchain install when MSRustup use is detected.
  • true => Always skip the public install (explicit opt-in for edge cases).
  • false => Always run the public install, restoring original behavior.

This is the only change which is not backward-compatible. However, the previous behavior was in direct opposition to the use case, so the decision was to have the new default behavior match the scenario requirements, with an available configuration option to revert if needed.

Support cross-compilation

The SDK pinned the MSRustup toolchain install to the target triple for the host architecture. That behavior is preserved by default, but new MSBuild property MsRustupTargets allows projects to specify which target triples to install (as a semicolon-separated list), to support cross-compilation (by --target arguments to msrustup toolchain install). E.g. to support both x64/amd64 and arm64:

<MsRustupTargets>aarch64-pc-windows-msvc;x86_64-pc-windows-msvc</MsRustupTargets>

Updated MSRustup install script from v5 -> v6

The bundled install script is updated to the current upstream version:

  • The install directory path is no longer an input: the script installs to the working directory. CargoTask now creates the install directory and sets it as the working directory for the script.
  • The script no longer directly parses MSRUSTUP_FILE for authentication. It does accept MSRUSTUP_PAT, so CargoTask's existing logic for setting MSRUSTUP_PAT from MSRUSTUP_FILE is reused.

Configurable Cargo profile

The SDK forced Cargo commands in non-Debug configurations for MSRustup projects to use a profile selection of --<configurationName> (expecting e.g. --release). That behavior is preserved by default, but new MSBuild property CargoProfile causes the SDK to pass --profile <CargoProfile> to Cargo instead. This enables using custom profiles defined in Cargo.toml without the side effects from using custom Configuration names, e.g.:

<CargoProfile Condition="'$(Configuration)' == 'Release'">release-windows</CargoProfile>

Support more crate registry name variations

The authentication to crate registries for MSRustup projects leverages the environment variables CARGO_REGISTRIES_{registryName}_TOKEN. The variable naming requirement is that '-' in the registry name be converted to '_', which was missing from the conversion logic; it has now been added.

Targeted fixes to MSRustup usage scenarios, avoiding large-scale refactoring.

While the public Rust toolchain and MS-internal MSRustup can coexist, build scenarios using MSRustup will only use MSRustup. Previously, even when the SDK detected MSRustup usage, it still attempted to install the public Rust toolchain before MSRustup, which would fail in network-isolated build environments.

New tri-state MSBuild property `SkipPublicRustUpInstall` allows for control over the public Rust toolchain install:
- (default) => Auto-detect; skip the public Rust toolchain install when MSRustup use is detected.
- true => Always skip the public install (explicit opt-in for edge cases).
- false => Always run the public install, restoring original behavior.

This is the only change which is not backward-compatible. However, the previous behavior was in direct opposition to the use case, so the decision was to have the new default behavior match the scenario requirements, with an available configuration option to revert if needed.

The SDK pinned the MSRustup toolchain install to the target triple for the host architecture. That behavior is preserved by default, but new MSBuild property `MsRustupTargets` allows projects to specify which target triples to install (as a semicolon-separated list), to support cross-compilation (by `--target` arguments to `msrustup toolchain install`). E.g. to support both x64/amd64 and arm64:

   \<MsRustupTargets\>aarch64-pc-windows-msvc;x86_64-pc-windows-msvc\</MsRustupTargets\>

The bundled install script is updated to the current upstream version:
- The install directory path is no longer an input: the script installs to the working directory. CargoTask now creates the install directory and sets it as the working directory for the script.
- The script no longer directly parses `MSRUSTUP_FILE` for authentication. It does accept `MSRUSTUP_PAT`, so CargoTask's existing logic for setting `MSRUSTUP_PAT` from `MSRUSTUP_FILE` is reused.

The SDK forced Cargo commands in non-Debug configurations for MSRustup projects to use a profile selection of `--<configurationName>` (expecting e.g. `--release`). That behavior is preserved by default, but new MSBuild property `CargoProfile` causes the SDK to pass `--profile <CargoProfile>` to Cargo instead. This enables using custom profiles defined in Cargo.toml without the side effects from using custom Configuration names, e.g.:

   \<CargoProfile Condition="'$(Configuration)' == 'Release'"\>release-windows\</CargoProfile\>

The authentication to crate registries for MSRustup projects leverages the environment variables `CARGO_REGISTRIES_{registryName}_TOKEN`. The variable naming requirement is that '-' in the registry name be converted to '_', which was missing from the conversion logic; it has now been added.
@wheelv5

wheelv5 commented Jun 17, 2026

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant