Skip to content

Fix Rust SDK NuGet source configuration - #1049

Merged
Baiju Meswani (baijumeswani) merged 7 commits into
microsoft:mainfrom
loganrosen:lrosen-microsoft-fix-rust-nuget-config
Sep 4, 2026
Merged

Fix Rust SDK NuGet source configuration#1049
Baiju Meswani (baijumeswani) merged 7 commits into
microsoft:mainfrom
loganrosen:lrosen-microsoft-fix-rust-nuget-config

Conversation

@loganrosen

@loganrosen Logan Rosen (loganrosen) commented Aug 27, 2026

Copy link
Copy Markdown
Member

Why

The Rust SDK build script downloaded native packages directly from hard-coded public NuGet feeds. That prevented developers behind authenticated feeds, mirrors, or enterprise proxies from using their existing NuGet.Config and credential-provider setup.

What changed

This PR brings Rust native-package acquisition in line with the JavaScript SDK while keeping direct HTTPS downloads as the default.

Mode Behavior
http Downloads from configurable HTTPS v3 feeds without invoking external tools.
dotnet Restores exact package versions with dotnet restore, honoring NuGet.Config and standard authentication.
nuget Restores exact package versions with the NuGet CLI, also honoring NuGet.Config and standard authentication.

The build script now supports feed, config-file, and executable overrides; redacts sensitive URLs; prevents HTTPS downgrade redirects; and preserves the existing warning-plus-runtime-fallback behavior when acquisition fails. Native packages are staged through isolated temporary directories, and version/source transitions invalidate stale cache state before reuse. Cargo also watches the configured NuGet.Config, so editing a failed feed or credential configuration triggers another acquisition attempt.

Validation

  • 26 focused, network-free tests covering configuration, command construction, URL redaction, package discovery, cache transitions, archive rejection, and isolated staging
  • Rust formatting and Clippy with warnings denied
  • Published-crate content verification for the shared build-support and extraction modules
  • Live dotnet and nuget restores through the machine proxy-only NuGet configuration

Follow-up

#1050 tracks independent SHA-512 pins for additional HTTP-mode package-integrity hardening.

Closes #1033

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings August 27, 2026 23:06
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the MSFT-AIP Team on Vercel.

A member of the Team first needs to authorize it.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: 2 High severity

New issues introduced by this change (2)
Severity Finding
High severity sdk_v2/​rust/​build.rs — This guard checks the shared output directory rather than what the current archive extracted. When…
High severity sdk_v2/​rust/​build_support.rs — URL schemes are case-insensitive, and feed validation accepts mixed-case HTTPS, but this scanner…
What changed in this PR

Adds configurable native NuGet acquisition for the Rust SDK, including authenticated tooling-based restores.

Changes:

  • Adds HTTP, dotnet, and nuget acquisition modes.
  • Adds URL redaction and version-marker cache handling.
  • Documents and tests the new configuration.
File Description
sdk_v2/​rust/​build.rs Integrates restore modes, staging, and caching.
sdk_v2/​rust/​build_support.rs Adds shared configuration and restore helpers.
sdk_v2/​rust/​tests/​build_support_test.rs Tests configuration, arguments, redaction, and caching.
sdk_v2/​rust/​README.md Documents acquisition modes and variables.
sdk_v2/​rust/​Cargo.toml Includes build support in published crates.
Suppressed comments (1)

sdk_v2/rust/build.rs:362

  • The destination may already contain this filename with a mismatched/absent marker. If the restored package contains other native files but not its expected binary, this check sees the stale destination, writes the requested version marker, and permanently treats the old binary as current. Verify that files itself contains pkg.expected_file before staging and recording the marker.
    if out_dir.join(&pkg.expected_file).exists() {
        build_support::record_package_version(out_dir, &pkg.expected_file, &pkg.version)

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sdk_v2/rust/build.rs Outdated
Comment thread sdk_v2/rust/build_support.rs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity sdk_v2/​rust/​build.rs — Each feed attempt still extracts every matching native library directly into the shared output…
Issues resolved since last review (2)
Severity Finding
High severity sdk_v2/​rust/​build_support.rs — URL schemes are case-insensitive, and feed validation accepts mixed-case HTTPS, but this scanner… View resolved comment
High severity sdk_v2/​rust/​build.rs — This guard checks the shared output directory rather than what the current archive extracted. When… View resolved comment
Suppressed comments (1)

sdk_v2/rust/build.rs:361

  • A package can stage more than its sentinel file (the Runtime package optionally includes Microsoft.Windows.AI.MachineLearning.dll), but upgrading it removes only expected_file. If the newer package omits or renames a companion, the old executable remains in the shared output directory; on Windows preload_dependencies will still load that stale WinML DLL. Track the files staged by each package/version and remove the previous package's full file set before copying the replacement (the HTTP path needs the same cleanup).
    build_support::invalidate_package(out_dir, &pkg.expected_file)?;
    for file in files {

Comment thread sdk_v2/rust/build.rs Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity sdk_v2/​rust/​build.rs — The cache markers survive the higher-priority local-binary path. For example, after a NuGet build…
Issues resolved since last review (1)
Severity Finding
High severity sdk_v2/​rust/​build.rs — Each feed attempt still extracts every matching native library directly into the shared output… View resolved comment

Comment thread sdk_v2/rust/build.rs
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: None

Issues resolved since last review (1)
Severity Finding
High severity sdk_v2/​rust/​build.rs — The cache markers survive the higher-priority local-binary path. For example, after a NuGet build… View resolved comment
Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

sdk_v2/rust/build.rs:563

  • The configured NuGet.Config itself is not registered as a Cargo input. If a restore fails and the user fixes that file (for example, updates a mirror or credentials) without changing the environment variable, Cargo considers this successful build script fresh and does not retry acquisition. Emit cargo:rerun-if-changed for config.config_file after parsing it.
        let config = build_support::read_config()
            .unwrap_or_else(|error| panic!("invalid NuGet configuration: {error}"));

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Balanced
Findings: None

@loganrosen

Copy link
Copy Markdown
Member Author

Scott McKay (@skottmckay) Baiju Meswani (@baijumeswani), could one of you please review this? It updates Rust NuGet acquisition and aligns it with the configurable/authenticated feed support from #945.

@baijumeswani

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@baijumeswani

Copy link
Copy Markdown
Collaborator

Logan Rosen (@loganrosen) could you merge main into your branch and push again? A recent fix in main is needed to get the pipelines green.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@loganrosen

Copy link
Copy Markdown
Member Author

Could you merge main into your branch and push again?

Baiju Meswani (@baijumeswani) Done. Merged main and pushed commit de41674a.

@baijumeswani

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@baijumeswani
Baiju Meswani (baijumeswani) merged commit a1fc3c3 into microsoft:main Sep 4, 2026
46 of 49 checks passed
@loganrosen
Logan Rosen (loganrosen) deleted the lrosen-microsoft-fix-rust-nuget-config branch September 4, 2026 14:44
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.

[Bug] Rust SDK ignores NuGet.Config and hard-codes public NuGet feeds

3 participants