-
Notifications
You must be signed in to change notification settings - Fork 448
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 some problems with the Protobuf CMake file #4262
Conversation
3b2b974
to
93dd245
Compare
CMakeLists.txt
Outdated
@@ -128,7 +128,7 @@ if (BUILD_STATIC_RELEASE) | |||
# Set the static variable | |||
set(P4C_STATIC_BUILD STATIC) | |||
# Do not bring in dynamic libstdcc and libgcc | |||
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++ -Wl,-z,muldefs") | |||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-z,muldefs") |
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.
Linking protoc when using -static causes a series of problems. It seems to be a bad idea to use -static in general, so let's just fix this call.
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.
But this option is under BUILD_STATIC_RELEASE
. It seems wrong to me to have this build non-static binary. If BUILD_STATIC_RELEASE
is broken, we should just remove it. Arguably it is broken on most linux distros as glibc should not be linked statically (and often there is no corresponding .a
). Therefore, BUILD_STATIC_RELASE
would be useful only on distros like Alpine (which uses MUSL instead of GLIBC).
I suggest you just don't enable BUILD_STATIC_RELEASE
. If you have need for semi-static (i.e. glibc dynamic, rest static) build, that should be handled by a new CMake option in a new PR.
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.
We a CI test that causes problems, so it is a little tricky to make this work. -static
not only causes problems for Protobuf but also the libgc build.
Let me experiment a bit with this. I am able to build locally with clang+lld. So maybe that is one way to ensure we can at least generate some form of static release.
With bf-p4c, we did not even use the -static
iirc.
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.
Yep, that is why I suggested actually removing static as a possibility. If we add semi-static instead, it would not be hard if anyone needed full-static to set it from it (basically just setting CMAKE_EXE_LINKER_FLAGS
to -static
). We probably have no way of knowing if static build is used by anyone (unless they show up 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.
So what is the best course of action here? Throw a warning when BUILD_STATIC_RELEASE
is enabled? Or rename BUILD_STATIC_RELEASE?
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 would suggest renaming it. This seems the cleanest to me and least risk of breaking someones workflow. Maybe something like BUILD_SEMI_STATIC_RELEASE
, although it does not explain what it means to be semi-static. But I cannot think of a short way to express "static except for basic OS dependencies like glibc".
@@ -28,7 +28,7 @@ add_custom_target (dpdk_runtime_dir | |||
# placed in the build directory inside `control-plane` directory | |||
add_custom_command( | |||
OUTPUT ${DPDK_P4RUNTIME_INFO_GEN_SRCS} ${DPDK_P4RUNTIME_INFO_GEN_HDRS} | |||
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} | |||
COMMAND ${Protobuf_PROTOC_EXECUTABLE} |
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 canonical Protobuf variable prefix is now Protobuf_
instead of PROTOBUF_
.
https://cmake.org/cmake/help/latest/module/FindProtobuf.html
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build tests.") | ||
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build libprotoc and protoc compiler.") | ||
set(protobuf_BUILD_PROTOC_BINARIES ON CACHE BOOL "Build libprotoc and protoc compiler.") |
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.
We build protoc from scratch, because the downloaded, prebuilt binary can interact badly with protoc plugins such as grpc_cpp_plugin
.
00ae8b3
to
1b7d9cb
Compare
1b7d9cb
to
2dbbf7a
Compare
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 change in P4C_STATIC_BUILD
is wrong in my opinion. It might be broken, but changing its behavior to build non-static binary would be extremely confusing.
Otherwise there seem to be some unnecessary code and I don't understand why you are using two different variables for PROTOC binary (in different places in the cmake).
CMakeLists.txt
Outdated
@@ -128,7 +128,7 @@ if (BUILD_STATIC_RELEASE) | |||
# Set the static variable | |||
set(P4C_STATIC_BUILD STATIC) | |||
# Do not bring in dynamic libstdcc and libgcc | |||
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++ -Wl,-z,muldefs") | |||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -Wl,-z,muldefs") |
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.
But this option is under BUILD_STATIC_RELEASE
. It seems wrong to me to have this build non-static binary. If BUILD_STATIC_RELEASE
is broken, we should just remove it. Arguably it is broken on most linux distros as glibc should not be linked statically (and often there is no corresponding .a
). Therefore, BUILD_STATIC_RELASE
would be useful only on distros like Alpine (which uses MUSL instead of GLIBC).
I suggest you just don't enable BUILD_STATIC_RELEASE
. If you have need for semi-static (i.e. glibc dynamic, rest static) build, that should be handled by a new CMake option in a new PR.
f675f43
to
7458d4a
Compare
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 the changes now make sense. But I strongly suggest the renaming of static build is a separate PR. It is not directly related to Protobuf and it would be good if it is more visible in the commit messages for the benefit of downstream tools etc.
# Disabling checks until we find a better way to build a fully static binary. | ||
ldd ./build/p4c-bm2-psa 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" | ||
ldd ./build/p4c-bm2-ss 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" | ||
ldd ./build/p4c-dpdk 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" | ||
ldd ./build/p4c-ebpf 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" | ||
ldd ./build/p4c-pna-p4tc 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" | ||
ldd ./build/p4c-ubpf 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" | ||
ldd ./build/p4test 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" | ||
ldd ./build/p4testgen 2>&1 # | grep -E -qi "(not a dynamic executable)|(statically linked)" |
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.
We could check that there is no boost, no libstdc++, etc. It would be a partial check only, but it would be at least something.
7458d4a
to
f520ef6
Compare
f520ef6
to
0da31ee
Compare
0da31ee
to
d27dce7
Compare
… Build protoc from scratch.
d27dce7
to
8c28a57
Compare
A P4C extension I was working on needed gRPC. However, the way we currently build Protobuf does not combine well with the gRPC FetchContent module. This PR adds a couple fixes for the Protobuf FetchContent script.