dotnet / sourcelink

Source Link enables a great source debugging experience for your users, by adding source control metadata to your built assets
MIT License
1.26k stars 122 forks source link

Support for C++ libs #580

Open nickdalt opened 4 years ago

nickdalt commented 4 years ago

Currently C++ support appears to be limited to DLL and EXE targets.

What I would like to see is sourcelink information being generated for static lib targets and then when the final link occurs into a executable the resulting pdb contains the combined sourcelink information for all the static libs that went into building the executable.

I am not sure if this would require an update to link.exe in order to support this scenario

tmat commented 4 years ago

This should be possible today, but I'm not sure if it works out-of-the box with just including the Source Link nuget packages in your projects. You might need some tweaking of the build.

The linker supports embedding source link record in each static lib's PDB and then preservers all these records in the final linked binary. link.exe has /sourcelink switch that instructs it to embed specified Source Link JSON.

nickdalt commented 4 years ago

I test shows few problems:-

  1. Including the NuGet packages in a C++ static lib project does nothing at all. With a exe project it works as expected.

  2. While the linker supports the /sourcelink switch the lib tool does not

    lib /sourcelink LINK : warning LNK4044: unrecognized option '/sourcelink'; ignored

So currently the only option would appear to be to create source link files for each lib and then ship them with the libs. They would then need to be combined in the final link (assuming the /sourcelink switch cannot be used multiple times).

Ideally the lib tool would be updated to support /sourcelink

bormm commented 3 years ago

Any news about this @tmat ?

sylveon commented 2 years ago

Am also interested in using SourceLink with static libraries