-
Notifications
You must be signed in to change notification settings - Fork 163
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
fix(build): update grpc cmake module to use find_package() when building using system library #144
Conversation
…ing using system library. This fixes the linking of libraries at the end of Falco build. Signed-off-by: Federico Di Pierro <nierro92@gmail.com> Co-authored-by: Leonardo Grasso <me@leonardograsso.com>
Hi @FedeDP. Thanks for your PR. I'm waiting for a falcosecurity member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
…cosecurity/libs#144. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
…cosecurity/libs#144. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
…cosecurity/libs#144. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
/ok-to-test |
…make module is not found on system. Ubuntu focal is not shipping the module. Avoid breaking CI and builds on it. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
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.
/approve
👍
LGTM label has been added. Git tree hash: b8f2c6f38667c50e502cc7f22ebf1f9b380aab0d
|
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.
If we need the fallback anyway, does the find_package
approach actually help with anything? i.e. are there environments where find_package
works while find_library
doesn't?
cmake/modules/grpc.cmake
Outdated
find_path(GRPCXX_INCLUDE NAMES grpc++/grpc++.h) | ||
if(NOT GRPCXX_INCLUDE) | ||
find_path(GRPCPP_INCLUDE NAMES grpcpp/grpcpp.h) | ||
add_definitions(-DGRPC_INCLUDE_IS_GRPCPP=1) | ||
endif() |
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.
Do we want to pass PATHS ${GRPC_INCLUDE}
(or something that uses the pkg_config data) to the find_path
calls here?
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.
I think we might; but that was there before my PR and i didn't want to touch it (gRPC cmake is a bit like the ultimate boss to fight against! Now i unlocked holiness badge :P)
I mean, that checking code is the same as before.
Btw we could adjust it, if you think it is needed :)
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.
yeah, the grpc build scripts are on a whole different level :D
my reasoning for the requested change is:
- the old code always did find_library etc. without any hints so only searched the default paths, whatever they are
- the new code can potentially find grpc elsewhere, but we do:
- get the GRPC_INCLUDE property from the grpc cmake module (good)
- look for grpc++/grpc++.h in the default locations (bad)
- if not found, look for grpcpp/grpcpp.h in the default locations again (bad too)
so, this new code appears more flexible but in the end still requires the grpc headers to live in the default location
... or I'm completely wrong :D
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.
Nope! The problem was that the old code assumed that grpc libraries had built-in all their deps, ie: statically linked.
The new code instead is able to correctly use a grpc that dynamically links its dependencies, while still managing statically linked one.
The old case was left still because we found out that find_package(gRPC)
can fail on some distro because gRPC cmake config module is not installed.
To summarize:
- package found -> both dynamically and statically linked gRPC work fine
- package not found -> current libs master behavior
the new code can potentially find grpc elsewhere, but we do:
BTW you are right, i will update that!
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.
Note however that
find_path(GRPCXX_INCLUDE NAMES grpc++/grpc++.h)
if(NOT GRPCXX_INCLUDE)
find_path(GRPCPP_INCLUDE NAMES grpcpp/grpcpp.h)
add_definitions(-DGRPC_INCLUDE_IS_GRPCPP=1)
endif()
is just used to set the GRPC_INCLUDE_IS_GRPCPP define ;)
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.
Yes, but that assumes that grpc++/grpc++.h
can be found in the default include paths.
If GRPC_INCLUDE
is non-standard, we'll still look for grpc++.h in the default locations, so we won't find it if it exists in e.g. /opt/grpc/include/grpc++.h` (where the grpc cmake pointed us to).
If we simply add PATHS ${GRPC_INCLUDE}
to the find_path
invocation, we should be good (I think).
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.
the new code can potentially find grpc elsewhere, but we do:
Should be fixed now! Thanks for your input!
set(GPR_LIB gRPC::gpr) | ||
set(GRPC_LIB gRPC::grpc) | ||
set(GRPCPP_LIB gRPC::grpc++) |
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.
What does this do? Does it want to link with -lgRPC::gpr
or is it some cmake syntax I'm not aware of that pulls the values from the find_package
result?
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.
gRPC::*
are namespaced targets names exported by find_package
(those targets are usually defined in /usr/lib/cmake/grpc/gRPCTargets.cmake
). They can be used as items in target_link_libraries
and are automatically resolved.
To be more precise, the documentation says that an item can be:
A library target name: The generated link line will have the full path to the linkable library file associated with the target. The buildsystem will have a dependency to re-link if the library file changes.
Regarding the namespaced targets also adds:
Items containing
::
, such asFoo::Bar
, are assumed to be IMPORTED or ALIAS library target names and will cause an error if no such target exists.
Okay, I actually read the linked issue ;) So AIUI, gRPC can have some extra dependencies we don't know about so we don't link them. The patch looks mostly fine but please see the comments (for my education, mostly :D). |
Hey @gnosek
Yes, there are. |
Well, find_library will work all the time; the issue is that it is not able to provide a list of gRPC deps, thus we would fail at the linking stage if gRPC is not statically linked. |
Signed-off-by: Federico Di Pierro <nierro92@gmail.com> Co-authored-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
8f911eb
to
cfdc21d
Compare
Force-pushed to fix dco (i always get wrong github "commit suggestion" ...) |
/test build-libs |
…path hint. Signed-off-by: Federico Di Pierro <nierro92@gmail.com> Co-authored-by: Grzegorz Nosek <grzegorz.nosek@sysdig.com>
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.
/approve
👏
LGTM label has been added. Git tree hash: 5fe6f6a132b61e66cbbda08fb3b1853df89c4873
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: FedeDP, leogr The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
Thanks!
…cosecurity/libs#144. Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
What type of PR is this?
/kind bug
Any specific area of the project related to this PR?
/area build
What this PR does / why we need it:
It allows to build falco linking system grpc.
Which issue(s) this PR fixes:
Fixes #99
Special notes for your reviewer:
Does this PR introduce a user-facing change?: