Skip to content

introduce single CMake script build all packages #129

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

Merged

Conversation

syuu1228
Copy link
Contributor

@syuu1228 syuu1228 commented Jun 7, 2024

This introduces single CMake script to build all packages and non-package build with same result, including shared library SONAME and versioning.

Complicated shellscripting to build package build are no longer required, everything can be build with "cmake -S . -B build && cmake --build build".

Note that there is a limitation, this requires a dummy C code to call libscylla-cpp-driver function.
It is because this rebuild libraries with C Linker on CMake. The dummy C code is located at dummy/dummy.c.

CMakeList.txt is now fully re-written without unrelated codes. And to build Rust code easier, imported CMakeRust project: https://github.com/Devolutions/CMakeRust

And also FindLibClang.cmake from cpp2py:
https://github.com/TRIQS/cpp2py/blob/master/cmake/FindLibClang.cmake

Both included few patches since little bit outdated, and have few bugs.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have enabled appropriate tests in .github/workflows/build.yml in gtest_filter.
  • I have enabled appropriate tests in .github/workflows/cassandra.yml in gtest_filter.

@syuu1228
Copy link
Contributor Author

syuu1228 commented Jun 7, 2024

Build passed on following environments:

  • RPM
    • rocky-8-x86_64
    • rocky-9-x86_64
    • fedora-38-x86_64
    • fedora-39-x86_64
    • fedora-40-x86_64
    • fedora-rawhide-x86_64
  • DEB
    • Ubuntu x86_64
      • focal (20.04), jammy (22.04), mantic (23.04), noble (24.04), oracular (24
        .10)
    • Debian x86_64
      • bullseye (11), bookworm (12), trixie (13), sid (unstable)
  • HomeBrew
    • macOS Sonoma 14.5/arm64

Build failed on following environments:

  • DEB
    • Ubuntu x86_64
      • bionic (18.04)
    • Debian x86_64
      • buster (10)

These two are outdated releases, does not have newer packages for build dependencies.
I think we just can drop them from support list.

@wprzytula
Copy link
Collaborator

@syuu1228 CI is failing because libclang is not found.

@syuu1228 syuu1228 force-pushed the build_all_packages_in_single_cmake branch 3 times, most recently from 64d3280 to 67f1bd9 Compare June 10, 2024 07:54
@wprzytula
Copy link
Collaborator

wprzytula commented Jun 12, 2024

Waiting with review until CI stops failing.

@syuu1228 syuu1228 force-pushed the build_all_packages_in_single_cmake branch 5 times, most recently from 5af6a7f to a92c992 Compare June 17, 2024 19:40
@syuu1228
Copy link
Contributor Author

Rewrited almost all code, now CI can pass.
Here are change lists:

  • Clean up of CMakeLists.txt broke INTEGRATION_TESTS so I reverted this code, and re-implemented same feature without cleanup.
  • Fixed dependencies on INTEGRATION_TESTS Github Actions
  • On previous version, a shared library builds on CMake with C linker, which can set SONAME and do versioning natively.
    But I have found that exported symbols are very different, when comparing a shared library built on CMake vs built on Cargo.
    Seems like CMake one including all private functions, Cargo one is not.
    So I stopped building a shared library on CMake, implemented library versioning on CMake instead (it does almost same thing with versioning.sh).
  • Dropped FindLibClang.cmake, since it cause error on some environment, even cargo build can run without the error on same environment.

@wprzytula wprzytula requested review from Lorak-mmk and wprzytula June 18, 2024 08:04
@syuu1228
Copy link
Contributor Author

Build failed on following environments:

  • DEB

    • Ubuntu x86_64

      • bionic (18.04)
    • Debian x86_64

      • buster (10)

These two are outdated releases, does not have newer packages for build dependencies. I think we just can drop them from support list.

Fixed the build failure, now build passed on these distros.

@Lorak-mmk
Copy link
Collaborator

Afaik apart from using prebuiilt libraries (.so + .h) it's popular in C/C++ to use submodules (or something similar) and CMake's add_subdirectory to build dependency alongside main project. It was one of the goals to be mostly compatible with cpp-driver, which allowed such usage. Example: I used cpp-driver in this manner during ZPP project in a more modern C++ wrapper: https://github.com/scylla-zpp-blas/scylla_modern_cpp_driver/blob/a9ea3ca5b2d2921af497164994d64ddf09e52fd9/CMakeLists.txt#L6

Is such usage still possible after your changes? I didn't review the changes yet, but I see fragments:

#---------------
# Policies
#---------------

if(POLICY CMP0074)
  cmake_policy(SET CMP0074 NEW)
endif()

if (POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif()

or

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

I can't say I know CMake that well, so I'm not sure: is this going to be a problem?

@mykaul
Copy link

mykaul commented Jun 30, 2024

What's the status of this PR?

@roydahan
Copy link
Collaborator

roydahan commented Jul 8, 2024

@Lorak-mmk can you please review this one?

@Lorak-mmk
Copy link
Collaborator

@Lorak-mmk can you please review this one?

I'd prefer to get answer to my question first, because it may affect the PR

@syuu1228
Copy link
Contributor Author

Afaik apart from using prebuiilt libraries (.so + .h) it's popular in C/C++ to use submodules (or something similar) and CMake's add_subdirectory to build dependency alongside main project. It was one of the goals to be mostly compatible with cpp-driver, which allowed such usage. Example: I used cpp-driver in this manner during ZPP project in a more modern C++ wrapper: https://github.com/scylla-zpp-blas/scylla_modern_cpp_driver/blob/a9ea3ca5b2d2921af497164994d64ddf09e52fd9/CMakeLists.txt#L6

Is such usage still possible after your changes?

I'm not good at CMake so maybe I'm missing something, but I guess there is no reason to prevent such usage.
I tested this branch with scylla-zpp-blas/scylla_modern_cpp_driver, at least I able to build it as follows:

$ cmake -B build -S . -G Ninja
-- The C compiler identification is GNU 14.1.1
-- The CXX compiler identification is GNU 14.1.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Cargo Home: /home/syuu/.cargo
-- Rust Compiler Version: 1.79.0
-- Found OpenSSL: /usr/lib64/libssl.so
-- OpenSSL version: v
CMake Deprecation Warning at lib/cpp-driver/cmake/ClangFormat.cmake:4 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
Call Stack (most recent call first):
  lib/cpp-driver/CMakeLists.txt:95 (include)


-- Found CLANG_FORMAT: /usr/bin/clang-format
-- Driver version: 2.16.1
-- Using std::atomic implementation for atomic operations
-- Found PkgConfig: /usr/bin/pkg-config (found version "2.1.1")
-- Using akrzemi's `optional` implementation
CMake Deprecation Warning at lib/cpp-driver/src/third_party/sparsehash/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Checking to see if CXX compiler accepts flag -std=c++11
-- Checking to see if CXX compiler accepts flag -std=c++11 - yes
-- Using hash header <functional> and namespace "std"
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for memcpy
-- Looking for memcpy - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of long long
-- Check size of long long - done
-- Check size of uint16_t
-- Check size of uint16_t - done
-- Check size of u_int16_t
-- Check size of u_int16_t - done
-- Check size of __uint16_t
-- Check size of __uint16_t - done
-- Looking for GRND_NONBLOCK
-- Looking for GRND_NONBLOCK - found
-- Looking for timerfd_create
-- Looking for timerfd_create - found
-- Looking for SO_NOSIGPIPE
-- Looking for SO_NOSIGPIPE - not found
-- Looking for sigtimedwait
-- Looking for sigtimedwait - found
-- Performing Test HAVE_BUILTIN_BSWAP32
-- Performing Test HAVE_BUILTIN_BSWAP32 - Success
-- Performing Test HAVE_BUILTIN_BSWAP64
-- Performing Test HAVE_BUILTIN_BSWAP64 - Failed
CASS INCLUDE:
-- Found Boost: /usr/lib64/cmake/Boost-1.83.0/BoostConfig.cmake (found suitable version "1.83.0", minimum required is "1.60.0") found components: system filesystem unit_test_framework
-- Configuring done (3.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/syuu/scylla_modern_cpp_driver/build
$ cd build/
$ ninja
[16/19] running cargo
   Compiling autocfg v1.1.0
   Compiling proc-macro2 v1.0.56
   Compiling libc v0.2.147
   Compiling unicode-ident v1.0.2
   Compiling quote v1.0.26
   Compiling cfg-if v1.0.0
   Compiling syn v1.0.98
   Compiling memchr v2.5.0
   Compiling log v0.4.17
   Compiling cc v1.0.73
   Compiling pin-project-lite v0.2.9
   Compiling thiserror v1.0.40
   Compiling pkg-config v0.3.25
   Compiling smallvec v1.9.0
   Compiling once_cell v1.13.1
   Compiling futures-core v0.3.21
   Compiling parking_lot_core v0.9.3
   Compiling serde v1.0.140
   Compiling futures-task v0.3.21
   Compiling futures-channel v0.3.21
   Compiling glob v0.3.0
   Compiling scopeguard v1.1.0
   Compiling futures-util v0.3.21
   Compiling prettyplease v0.2.4
   Compiling futures-sink v0.3.21
   Compiling minimal-lexical v0.2.1
   Compiling pin-utils v0.1.0
   Compiling futures-io v0.3.21
   Compiling libloading v0.7.3
   Compiling either v1.7.0
   Compiling tracing-core v0.1.30
   Compiling regex-syntax v0.6.27
   Compiling bytes v1.2.0
   Compiling static_assertions v1.1.0
   Compiling foreign-types-shared v0.1.1
   Compiling rustversion v1.0.8
   Compiling async-trait v0.1.57
   Compiling bindgen v0.65.1
   Compiling snap v1.0.5
   Compiling openssl v0.10.41
   Compiling foreign-types v0.3.2
   Compiling twox-hash v1.6.3
   Compiling iana-time-zone v0.1.47
   Compiling rustc-hash v1.1.0
   Compiling lazy_static v1.4.0
   Compiling shlex v1.1.0
   Compiling lazycell v1.3.0
   Compiling num-traits v0.2.15
   Compiling num-integer v0.1.45
   Compiling lock_api v0.4.7
   Compiling slab v0.4.7
   Compiling num-bigint v0.3.3
   Compiling tokio v1.29.1
   Compiling bitflags v1.3.2
   Compiling clang-sys v1.3.3
   Compiling unicode-segmentation v1.9.0
   Compiling ppv-lite86 v0.2.16
   Compiling peeking_take_while v0.1.2
   Compiling tokio-openssl v0.6.3
   Compiling nom v7.1.1
   Compiling lz4_flex v0.11.1
   Compiling heck v0.3.3
   Compiling hashbrown v0.12.3
   Compiling byteorder v1.4.3
   Compiling tracing-log v0.1.3
   Compiling sharded-slab v0.1.4
   Compiling syn v2.0.15
   Compiling itertools v0.11.0
   Compiling thread_local v1.1.4
   Compiling arc-swap v1.5.0
   Compiling ansi_term v0.12.1
   Compiling histogram v0.6.9
   Compiling strum v0.23.0
   Compiling machine-uid v0.2.0
   Compiling time v0.1.44
   Compiling which v4.2.5
   Compiling getrandom v0.2.7
   Compiling socket2 v0.4.9
   Compiling mio v0.8.8
   Compiling num_cpus v1.13.1
   Compiling signal-hook-registry v1.4.0
   Compiling openssl-sys v0.9.75
   Compiling parking_lot v0.12.1
   Compiling rand_core v0.6.3
   Compiling uuid v1.1.2
   Compiling dashmap v5.3.4
   Compiling socket2 v0.5.3
   Compiling rand_chacha v0.3.1
   Compiling rand_pcg v0.3.1
   Compiling regex-automata v0.1.10
   Compiling chrono v0.4.22
   Compiling regex v1.6.0
   Compiling rand v0.8.5
   Compiling matchers v0.1.0
   Compiling cexpr v0.6.0
   Compiling bigdecimal v0.2.2
   Compiling toml v0.5.9
   Compiling thiserror-impl v1.0.40
   Compiling tokio-macros v2.1.0
   Compiling futures-macro v0.3.21
   Compiling openssl-macros v0.1.0
   Compiling tracing-attributes v0.1.23
   Compiling scylla-macros v0.2.0 (https://github.com/scylladb/scylla-rust-driver.git?rev=40aaee6#40aaee6e)
   Compiling strum_macros v0.23.1
   Compiling num-derive v0.3.3
   Compiling proc-macro-crate v1.1.3
   Compiling num_enum_derive v0.6.1
   Compiling tracing v0.1.37
   Compiling tracing-subscriber v0.3.15
   Compiling num_enum v0.6.1
   Compiling futures-executor v0.3.21
   Compiling futures v0.3.21
   Compiling scylla-cpp-driver-rust v0.1.0 (/home/syuu/scylla_modern_cpp_driver/lib/cpp-driver/scylla-rust-wrapper)
   Compiling scylla-cql v0.0.8 (https://github.com/scylladb/scylla-rust-driver.git?rev=40aaee6#40aaee6e)
   Compiling scylla v0.9.0 (https://github.com/scylladb/scylla-rust-driver.git?rev=40aaee6#40aaee6e)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 12.84s
[19/19] Linking CXX executable tests/scmd_tests
$ ls
build.ninja     cmake_install.cmake             libscylla_modern_cpp_driver.so
CMakeCache.txt  lib                             tests
CMakeFiles      libscylla-cpp-driver.so.2.16.1

Note that following APIs causes undefined reference for unknown reason, I needed to comment out in the source code:

/usr/bin/ld: libscylla_modern_cpp_driver.so: undefined reference to `cass_future_wait_timed'
/usr/bin/ld: libscylla_modern_cpp_driver.so: undefined reference to `cass_statement_reset_parameters'
/usr/bin/ld: libscylla_modern_cpp_driver.so: undefined reference to `cass_batch_set_keyspace_n'

And it's not because of my patch, it caused on master branch as well.

I didn't review the changes yet, but I see fragments:

#---------------
# Policies
#---------------

if(POLICY CMP0074)
  cmake_policy(SET CMP0074 NEW)
endif()

if (POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif()

or

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

I can't say I know CMake that well, so I'm not sure: is this going to be a problem?

I did not added any of them, it exist on cpp-rust-driver and also cpp-driver.
What I modified is, dropped if(CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_TESTS) condition.
(Line 33 to line 211 of CMakeLists.txt are under the if condition).
Seems like it is added because only C++ based tests are using these parameters, but I needed it for the new build script.
So restored to original cpp-driver's behavior.

(BTW maybe I can move back some of the parameters to the if condition, since I initially trying to link libscylla-cpp-driver.so in CMake so I did some compiling/linking in CMake, but I stopped it now)

Copy link
Collaborator

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left few minor comments, apart from that LGTM - although I can't say that I reviewed the changes very carefully, cmake and build / packaging code is usually unreadable black magic to me.

I did verify that the project builds after the changes and that build directory contains all the libraries.

One advantage of this PR not mentioned in description is that now output from cargo is visible during cmake --build build. That's a nice QoL improvement, thank you!

@@ -23,7 +23,7 @@ jobs:
- name: Setup environment
run: |
sudo apt-get update
sudo apt-get install libssl1.1 libuv1-dev libkrb5-dev libc6-dbg
sudo apt-get install libssl-dev libuv1-dev libkrb5-dev pkg-config openssl ca-certificates clang cmake cargo libc6-dbg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md libssl-dev, pkg-config, openssl, clang, cmake and cargo should be installed by default.
Why is there a need to install them manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I did not realized most of the dependencies are preinstalled on Github Action instance.
Seems like we don't need to change dependencies at all, I reverted .github/workflows/*.yml changes.

sudo apt-get install libssl1.1 libuv1-dev libkrb5-dev libc6-dbg
sudo apt-get install libssl-dev libuv1-dev libkrb5-dev pkg-config openssl ca-certificates clang cmake cargo libc6-dbg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted this change too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between dist and packaging directories?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On previous version of this patch, I moved pkgconfig files to packaging/, since cpp-driver's CMakeLists.txt will install pkgconfig from the directory so we can reuse cpp-driver's CMake script fewer changes.

But I decided changing this, since packaging/ can be confusing with dist/.
On latest push, I deleted packaging/ and moved pkgconfig files to scylla-rust-wrapper/.
Because pkgconfig will be install in scylla-rust-wrapper/CMakeLists.txt.

syuu1228 added 2 commits July 16, 2024 22:09
Import CMakeRust which add support build Cargo project in CMake:
https://github.com/Devolutions/CMakeRust
Seems like this package is not necessary for building cpp-rust-driver,
dropping.
@syuu1228 syuu1228 force-pushed the build_all_packages_in_single_cmake branch from a92c992 to 29ac4ce Compare July 16, 2024 21:06
This introduces single CMake script to build all packages and non-package build with same result, including shared library SONAME and versioning.

Complicated shellscripting to build package build are no longer required,
everything can be build with "cmake -S . -B build && cmake --build build".
@syuu1228 syuu1228 force-pushed the build_all_packages_in_single_cmake branch from 29ac4ce to 493a379 Compare July 17, 2024 01:57
@roydahan
Copy link
Collaborator

@Lorak-mmk do you think we should wait for @wprzytula / @muzarski review or we can merge?

@wprzytula
Copy link
Collaborator

@Lorak-mmk do you think we should wait for @wprzytula / @muzarski review or we can merge?

With my scarce knowledge of CMake, I doubt that my review would be beneficial in any way.

@Lorak-mmk Lorak-mmk merged commit 0cd7ca7 into scylladb:master Jul 22, 2024
5 checks passed
@muzarski muzarski mentioned this pull request Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants