-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[WIP] protobuf: build with cmake instead of autoconf #84824
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
Conversation
cc @veprbl who has a protobuf PR open as well |
Thanks for the ping. I don't mind either solution. |
@eamsden please rebase on top of master. |
7bb0771
to
0351abd
Compare
@veprbl done |
|
||
-install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_CMAKEDIR}/ | ||
+install(DIRECTORY ${CMAKE_INSTALL_CMAKEDIR}/ | ||
DESTINATION "${CMAKE_INSTALL_CMAKEDIR}" |
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 suspect you are trying to deal with an absolute path we set in our default setup-hook:
cmakeFlags="-DCMAKE_INSTALL_LIBDIR=${!outputLib}/lib $cmakeFlags" |
But how can this work that you install from a directory in "$out" to itself.
I think, we typically workaround this by doing:
"-DCMAKE_INSTALL_LIBDIR=lib" |
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.
Is it preferred to do it through flags instead of patching the (very odd and unfortunate) CMake 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.
The good thing about "-DCMAKE_INSTALL_LIBDIR=lib" is that we can search for it through nixpkgs and see packages affected.
Also, I am still not sure how your patch works.
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.
Looking at the source code, it intends to put intermediary file generated by configure_file
under lib/cmake/protobuf
in the build directory but (wrongly) assumes the CMAKE_INSTALL_LIBDIR
is relative.
The line you patch would install the directory from the build directory to the target location but since we have absolute CMAKE_INSTALL_LIBDIR
, it is already in the target location and not in the build directory (${CMAKE_CURRENT_BINARY_DIR}
).
The correct patch would be changing the output of configure_file
and the input of install(DIRECTORY
to something like ${CMAKE_CURRENT_BINARY_DIR}/this_is_an_intermediary_dir_for_cmake_files
. I do not think there is any need for the intermediate directory to be the same as the target destination.
# CMake doesn't generate the version.rc file from version.rc.in. | ||
++ lib.optional | ||
(lib.versionAtLeast version "3.6" && lib.versionOlder version "3.7") | ||
./protobuf-3.6-cmake-versionrc.patch; |
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.
Upstream only generates that one for windows:
https://github.com/protocolbuffers/protobuf/blob/7b8a241b575b756c4dd7a5aec7f7a60854d5f711/cmake/CMakeLists.txt#L219-L220
Why do we need it? If we need it, we should let upstream know by submitting the patch or filing an issue.
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.
It causes the build to fail, but just for version 3.6, if we don't generate it, thus the version bounding check.
(if lib.versionAtLeast version "3.6.0" | ||
then '' | ||
rm -rf third_party/googletest | ||
cp -a ${gmock.src} third_party/googletest | ||
chmod -R a+w third_party/googletest | ||
'' | ||
else '' | ||
cp -a ${gmock.src}/googlemock gmock | ||
cp -a ${gmock.src}/googletest googletest | ||
chmod -R a+w gmock | ||
chmod -R a+w googletest | ||
ln -s ../googletest gmock/gtest | ||
'') |
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 set fetchSubmodules = true
in fetchFromGithub
(don't forget to update hashes).
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.
That is an approach I could take. I borrowed this approach from the existing Autoconf 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.
Let's try that. Also remove the darwin hack below, we'll figure something out if it's still 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.
(Don't forget to drop gmock
argument)
buildInputs = [ zlib ]; | ||
configureFlags = if buildProtobuf == null then [] else [ "--with-protoc=${buildProtobuf}/bin/protoc" ]; |
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.
Did you check that cross builds still function?
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 believe so. protobuf builds protoc but doesn't actually use it as part of the build, it appears someone misread the instructions for cross compiling projects that depend on protobuf as directions for cross-compiling protobuf. But I'll run the build one more time to be sure.
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.
nix-build -A pkgsCross.armv7l-hf-multiplatform.protobuf
is now failing with a not found
rather than a exec format error
for protoc (the latter would have been what I expected. I'll investigate in a few hours.
|
||
enableParallelBuilding = true; | ||
|
||
doCheck = true; | ||
|
||
dontDisableStatic = true; |
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 option is only applicable to the default configurePhase
:
nixpkgs/pkgs/stdenv/generic/setup.sh
Lines 981 to 986 in 2ef110a
# By default, disable static builds. | |
if [ -z "${dontDisableStatic:-}" ]; then | |
if [ -f "$configureScript" ] && grep -q enable-static "$configureScript"; then | |
configureFlags="--disable-static $configureFlags" | |
fi | |
fi |
I would check if static libraries are still present and remove this line. In fact we should compare what files are present in the old build result vs the new.
buildInputs = [ zlib ]; | ||
configureFlags = if buildProtobuf == null then [] else [ "--with-protoc=${buildProtobuf}/bin/protoc" ]; | ||
|
||
enableParallelBuilding = true; |
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 line is not needed for cmake builds, as it is the default there.
|
Could you please resolve the conversations and explicitly approve. That way I know when a PR is ready for staging. Thanks! |
--replace 'tmpnam(b)' '"'$TMPDIR'/foo"' | ||
''; | ||
patches = | ||
[ ./protobuf-cmake.patch ] |
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.
Could you add a comment and link to upstream issue/PR?
let | ||
mkProtobufDerivation = buildProtobuf: stdenv: stdenv.mkDerivation { | ||
stdenv.mkDerivation rec { | ||
# make sure you test also -A pythonPackages.protobuf |
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.
Maybe add
passthru = {
tests = {
python = python3.pkgs.protobuf;
};
};
Ofborg will then check the python module automatically.
I marked this as stale due to inactivity. → More info |
This has been implemented in #169497. |
Motivation for this change
Protobuf has both cmake and autoconf/Make based build systems. The CMake build system will install both pkgconfig and cmake packages for other builds using protobuf to import, while the autoconf build system only installs the pkgconfig files.
In particular, this is a prerequisite for packaging the onnx library
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)