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

Convert all usages of target_link_libraries to use PUBLIC/PRIVATE specifiers #81924

Merged
merged 8 commits into from
Feb 24, 2023

Conversation

jkoritzinsky
Copy link
Member

CMake requires all usages to be consistent, and we're going to add these specifiers as part of the sanitizer work, so make them consistently used across the repo (excluding external sources) here.

Split out of #74623

…cifiers

CMake requires all usages to be consistent, and we're going to add these specifiers as part of the sanitizer work, so make them consistently used across the repo here.
@ghost
Copy link

ghost commented Feb 9, 2023

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

Issue Details

CMake requires all usages to be consistent, and we're going to add these specifiers as part of the sanitizer work, so make them consistently used across the repo (excluding external sources) here.

Split out of #74623

Author: jkoritzinsky
Assignees: -
Labels:

area-Infrastructure

Milestone: -

Copy link
Member

@lambdageek lambdageek left a comment

Choose a reason for hiding this comment

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

Mono LGTM, except I think component_base should be PRIVATE

src/mono/mono/component/CMakeLists.txt Outdated Show resolved Hide resolved
src/mono/mono/component/CMakeLists.txt Outdated Show resolved Hide resolved
Co-authored-by: Aleksey Kliger (λgeek) <akliger@gmail.com>
@mdh1418
Copy link
Member

mdh1418 commented Feb 13, 2023

Do we also need one for

target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES_ADDITIONAL})
?

When new CMakeLists.txt files are added, what would be the best way to notify the contributor that a target_link_libraries is missing the PUBLIC|PRIVATE|INTERFACE scope specifiers?

@jkoritzinsky
Copy link
Member Author

Do we also need one for

target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES_ADDITIONAL})

?

Yes, I missed that one.

When new CMakeLists.txt files are added, what would be the best way to notify the contributor that a target_link_libraries is missing the PUBLIC|PRIVATE|INTERFACE scope specifiers?

We don't have automated tooling for this today, but when the work to enable AddressSanitizer gets in, the requirement will likely be enforced by CMake (as we'll add a linker flag with a specifier to many of the projects, which will cause CMake to error when someone adds a linker flag/library link without the scope specifier)

@lambdageek
Copy link
Member

@jkoritzinsky FYI I'm going to merge #82182 shortly which might create some conflicts with this PR. I'm adding some object libraries to mono - and they will already be using PRIVATE/PUBLIC

Copy link
Member

@mdh1418 mdh1418 left a comment

Choose a reason for hiding this comment

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

There are a few more in the AndroidAppBuilder and AppleAppBuilder Tasks which have a slight modification of CMakeLists.txt name


target_link_libraries(
%ProjectName%
"-framework Foundation"
"-framework Security"
"-framework UIKit"
%FrameworksToLink%
"-lz"
"-lc++"
"-liconv"
%NativeLibrariesToLink%
)
if(%UseNativeAOTRuntime%)
target_link_libraries(
%ProjectName%
"-Wl,-u,_NativeAOT_StaticInitialization"
)

Besides those, and double checking that we can ignore src/native/external/zlib, then if the CI failures are unrelated (Could something like The type or namespace name 'ProducedBy' could not be found be a result of a PRIVATE scope instead of PUBLIC?), then I think this is in good shape.

@jkoritzinsky
Copy link
Member Author

The CI failures are unrelated. There was a regression that made it into main that there are already PRs out to fix. I'll go update the AppBuilder templates.

@lambdageek
Copy link
Member

lambdageek commented Feb 24, 2023

Do the templates actually matter? They're meant to be like examples of "user code". They're not consuming any of the cmake fragments that we have in the runtime repo.

Update well ok, Jeremy updated the templates already. That's ok. it doesn't hurt to clean them up a bit

@jkoritzinsky
Copy link
Member Author

Do the templates actually matter? They're meant to be like examples of "user code". They're not consuming any of the cmake fragments that we have in the runtime repo.

Update well ok, Jeremy updated the templates already. That's ok. it doesn't hurt to clean them up a bit

Yeah we don't really need to update them, but I figured it was worthwhile for consistency since it was brought up.

@mdh1418
Copy link
Member

mdh1418 commented Feb 24, 2023

Do the templates actually matter? They're meant to be like examples of "user code". They're not consuming any of the cmake fragments that we have in the runtime repo.
Update well ok, Jeremy updated the templates already. That's ok. it doesn't hurt to clean them up a bit

Yeah we don't really need to update them, but I figured it was worthwhile for consistency since it was brought up.

The templates are currently used to build custom CMakeLists.txt that will be used by the AppleAppBuilder and AndroidAppBuilder for library tests, runtime tests, and mono samples, so in that sense its more than just examples. I think the consistency would be good especially if the AddressSanitizer ends up being extended for Mono (not sure if that possible or planned). Moreover, if there are more tasks brought up in the future that look to those (AppleAppBuilder and AndroidAppBuilder) for inspiration (like the LibraryBuilder PR), then theres a better chance a PUBLIC/PRIVATE scope will be added to target_link_libraries the task as well.

Copy link
Member

@mdh1418 mdh1418 left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@jkoritzinsky
Copy link
Member Author

All failures are known issues.

@jkoritzinsky jkoritzinsky merged commit e11c334 into dotnet:main Feb 24, 2023
@jkoritzinsky jkoritzinsky deleted the private-link-libraries branch February 24, 2023 23:33
@ghost ghost locked as resolved and limited conversation to collaborators Mar 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants