Cargo build SDK: MSRustup scenario fixes#673
Open
wheelv5 wants to merge 1 commit into
Open
Conversation
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.
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SkipPublicRustUpInstallallows for control over the public Rust toolchain install: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
MsRustupTargetsallows projects to specify which target triples to install (as a semicolon-separated list), to support cross-compilation (by--targetarguments tomsrustup 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:
MSRUSTUP_FILEfor authentication. It does acceptMSRUSTUP_PAT, so CargoTask's existing logic for settingMSRUSTUP_PATfromMSRUSTUP_FILEis 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 propertyCargoProfilecauses 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.