Skip to content

Commit

Permalink
EXP: [C++] Require C++20
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Feb 6, 2025
1 parent deccce1 commit 394fc03
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion c_glib/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
project('arrow-glib', 'c', 'cpp',
default_options: [
'c_std=c99',
'cpp_std=c++17',
'cpp_std=c++20',
],
license: 'Apache-2.0',
# Debian:
Expand Down
2 changes: 1 addition & 1 deletion ci/appveyor-cpp-build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ cmake -G "%GENERATOR%" %ARROW_CMAKE_ARGS% ^
-DARROW_WITH_ZSTD=ON ^
-DCMAKE_BUILD_TYPE="Release" ^
-DCMAKE_CXX_FLAGS_RELEASE="/MD /Od /UNDEBUG" ^
-DCMAKE_CXX_STANDARD=17 ^
-DCMAKE_CXX_STANDARD=20 ^
-DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX%\Library ^
-DCMAKE_UNITY_BUILD=ON ^
-DCMAKE_VERBOSE_MAKEFILE=OFF ^
Expand Down
4 changes: 2 additions & 2 deletions ci/scripts/cpp_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ if [ "${ARROW_EMSCRIPTEN:-OFF}" = "ON" ]; then
-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE:-OFF} \
-DCMAKE_C_FLAGS="${CFLAGS:-}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS:-}" \
-DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-17}" \
-DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-20}" \
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR:-lib} \
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-${ARROW_HOME}} \
-DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD:-OFF} \
Expand Down Expand Up @@ -216,7 +216,7 @@ else
-DCMAKE_VERBOSE_MAKEFILE=${CMAKE_VERBOSE_MAKEFILE:-OFF} \
-DCMAKE_C_FLAGS="${CFLAGS:-}" \
-DCMAKE_CXX_FLAGS="${CXXFLAGS:-}" \
-DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-17}" \
-DCMAKE_CXX_STANDARD="${CMAKE_CXX_STANDARD:-20}" \
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR:-lib} \
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX:-${ARROW_HOME}} \
-DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD:-OFF} \
Expand Down
6 changes: 3 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -553,10 +553,10 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARROW_CXXFLAGS}")
# C++ specific flags.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CXX_COMMON_FLAGS} ${ARROW_CXXFLAGS}")

# Remove --std=c++17 to avoid errors from C compilers
string(REPLACE "-std=c++17" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
# Remove -std=c++20 to avoid errors from C compilers
string(REPLACE "-std=c++20" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})

# Add C++-only flags, like -std=c++17
# Add C++-only flags, like -std=c++20
set(CMAKE_CXX_FLAGS "${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}")

# ASAN / TSAN / UBSAN
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmake_modules/GandivaAddBitcode.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# Create bitcode for the given source file.
function(gandiva_add_bitcode SOURCE)
set(CLANG_OPTIONS -std=c++17)
set(CLANG_OPTIONS -std=c++20)
if(MSVC)
# "19.20" means that it's compatible with Visual Studio 16 2019.
# We can update this to "19.30" when we dropped support for Visual
Expand Down
8 changes: 4 additions & 4 deletions cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,12 @@ endif()

# This ensures that things like c++17 get passed correctly
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
elseif(${CMAKE_CXX_STANDARD} VERSION_LESS 17)
message(FATAL_ERROR "Cannot set a CMAKE_CXX_STANDARD smaller than 17")
set(CMAKE_CXX_STANDARD 20)
elseif(${CMAKE_CXX_STANDARD} VERSION_LESS 20)
message(FATAL_ERROR "Cannot set a CMAKE_CXX_STANDARD smaller than 20")
endif()

# We require a C++17 compliant compiler
# We require a C++20 compliant compiler
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# ARROW-6848: Do not use GNU (or other CXX) extensions
Expand Down
4 changes: 2 additions & 2 deletions cpp/examples/minimal_build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ option(ARROW_LINK_SHARED "Link to the Arrow shared library" ON)
find_package(Arrow REQUIRED)

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
endif()

# We require a C++17 compliant compiler
# We require a C++20 compliant compiler
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT CMAKE_BUILD_TYPE)
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/minimal_build/run_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ echo

rm -rf $EXAMPLE_BUILD_DIR
mkdir -p $EXAMPLE_BUILD_DIR
${CXX:-c++} -std=c++17 \
${CXX:-c++} -std=c++20 \
-o $EXAMPLE_BUILD_DIR/arrow-example \
$EXAMPLE_DIR/example.cc \
$(PKG_CONFIG_PATH=$ARROW_BUILD_DIR/lib/pkgconfig \
Expand Down
4 changes: 2 additions & 2 deletions cpp/examples/parquet/parquet_arrow/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ option(PARQUET_LINK_SHARED "Link to the Parquet shared library" ON)

# This ensures that things like -std=gnu++... get passed correctly
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
endif()

# We require a C++17 compliant compiler
# We require a C++20 compliant compiler
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Look for installed packages the system
Expand Down
2 changes: 1 addition & 1 deletion cpp/examples/tutorial_examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ project(ArrowTutorialExamples)

find_package(ArrowDataset)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wextra")

set(CMAKE_BUILD_TYPE Release)
Expand Down
6 changes: 2 additions & 4 deletions cpp/src/arrow/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ namespace internal {

/// Like std::string_view::starts_with in C++20
inline bool StartsWith(std::string_view s, std::string_view prefix) {
return s.length() >= prefix.length() &&
(s.empty() || s.substr(0, prefix.length()) == prefix);
return s.starts_with(prefix);
}

/// Like std::string_view::ends_with in C++20
inline bool EndsWith(std::string_view s, std::string_view suffix) {
return s.length() >= suffix.length() &&
(s.empty() || s.substr(s.length() - suffix.length()) == suffix);
return s.ends_with(suffix);
}

/// \brief Split a string with a delimiter
Expand Down
2 changes: 1 addition & 1 deletion dev/release/verify-apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pushd build/minimal_build
cmake .
make -j$(nproc)
./arrow-example
c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++17
c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++20
./arrow-example
popd
echo "::endgroup::"
Expand Down
2 changes: 1 addition & 1 deletion dev/release/verify-yum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pushd build/minimal_build
${cmake_command} .
make -j$(nproc)
./arrow-example
c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++17
c++ -o arrow-example example.cc $(pkg-config --cflags --libs arrow) -std=c++20
./arrow-example
popd
echo "::endgroup::"
Expand Down
2 changes: 1 addition & 1 deletion dev/tasks/conda-recipes/arrow-cpp/build-arrow.bat
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ cmake -G "Ninja" ^
-DBUILD_SHARED_LIBS=ON ^
-DBoost_NO_BOOST_CMAKE=ON ^
-DCMAKE_BUILD_TYPE=release ^
-DCMAKE_CXX_STANDARD=17 ^
-DCMAKE_CXX_STANDARD=20 ^
-DCMAKE_INSTALL_PREFIX="%LIBRARY_PREFIX%" ^
-DCMAKE_UNITY_BUILD=ON ^
-DLLVM_TOOLS_BINARY_DIR="%LIBRARY_BIN%" ^
Expand Down
2 changes: 1 addition & 1 deletion dev/tasks/conda-recipes/arrow-cpp/build-arrow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ cmake -GNinja \
-DARROW_WITH_ZSTD=ON \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=release \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_INSTALL_LIBDIR=lib \
-DCMAKE_INSTALL_PREFIX=$PREFIX \
-DLLVM_TOOLS_BINARY_DIR=$PREFIX/bin \
Expand Down
2 changes: 1 addition & 1 deletion dev/tasks/homebrew-formulae/apache-arrow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def install
return 0;
}
EOS
system ENV.cxx, "test.cpp", "-std=c++17", "-I#{include}", "-L#{lib}", "-larrow", "-o", "test"
system ENV.cxx, "test.cpp", "-std=c++20", "-I#{include}", "-L#{lib}", "-larrow", "-o", "test"
system "./test"
end
end
4 changes: 2 additions & 2 deletions docs/source/java/cdata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ without writing JNI bindings ourselves.
include = {
"CDataCppBridge.h"
},
compiler = {"cpp17"},
compiler = {"cpp20"},
linkpath = {"/arrow/cpp/build/debug/"},
link = {"arrow"}
)
Expand Down Expand Up @@ -436,7 +436,7 @@ CMakeLists.txt definition file:
find_package(Arrow REQUIRED)
message(STATUS "Arrow version: ${ARROW_VERSION}")
include_directories(${JNI_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(cdatacpptojava PRIVATE Arrow::arrow_shared)
target_link_libraries(cdatacpptojava PRIVATE ${JNI_LIBRARIES})
Expand Down
2 changes: 1 addition & 1 deletion docs/source/python/integration/extending.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ To build this module, you will need a slightly customized ``setup.py`` file
ext.library_dirs.extend(pa.get_library_dirs())
if os.name == 'posix':
ext.extra_compile_args.append('-std=c++17')
ext.extra_compile_args.append('-std=c++20')
setup(ext_modules=ext_modules)
Expand Down
2 changes: 1 addition & 1 deletion matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function(build_arrow)

endfunction()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)

set(MLARROW_VERSION "20.0.0-SNAPSHOT")
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" MLARROW_BASE_VERSION "${MLARROW_VERSION}")
Expand Down
2 changes: 1 addition & 1 deletion python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ endif()
# For any C code, use the same flags.
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")

# Add C++-only flags, like -std=c++17
# Add C++-only flags, like -std=c++20
set(CMAKE_CXX_FLAGS "${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}")

message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
Expand Down
4 changes: 2 additions & 2 deletions python/pyarrow/tests/test_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
here = os.path.dirname(os.path.abspath(__file__))
test_ld_path = os.environ.get('PYARROW_TEST_LD_PATH', '')
if os.name == 'posix':
compiler_opts = ['-std=c++17']
compiler_opts = ['-std=c++20']
elif os.name == 'nt':
compiler_opts = ['-D_ENABLE_EXTENDED_ALIGNED_STORAGE', '/std:c++17']
compiler_opts = ['-D_ENABLE_EXTENDED_ALIGNED_STORAGE', '/std:c++20']
else:
compiler_opts = []

Expand Down

0 comments on commit 394fc03

Please sign in to comment.