-
Notifications
You must be signed in to change notification settings - Fork 51
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
CMakeLists: Make grpc-device buildable on NILRT 11 #1082
CMakeLists: Make grpc-device buildable on NILRT 11 #1082
Conversation
NILRT 11 will ship with grpc >1.60 and protobuf >v25.2. grpc-device doesn't compile with these toolchain versions, throwing errors about undefined symbols. Downgrading grpc back to 1.51 (with python3-grpcio and protobuf recipes) successfully works around these issues. But for security and general currency reasons, we cannot afford to ship NILRT 11 with these downgrades. Current CMakeLists.txt is limited to some of the bitbake functionalities which makes it difficult to build with new changes. Changes in this commit will make sure NILRT 11 compiles grpc-device with the latest/upgraded grpc version without affecting the existing build process. Changes: 1. refactor toolchain link logic - Deprecate the CMAKE_CROSSCOMPILING variable, in favor of USE_SUBMODULE_LIBS cmake option. Refactor the linking logic to be a consolidation of all the linking actions from across the file, and to better support builds in generic linux environments. 2. fixup utf8cpp library link - The utf8cpp cmake library namespace is incorrectly identified as 'utf8cpp', instead of the proper 'utf8cpp:utf8cpp'. As a result, cmake does not link the utf8.h header and compilation fails. 3. parameterize python3 venv - Create a USE_PYTHON_VIRTUALENV cmake option. When asserted, it will add the bespoke venv to the toolchain. Otherwise, the cmake config will use the system python environment. 4. link the device server to grpc_gpr - ni_grpc_device_server target depends on symbols from grpc gpr.so, namely gpr_log. Add grpc_gpr to link libraries for ni_grpc_device_server. 5. add abseil_sync dep to server target - ni_grpc_device_server uses symbology from libabsl_synchronization library. Add a library dependency to reflect that relationship. 6. add utf8cpp dep to IntegrationTestsRunner - The IntegrationTestsRunner depends on utf8.h header indirectly, via its access to the device server source. 7. fill out target lib deps - Shove ni_grpc_device_server library dependencies into a variable, so that it can be easily passed along to the test targets. 8. suppress protobuf installation in SM - Set protobuf_INSTALL=OFF, which suppresses the protobuf installation codepaths - that we don't want to use anyway and which cause the failure. 9. add necessary gRPC dep to ni_grpc_device_server - ni_grpc_device_server must be linked against libgrpc, as well as the grpccpp libs. 10.fixup venv codegen deps - Give the codegen targets a dependency on the python virtualenv via the all_codegen_dependencies variable. Signed-off-by: Rajendra Desai <rajendra.desai@ni.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.
Change looks good to me. I appreciate the thoroughness and clarity.
I would like @reckenro and @maxxboehme to review if possible.
It looks like you have some errors in the windows build.
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.
Looks good to me besides sorting out the build failures
…d fixed a small typo Signed-off-by: Rajendra Desai <rajendra.desai@ni.com>
Signed-off-by: Rajendra Desai <rajendra.desai@ni.com>
MSVC_RUNTIME_LIBRARY property) which is supported on cmake version >3.15 in case of MSVC compiler Signed-off-by: Rajendra Desai <rajendra.desai@ni.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.
Looks good so far. Will wait for final review when windows build has been fixed.
I tried doing a windows build locally with the existing changes to debug the pipeline failures that I am getting for Windows build, but I am not able to reproduce those linker errors that are being reported in the pipeline logs. I am able to build and run the executables (IntegrationTestsRunner.exe, ni_grpc_device_server.exe, SystemTestsRunner.exe, UnitTestsRunner.exe) successfully. @maxxboehme @astarche @reckenro @bkeryan: Is there anything more I can try out? Or am I missing something? |
@rajendra-desai-ni , this is my stab at a guess or at least where I'd look. I'm guessing it has to do with the lines about I say that because that seems to indicate statically linked according to the documentation while in the CMAKE < 3.15 case it's using That's where I'd look into at least. I say this all with little experience debugging the CMAKE builds and no idea what the desired settings are in this case. |
It seems that all of the errors are about gtest.lib and gmock.lib. Perhaps the issue is related to gtest_force_shared_crt, which is supposed to prevent gtest from replacing /MD with /MT. Does this need to be set before you add the third_party/gtest dir? |
This reverts commit 2ea12e9.
@reckenro, Thanks for the reply, I tried doing a static linking to the project files since we are building the exe's, but even that doesn't seem to be working. It looks like the other workarounds doesn't seem to work as well :( |
@bkeryan, I am not sure if setting gtest_force_shared_crt before adding the third_party/gtest dir would make any difference as we are anyways setting it before building the binaries or linking the files. Please correct me if I am wrong here. |
@rajendra-desai-ni I don't know the answer. That's why I asked the question. Did you try moving this variable above the add_subdirectory? The old code did it in this order:
I can't find this variable in your latest changes. Did you remove it? |
@bkeryan: I was trying out other workarounds, so I had removed the code. I reverted those and tried your suggested changes and I am now able to get the windows pipeline building. Thanks for the help!! |
@bkeryan @reckenro @maxxboehme @astarche : All the required checks are now successful. Please feel free to re-review the changes as there were many commits and comments to fix the failing windows pipeline. |
@maxxboehme @astarche @reckenro @bkeryan : It looks like I have got all necessary approvals for this PR. Can one of you please merge this PR so that I can go ahead and enable the package from NILRT side? Or is this PR merge self-doable and if so, do I need to squash and merge? |
AB#2640878
What does this Pull Request accomplish?
NILRT 11 will ship with grpc >1.60 and protobuf >v25.2. grpc-device doesn't compile with these toolchain versions, throwing errors about undefined symbols. Downgrading grpc back to 1.51 (with python3-grpcio and protobuf recipes) successfully works around these issues. But for security and general currency reasons, we cannot afford to ship NILRT 11 with these downgrades.
Current CMakeLists.txt is limited to some of the bitbake functionalities which makes it difficult to build with new changes.
Changes in this commit will make sure NILRT 11 compiles grpc-device with the latest/upgraded grpc version without affecting the existing build process.
Why should this Pull Request be merged?
This patchset includes necessary changes to enable building on NILRT, within OpenEmbedded.
What testing has been done?
Implementation
Deprecate the CMAKE_CROSSCOMPILING variable, in favor of USE_SUBMODULE_LIBS cmake option. Refactor the linking
logic to be a consolidation of all the linking actions from across the file, and to better support builds in generic linux
environments.
The utf8cpp cmake library namespace is incorrectly identified as 'utf8cpp', instead of the proper 'utf8cpp:utf8cpp'. As a result,
cmake does not link the utf8.h header and compilation fails.
Create a USE_PYTHON_VIRTUALENV cmake option. When asserted, it will add the bespoke venv to the toolchain. Otherwise,
the cmake config will use the system python environment.
ni_grpc_device_server target depends on symbols from grpc gpr.so, namely gpr_log. Add grpc_gpr to link libraries for
ni_grpc_device_server.
ni_grpc_device_server uses symbology from libabsl_synchronization library. Add a library dependency to reflect that
relationship.
The IntegrationTestsRunner depends on utf8.h header indirectly, via its access to the device server source.
Shove ni_grpc_device_server library dependencies into a variable, so that it can be easily passed along to the test targets.
Set protobuf_INSTALL=OFF, which suppresses the protobuf installation codepaths - that we don't want to use anyway and
which cause the failure.
ni_grpc_device_server must be linked against libgrpc, as well as the grpccpp libs.
Give the codegen targets a dependency on the python virtualenv via the all_codegen_dependencies variable.
This is needed to fix Linker issues while building the binaries
It is preferable to do a clean build to ensure all object files are deleted and then rebuilt from scratch, which can help
resolve inconsistencies and errors.