Skip to content
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

Trimmable Support #522

Merged
merged 3 commits into from
Jul 30, 2024
Merged

Trimmable Support #522

merged 3 commits into from
Jul 30, 2024

Conversation

kayoub5
Copy link
Collaborator

@kayoub5 kayoub5 commented Jul 28, 2024

Resolves #517

@kayoub5
Copy link
Collaborator Author

kayoub5 commented Jul 28, 2024

@landerverhacklansweeper could you give this PR a test?

@kayoub5 kayoub5 requested a review from chmorgan July 28, 2024 14:26
Copy link

codecov bot commented Jul 28, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 81.55%. Comparing base (322e437) to head (471f965).
Report is 1 commits behind head on master.

Files Patch % Lines
SharpPcap/LibPcap/PcapDevice.cs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #522      +/-   ##
==========================================
- Coverage   82.35%   81.55%   -0.81%     
==========================================
  Files          51       51              
  Lines        2823     2824       +1     
  Branches      312      310       -2     
==========================================
- Hits         2325     2303      -22     
- Misses        383      420      +37     
+ Partials      115      101      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@chmorgan
Copy link
Collaborator

@kayoub5 anyone else that might be able to review? I'm a bit out of touch with latest .NET language features, I'm not even sure what trimmable support means.

@landerverhacklansweeper
Copy link
Contributor

@kayoub5 anyone else that might be able to review? I'm a bit out of touch with latest .NET language features, I'm not even sure what trimmable support means.

Trimmable means that any unnecessary code that is not strictly needed for the code to run can be thrown out. This makes the application a lot smaller. To figure out which code is used, the trimmer needs to build a dependency tree. It figures out which code is used, and which is not. That's why reflection is a big no-no for trimming. Since It doesn't call code directly, that code might be thrown out.
One solution is to add attributes to specify which methods you use via reflection. A better solution is to avoid reflection altogether. If you want AOT(Ahead-Of-Time) compilation, reflection is not supported.

By marking a library as trimmable, I know that I can use SharpPcap, enable trimming, and be fine.

<IsTrimmable>true</IsTrimmable>

Thank you for your efforts

@landerverhacklansweeper
Copy link
Contributor

@landerverhacklansweeper could you give this PR a test?

I've tested this with my setup and can report that it works as it should. I've taken a look at the PR, and for me it looks good although I would still include net6.0.

Many thanks for your time and effort.

@kayoub5 kayoub5 merged commit dead0f7 into master Jul 30, 2024
9 of 11 checks passed
@kayoub5 kayoub5 deleted the feature/trimmable_support branch July 30, 2024 22:01
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.

SharpPcap is not trimmable because of dependency on NativeLibrary.SetDllImportResolver
3 participants