Skip to content
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

Require C++17 #9481

Closed
wants to merge 17 commits into from
Closed

Require C++17 #9481

wants to merge 17 commits into from

Conversation

pdillinger
Copy link
Contributor

@pdillinger pdillinger commented Feb 1, 2022

Summary: Drop support for some old compilers by requiring C++17 standard
(or higher). See #9388

First modification based on this is to remove some conditional compilation in slice.h (also
better for ODR)

Also in this PR:

  • Fix some Makefile formatting that seems to affect ASSERT_STATUS_CHECKED config in
    some cases
  • Add c_test to NON_PARALLEL_TEST in Makefile
  • Fix a clang-analyze reported "potential leak" in lru_cache_test
  • Better "compatibility" definition of DEFINE_uint32 for old versions of gflags
  • Fix a linking problem with shared libraries in Makefile (./random_test: error while loading shared libraries: librocksdb.so.6.29: cannot open shared object file: No such file or directory)
  • Always set ROCKSDB_SUPPORT_THREAD_LOCAL and use thread_local (from C++11)
    • TODO in later PR: clean up that obsolete flag
  • Fix a cosmetic typo in c.h (Typo on variable name #9488)

Test Plan: CircleCI config substantially updated.

  • Upgrade to latest Ubuntu images for each release
  • Generally prefer Ubuntu 20, but keep a couple Ubuntu 16 builds with oldest supported
    compilers, to ensure compatibility
  • Remove .circleci/cat_ignore_eagain except for Ubuntu 16 builds, because this is to work
    around a kernel bug that should not affect anything but Ubuntu 16.
  • Remove designated gcc-9 build, because the default linux build now uses GCC 9 from
    Ubuntu 20.
  • Add some apt-key add to fix some apt "couldn't be verified" errors
  • Generally drop SKIP_LINK=1; work-around no longer needed
  • Generally add-apt-repository before apt-get update as manual testing indicated the
    reverse might not work.

Travis:

  • Use gcc-7 by default (remove specific gcc-7 and gcc-4.8 builds)
  • TODO in later PR: fix s390x "Assembler messages: Error: invalid switch -march=z14" failure

AppVeyor:

  • Completely dropped because we are dropping VS2015 support and CircleCI covers
    VS >= 2017

Also local testing with old gflags (out of necessity when using ROCKSDB_NO_FBCODE=1).

Summary: Drop support for some old compilers by requiring C++17 standard
(or higher). See facebook#9388

Test Plan: CI config updated

TODO: finish sanitizing CircleCI config
Copy link
Contributor

@mrambacher mrambacher left a comment

Choose a reason for hiding this comment

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

This generally looks good to me.

For the Linux boxes, I wonder if using "-j$(nproc)" might be a better paradigm. The parallelism seems to inconsistent.

$(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++11 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS)
$(CXX) $(CXXFLAGS) $@.cc -o$@ ../librocksdb.a -I../include -O2 -std=c++17 $(PLATFORM_LDFLAGS) $(PLATFORM_CXXFLAGS) $(EXEC_LDFLAGS)
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if the examples do not specify a --std? Won't it build with the default for the compiler? And if that is less than 17, what will happen?

If we are requiring that std be set and be at least 17, then that probably also needs to be updated on the README/build instructions. If 17 is the lowest we are supporting (and most/all compilers default to it or higher), then I do not know this line is necessary.

- run: (mkdir build && cd build && cmake -DWITH_GFLAGS=1 .. && make V=1 -j20 && ctest -j20) 2>&1 | .circleci/cat_ignore_eagain
- run: (mkdir build && cd build && cmake -DWITH_GFLAGS=1 .. && make V=1 -j20 && ctest -j20)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a comment (could be in the PR and not the config file) as to why you are dropping the redirection everywhere?

@pdillinger
Copy link
Contributor Author

I wonder if using "-j$(nproc)" might be a better paradigm

I'm not touching this at this time.

What happens if the examples do not specify a --std? Won't it build with the default for the compiler? And if that is less than 17, what will happen?

You'll get errors like undefined std::string_view

@pdillinger pdillinger marked this pull request as ready for review February 2, 2022 17:45
@facebook-github-bot
Copy link
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

resource_class: 2xlarge
steps:
- pre-steps
- install-gflags
- upgrade-cmake
- run: (mkdir build && cd build && cmake -DWITH_GFLAGS=1 .. && make V=1 -j20 && ctest -j20) 2>&1 | .circleci/cat_ignore_eagain
- run: (mkdir build && cd build && cmake -DWITH_GFLAGS=1 .. && make V=1 -j20 && ctest -j20)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be -j 32? Every other use of 2xlarge used -j32

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is not about parallelism in CircleCI

@@ -338,7 +340,7 @@ jobs:
- pre-steps
- install-gflags
- install-benchmark
- run: (mkdir build && cd build && cmake -DWITH_GFLAGS=1 -DWITH_BENCHMARK=1 .. && make V=1 -j20 && ctest -j20) 2>&1 | .circleci/cat_ignore_eagain
- run: (mkdir build && cd build && cmake -DWITH_GFLAGS=1 -DWITH_BENCHMARK=1 .. && make V=1 -j20 && ctest -j20)
Copy link
Contributor

Choose a reason for hiding this comment

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

-j32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is not about parallelism in CircleCI

resource_class: xlarge
steps:
- pre-steps
- install-benchmark
- run: DEBUG_LEVEL=0 make microbench 2>&1 | .circleci/cat_ignore_eagain
- run: DEBUG_LEVEL=0 make microbench
Copy link
Contributor

Choose a reason for hiding this comment

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

No make parallelism?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is not about parallelism in CircleCI

resource_class: large
steps:
- pre-steps
- install-gflags
- run:
name: "Build examples"
command: |
OPT=-DTRAVIS V=1 make -j4 static_lib && cd examples && make -j4 | ../.circleci/cat_ignore_eagain
OPT=-DTRAVIS V=1 make -j4 static_lib && cd examples && make -j4
Copy link
Contributor

Choose a reason for hiding this comment

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

-j 8?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR is not about parallelism in CircleCI

CMakeLists.txt Outdated
if(HAVE_THREAD_LOCAL)
add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
endif()
# Thread-local is part of C++11 (TODO: clean up this flag)
Copy link
Contributor

Choose a reason for hiding this comment

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

C++17 or part of the C++ standard. (It is a bit confusing to say C++11 when we say we support 17 only.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

C++11 is factually accurate. I'm pointing out that the check has been effectively obsolete for a long time.

@@ -50,7 +50,7 @@ to build a portable binary, add `PORTABLE=1` before your make commands, like thi
## Supported platforms

* **Linux - Ubuntu**
* Upgrade your gcc to version at least 4.8 to get C++11 support.
* Upgrade your gcc to version at least 7 to get C++17 support.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this mention clang?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not the default compiler on Ubuntu

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood that it is not the default compiler. Nowhere in INSTALL does it say we support clang (on any platform) and what the minimum clang version is. Can we add that somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's near the top, "We do depend on newer gcc/clang with C++17 support (GCC >= 7, Clang >= 5)."

@@ -44,11 +41,9 @@ class Slice {
/* implicit */
Slice(const std::string& s) : data_(s.data()), size_(s.size()) {}

#ifdef __cpp_lib_string_view
// Create a slice that refers to the same contents as "sv"
/* implicit */
Slice(std::string_view sv) : data_(sv.data()), size_(sv.size()) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this pass in a const std::string_view& ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@facebook-github-bot
Copy link
Contributor

@pdillinger has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@pdillinger has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@pdillinger has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

hx235 added a commit to hx235/rocksdb that referenced this pull request Feb 7, 2022
pdillinger added a commit to pdillinger/rocksdb that referenced this pull request Feb 7, 2022
Summary: After facebook#9481, we are using newer default compiler for
build-format-compatible CircleCI nightly job, which fails on building
2.2.fb.branch branch because it tries to use a pre-compiled libsnappy.a
that is checked into the repo (!). This works around that by setting
SNAPPY_LDFLAGS=-lsnappy, which is only understood by such old versions.

Test Plan: Run check_format_compatible.sh on Ubuntu 20 AWS machine,
watch nightly run
facebook-github-bot pushed a commit that referenced this pull request Feb 8, 2022
Summary:
... seen only in internal clang-analyze runs after #9481

* Mostly, this works around falsely reported leaks by using
std::unique_ptr in some places where clang-analyze was getting
confused. (I didn't see any changes in C++17 that could make our Status
implementation leak memory.)
* Also fixed SetBGError returning address of a stack variable.
* Also fixed another false null deref report by adding an assert.

Also, use SKIP_LINK=1 to speed up `make analyze`

Pull Request resolved: #9515

Test Plan:
Was able to reproduce the reported errors locally and verify
they're fixed (except SetBGError). Otherwise, existing tests

Reviewed By: hx235

Differential Revision: D34054630

Pulled By: pdillinger

fbshipit-source-id: 38600ef3da75ddca307dff96b7a1a523c2885c2e
facebook-github-bot pushed a commit that referenced this pull request Feb 8, 2022
Summary:
After #9481, we are using newer default compiler for
build-format-compatible CircleCI nightly job, which fails on building
2.2.fb.branch branch because it tries to use a pre-compiled libsnappy.a
that is checked into the repo (!). This works around that by setting
SNAPPY_LDFLAGS=-lsnappy, which is only understood by such old versions.

Pull Request resolved: #9517

Test Plan:
Run check_format_compatible.sh on Ubuntu 20 AWS machine,
watch nightly run

Reviewed By: hx235

Differential Revision: D34055561

Pulled By: pdillinger

fbshipit-source-id: 45f9d428dd082f026773bfa8d9dd4dad66fc9378
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants