-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add support for C++ libs into sourcelink #605
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR. I'm not sure there is much benefit in merging Source Link files. VC++ linker supports multiple This was specifically designed to remove complexity of merging JSON from build systems such as CMake. |
…, multiple uses of the link /sourcelink arg are used.
OK, I hadn't realised that /sourcelink could be used multiple times. I have updated the code to used /sourcelink with each discovered .sourcelink.json file. |
<!-- | ||
Add compiler targets: C++ generates sourcelink file only for static libs. | ||
--> | ||
<PropertyGroup Condition="'$(Language)' == 'C++' and $(ConfigurationType) == 'StaticLibrary'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
<!-- | ||
Add compiler targets: C++ generates PDB with SourceLink in Link phase. | ||
--> | ||
<PropertyGroup Condition="'$(Language)' == 'C++'"> | ||
<PropertyGroup Condition="'$(Language)' == 'C++' and $(ConfigurationType) != 'StaticLibrary'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
<!-- C++ Link task currently doesn't recognize SourceLink property only add this for non-static libs since lib doesn't | ||
understand /sourcelink | ||
--> | ||
<ItemGroup Condition="'$(Language)' == 'C++' and $(ConfigurationType) != 'StaticLibrary'"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
try | ||
{ | ||
//// Throughout we expect that the sourcelink files for a lib is alongside |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
<Link Update="@(Link)"> | ||
<AdditionalOptions>%(Link.AdditionalOptions) /sourcelink:"$(SourceLink)"</AdditionalOptions> | ||
<AdditionalOptions>%(Link.AdditionalOptions) @(SourceLinks->'/sourcelink:"%(Identity)"', ' ')</AdditionalOptions> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickdalt Thanks for the PR - sorry for the delay in review. Was busy with other things. Any ideas how we can test this reasonably? I think we should at least have unit tests for FindAdditionalSourceLinkFiles task. End-to-end test might be too complicated since it would depend on VC++ compiler targets. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Command line switches need escaping and we also need a test.
…, multiple uses of the link /sourcelink arg are used.
…dalt/sourcelink into support-for-cpp-static-libs
Added unit tests for FindAdditionalSourceLinkFiles Tweaks to inheritance to handle Task type confusion in VS2022
I am not clear what you want here
I can't see any easy way of testing end to end since that would require publishing the NuGet, consuming it in multiple C++ projects, building them, and finally checking that the pdb contains the sourcelink details for the libs. I have however added unit tests for FindAdditionalSourceLinkFiles |
I am interested in this - however my setup is a few static libraries packaged in a NuGet package and then acquired in another solution. I imagine in this setup, it would be required for the NuGet package to ship the relevant .sourcelink.json files, and then for the consumer of my package to also have the SourceLink NuGet package installed so that it can then be passed to Also, it seems SourceLink is disabled by default for IDE builds, but in a setup like the one mentioned here, we would need to at least get the SourceLink metadata from the static libraries into the final PDB even from IDE builds. Would we need to enable SourceLink as a whole for IDE builds or is this something this PR considers? I guess, alternatively, we could tweak our NuGet package's |
@nickdalt Sorry for the long delay. Switched focus to some other work. If you're still interested in bringing this PR forward, please rebase to the latest main. |
Modify Microsoft.SourceLink.Common as follows:-
Makes the assumption that the for a C++ static lib the sourcelink file will be in the same directory with the extension sourcelink.json
Possible additional tasks for maintainer:-
See also issue #580