Skip to content

Switch bpf2c to pull its own nuget dependencies #4502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Alan-Jowett
Copy link
Member

Description

Resolves: #4379
This pull request refactors the build process for the bpf2c tool by transitioning from manual package imports to NuGet-based package management, simplifying dependency handling. It also introduces conditional build steps for kernel-mode configurations and removes unused parameters from the script.

Build process improvements:

  • tools/bpf2c/templates/kernel_mode_bpf2c.vcxproj: Replaced manual package imports with PackageReference elements for NuGet-based dependency management, including conditional references for host and target platforms. Added a property to disable NuGet package resolution during build.
  • tools/bpf2c/templates/user_mode_bpf2c.vcxproj: Removed manual package imports, aligning the user-mode project template with the kernel-mode template's streamlined dependency management approach.

Script enhancements:

Testing

CI/CD

Documentation

No.

Installation

No.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Refactors the bpf2c build to use NuGet package management, adds conditional restore for kernel-mode builds, and removes an unused script parameter.

  • Replace manual SDK/WDK imports with PackageReference in kernel-mode project
  • Remove manual imports in user-mode project (needs matching PackageReference updates)
  • Add conditional msbuild /t:restore step and drop $Packages param in the PowerShell script

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tools/bpf2c/templates/user_mode_bpf2c.vcxproj Removed manual SDK/WDK imports (needs new NuGet references)
tools/bpf2c/templates/kernel_mode_bpf2c.vcxproj Added ResolveNuGetPackages property and PackageReference items
tools/bpf2c/Convert-BpfToNative.ps1.template Removed $Packages param and inserted conditional restore
Comments suppressed due to low confidence (4)

tools/bpf2c/Convert-BpfToNative.ps1.template:128

  • [nitpick] The new conditional $KernelMode restore path isn't covered by existing tests. Consider adding a unit or integration test to verify that msbuild /t:restore is only invoked when $KernelMode is true.
if ($KernelMode) {

tools/bpf2c/templates/user_mode_bpf2c.vcxproj:51

  • The user-mode project no longer has any PackageReference entries after removing manual imports. You should add an <ItemGroup> with matching PackageReference elements (e.g., for Microsoft.Windows.SDK.CPP and Microsoft.Windows.WDK) to restore dependencies via NuGet.
  <PropertyGroup Label="Globals">

tools/bpf2c/Convert-BpfToNative.ps1.template:132

  • The trailing backslashes inside "$BinDir\" and "$OutDir\" will escape the closing quote in PowerShell. Consider doubling the backslashes ("$BinDir\\") or using single quotes to avoid unintended escape behavior.
msbuild /p:BinDir="$BinDir\" /p:OutDir="$OutDir\" /p:IncludeDir="$IncludeDir" /p:Configuration="$Configuration" /p:Platform="$Platform" /p:FileName="$FileName" /p:AdditionalOptions="$AdditionalOptions" /p:ResourceFile="$ResourceFile" $ProjectFile

tools/bpf2c/Convert-BpfToNative.ps1.template:132

  • The variable $IncludeDir is passed to MSBuild but is not defined or set in the script parameters. Ensure $IncludeDir is declared or removed if unnecessary.
msbuild /p:BinDir="$BinDir\" /p:OutDir="$OutDir\" /p:IncludeDir="$IncludeDir" /p:Configuration="$Configuration" /p:Platform="$Platform" /p:FileName="$FileName" /p:AdditionalOptions="$AdditionalOptions" /p:ResourceFile="$ResourceFile" $ProjectFile

Signed-off-by: Alan Jowett <alanjo@microsoft.com>
Signed-off-by: Alan Jowett <alanjo@microsoft.com>
@saxena-anurag saxena-anurag added this pull request to the merge queue Jul 8, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 8, 2025
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.

BPF2C cannot build when project references are used
3 participants