Add SourceLink to native Windows DLL#4774
Conversation
Configure SourceLink for the native Windows DLL.
No warning, but there's no PDB in the output to verify. Should the PDB/symbols for the binary files be output in the artifacts too? |
I am not against, one more thing to check, how to correctly build . |
Include the PDBs for the Windows native DLLs in the build output.
Short answer is "no idea" 😄 |
|
Potentially one way to do it is to just include the symbols in the package itself via |
|
From NuGet.org symbol package constraints: Note Native projects, such as C++ projects, produce Windows PDBs instead of Portable PDBs. These are not supported by NuGet.org's symbol server. Please use Legacy Symbol Packages instead. Will look at Legacy Symbol Packages next... |
Symbols included (and found) now, and there's no warning related to SourceLink: |
I can produce opentelemetry-dotnet-instrumentation/build/Build.NuGet.Steps.cs Lines 138 to 142 in 45a3b23 - .SetOutputDirectory(NuGetArtifactsDirectory));
+ .SetOutputDirectory(NuGetArtifactsDirectory)
+ .EnableSymbols());Other packages still produce However, the contents are effectively identical because the PDBs are already included in the NuGet packages anyway: With a change like below, the PDBs are missing from both packages: - <file src="**\*" target="\" />
+ <file src="**\*.dll" target="\" />
+ <file src="**\*.dylib" target="\" />
+ <file src="**\*.so" target="\" />There doesn't appear to be a way to make Options seem to be:
I would go with 1 or 2. |
Kielek
left a comment
There was a problem hiding this comment.
I think that the symbols should be considered as a separate artifacts (and included into release artifacts).
Typically, it is not needed for normal use-cases, but can be valuable for debugging purposes.
For the same reasons zip files does not include pdb files for the managed code.
This isn't the case: |
There was a problem hiding this comment.
Pull request overview
This pull request adds SourceLink support to the native Windows DLL to address a BinSkim warning about missing SourceLink information in the PDB. The implementation configures MSVC's /SOURCELINK linker option and generates a source_link.json file during the build process that maps source file paths to their corresponding GitHub URLs.
Changes:
- Configured SourceLink for the native Windows DLL by adding an MSBuild target that generates the source_link.json file
- Updated the build process to copy PDB files alongside DLL files for both x64 and x86 architectures
- Updated the test verification file to include the newly-distributed PDB files
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/OpenTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.DLL.vcxproj | Adds SourceLink configuration, linker options, and MSBuild target to generate source_link.json from git repository information |
| build/Build.Steps.Windows.cs | Updates build script to copy both DLL and PDB files to distribution directory |
| test/IntegrationTests/BuildTests.DistributionStructure_windows.verified.txt | Updates expected file list to include PDB files for both x64 and x86 architectures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...penTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.DLL.vcxproj
Show resolved
Hide resolved
...penTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.DLL.vcxproj
Show resolved
Hide resolved
...penTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.DLL.vcxproj
Show resolved
Hide resolved
...penTelemetry.AutoInstrumentation.Native/OpenTelemetry.AutoInstrumentation.Native.DLL.vcxproj
Show resolved
Hide resolved
|
ZIP artifact sizes:
|
|
I just got around to looking at this PR. By including the PDB's we're doubling the size of the artifacts. Is that required for this to work or can we separate out the artifacts as Piotr initially mentioned? |
|
Whilst they are 2x, the absolute difference isn't much. As noted here #4774 (comment), PDBs are already included in the artifacts, so you could argue including extra ones is more correct. If you want to optimise for size, then IMHO that should be done comprehensively as a separate thing (i.e. to have separate "debug" artifacts). |
Why
Fixes BinSkim warning I saw while working on #4768:
What
Configure SourceLink for the native Windows DLL. Based on the example implemented provided here.
This appears to be an MSVC-specific feature, so there isn't a macOS or Linux equivalent as far as I'm aware.
Tests
Manually ran BinSkim on a locally compiled DLL and the warning isn't present.
Example content of the generated
source_link.jsonfile:{"documents": { "D:\\Coding\\open-telemetry\\opentelemetry-dotnet-instrumentation\\*" : "https://raw.githubusercontent.com/martincostello/opentelemetry-dotnet-instrumentation/8274215e86868e90c181aed15e97535c33e70cb3/*" }}Will also verify against the CI build once completed.
Checklist
CHANGELOG.mdis updated.Documentation is updated.New features are covered by tests.