-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 the path to the packages version of protoc #2488
Conversation
…otoc to the add_custom_command so it can be found and used
Some configurations of 'protobuf/3.9.1' failed in build 1 (
|
All green in build 2 (
|
… it contains multiple paths
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 should NOT merge this PR.
Only in a native build, we would want to execute the protoc
from the ${Protobuf_LIB_DIRS}/../bin
directory, so this change will break the recipe for any cross-building scenario as it is overriding the PATH
.
Yes, we are overriding the
DYLD_LIBRARY_PATH
, but due to Macos SIP protection, this is the only way to propagate those variables and yes, it works only in a native build 😖 I'm investigating some other alternatives to bypass this limitation (conan-io/conan#7324) that will work whenprotoc
is linked dynamically withprotobuf.dylib
in a cross-building scenario.
Nevertheless, I understand the underlying pain it is trying to fix: unless you activate the environment protoc
is not found. This is something we are trying to figure out how to tackle, different approaches:
conan create
or recipes consuming this package work because they are using theenvironment_append
orself.run(...., run_environment=True
).- Local build:
- (now) use a
virtualrunenv
generator and activate it, it will add the PATH to theprotoc
you are consuming - (in the future) Via the new toolchain paradigm it should be possible to add this environment to the CMake toolchain. It will supersede the approach in (1), but we need more feedback from users to evolve the toolchain feature.
- (now) use a
All green in build 3 (
|
@@ -200,7 +200,7 @@ index f90e525e..fd0c1f68 100644 | |||
- ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_protobuf_include_path} ${_abs_file} | |||
- DEPENDS ${_abs_file} protobuf::protoc | |||
+ COMMAND "${CMAKE_COMMAND}" #FIXME: use conan binary component | |||
+ ARGS -E env "DYLD_LIBRARY_PATH=${Protobuf_LIB_DIRS}:${CONAN_LIB_DIRS}:${Protobuf_LIB_DIRS_RELEASE}:${Protobuf_LIB_DIRS_DEBUG}:${Protobuf_LIB_DIRS_RELWITHDEBINFO}:${Protobuf_LIB_DIRS_MINSIZEREL}" protoc --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_protobuf_include_path} ${_abs_file} | |||
+ ARGS -E env "PATH=${Protobuf_LIB_DIRS}/../bin" "DYLD_LIBRARY_PATH=${Protobuf_LIB_DIRS}:${CONAN_LIB_DIRS}:${Protobuf_LIB_DIRS_RELEASE}:${Protobuf_LIB_DIRS_DEBUG}:${Protobuf_LIB_DIRS_RELWITHDEBINFO}:${Protobuf_LIB_DIRS_MINSIZEREL}" protoc --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_protobuf_include_path} ${_abs_file} |
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.
can't this be something like Protobuf_BIN_DIRS
or there is no such variable?
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 FindProtobuf
documentation suggest that there is a Protobuf_PROTOC_EXECUTABLE
but it doesn't seem to be set.
https://cmake.org/cmake/help/latest/module/FindProtobuf.html
But I did find a CONAN_BIN_DIRS_PROTOBUF
that looks like a cleaner option.
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.
This is at least partly due to fact, that we can't mimic having Protobuf_
variables prefixes, we currently have protobuf_
. See also #2037
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 problem is not the variable itself of casing issues. The problem is the value of the variable. Here we want to execute the protoc
that belongs to the build context, while this is a CMake file executed for a package in the host context. There is only a find_package(protobuf)
that provides everything from the host context, there is no find_package(protobuf THE_ONE_FROM_BUILD_CONTEXT)
so none of the variables that are available contain the PATH to the protoc
from the build context.
Information for protoc
is only known by Conan (it knows the full graph) and Conan need to pass that information to CMake, unless we use some conan-convention (which is not fair), we can only populate the environment (PATH
and DYLIB
) and use just protoc
inside CMake... but:
- it requires to populate the environment: also for local build
- we need to workaround SIP protection in Mac to use shared protoc.
If Protobuf_PROTOC_EXECUTABLE
is a standard variable, we can populate it from Conan with the path to the proper protoc
(still will fail for Macos because of SIP), but local-builds won't work unless the user adds this variable to the command-line command or the toolchain populates it.
@jgsogo what about (former) idea to generate wrapper executable, such as (pseudo-code):
from my point of view:
|
Yes, IMO the wrapper approach is the only one that would work for all scenarios, but it requires a feature in Conan (conan-io/conan#7324 and conan-io/conan#7240), with them Conan can generate the wrapper for all the executables in a package and populate For the local development flow, still the toolchain approach need to populate the environment, it isn't right now. |
@jgsogo is it really needed to wait for a feature in conan? e.g. in android_ndk_installer package, we provide such a wrapper for the CMake executable. I guess nothing prevents us from generating wrapper in the recipe right away. |
I know that wrapper, I've been using it and it is amazing. But that one is a wrapper over CMake and it uses the Here we can write a Both approaches could work (I¡d prefer the first one), but they won't fix the local-build problem which is the issue that originated this PR, it would only workaround the SIP-Macos issue. BUT, in order to generate the wrapper with the right values, you need the paths to the shared libraries you are using in the current graph, so it has to take the values in runtime, it cannot be generated together with the package. You cannot trust the virtualenv generators (they might not be generated), you need to intercept the environment variables and hardcode them in the wrapper. How can you do it? Who is responsible of writing the wrapper? |
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.
Having a look at the comments I see the issue is far beyond the naming of the bar, so I'd unblock my review
The I tried cross-compiling this recipe as is for an RPi and it fails when trying to run the Maybe |
All green in build 4 (
|
@jgsogo |
Splitting won't help with the SIP issue. If you build |
Hello guys, |
There is a PR to Conan proposing wrappers around executables, IMHO, that would be the way to go if we don't find any blocker. |
I came up with a better solution I think. The trick is to add a find_program() call in protobuf-config.cmake, which is a file installed by the package. We can then use See I know that my changes mix upgrade to version 3.13.0 AND adding this path... if you think my solution is worth merging, I could work on it. This change significantly reduces the complexity of writing a gRPC package that is easy to consume. It removes the need for findPackage(). |
The problem is not about locating The problem is about finding the dynamic libraries that |
I see. There's a catch with using PATH: if the user has another version of protoc installed in /usr/bin for example, simply calling "protoc" might call the wrong executable. So it is better to force using the right path. About finding the dynamic libraries: what about using |
Wow! Didn't know about the Note.- We cannot modify the executable in the Conan cache for two reasons:
|
Would it be possible to mark this PR as 'blocked' until there is a clear solution? Unless that will distract from the amazing work you guys are doing, in that case dont mind me! |
This approach does not appear to be viable at this time. |
Amend patches to add the path to the packages version of
protoc
to theadd_custom_command
so it can be found and usedFixes #1956
Specify library name and version: protobuf/3.11.4
conan-center hook activated.