Skip to content

Commit

Permalink
build: Use C++20 and dynamically link the C++ standard library (#1572)
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>
Co-authored-by: Johan Mabille <[email protected]>
  • Loading branch information
jjerphan and JohanMabille authored Jun 3, 2024
1 parent 221e6a3 commit e0aa4ea
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.21) # TARGET_RUNTIME_DLLS
# Make the `project` command handle the version of the project.
cmake_policy(SET CMP0048 NEW)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# We do not need any compilers' extensions, so we disable them.
set(CMAKE_CXX_EXTENSIONS OFF)
Expand Down
3 changes: 1 addition & 2 deletions cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@
"hidden": true,
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_MAKE_PROGRAM": "make",
"STATIC_LINK_STD_LIB": "OFF"
"CMAKE_MAKE_PROGRAM": "make"
},
"environment": {"cmakepreset_expected_host_system": "Darwin"}
},
Expand Down
30 changes: 0 additions & 30 deletions cpp/arcticdb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ option(TEST "Build all tests." ON)
option(BUILD_WITH_REMOTERY "Build ArcticDB with Remotery (used for performance analysis)" OFF)
option(SSL_LINK "Link against SSL libraries." ON)
option(HIDE_LINKED_SYMBOLS "Passed `exclude-libs` through to linker, ensuring linked library symbols are not exported. Shrinks binary size." ON)
option(STATIC_LINK_STD_LIB "Statically link the C++ standard libraries" ON)

find_package(GTest CONFIG REQUIRED)
include(CTest)
Expand Down Expand Up @@ -64,7 +63,6 @@ else()
# https://conda-forge.org/docs/maintainer/knowledge_base.html#newer-c-features-with-old-sdk
add_compile_definitions(_LIBCPP_DISABLE_AVAILABILITY)

SET(STATIC_LINK_STD_LIB OFF)
SET(HIDE_LINKED_SYMBOLS OFF)

find_package(pybind11 REQUIRED)
Expand Down Expand Up @@ -511,34 +509,6 @@ if (WIN32)
/external:I${CMAKE_SOURCE_DIR}/third_party
/Zc:__cplusplus #needed to get the correct __cplusplus macro value
)
else()
if (STATIC_LINK_STD_LIB)
message("Statically linking standard libraries")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "Statically linking standard libraries with CLANG is (currently) not supported")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(standard_libraries
-static-libgcc
-static-libstdc++
)
else()
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
else()
message("Dynamically linking standard libraries")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(standard_libraries
stdc++
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(standard_libraries
stdc++
gcc
)
else()
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
endif()
endif()
endif()


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/operations.cpp b/src/operations.cpp
index ca2fff3be..e22967e88 100644
--- a/src/operations.cpp
+++ b/src/operations.cpp
@@ -70,7 +70,7 @@

#include <unistd.h>
#include <fcntl.h>
-#if _POSIX_C_SOURCE < 200809L
+#if !defined(BOOST_FILESYSTEM_HAS_POSIX_AT_APIS)
#include <utime.h>
#endif
#include <limits.h>
16 changes: 16 additions & 0 deletions cpp/third_party/vcpkg_overlays/boost-filesystem/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Automatically generated by scripts/boost/generate-ports.ps1

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO boostorg/filesystem
REF boost-1.80.0
SHA512 9e8c3151f65af1242014987b10009c6b0467d0da3da1813e709a7238669a54a7256097ec205e3ff430b3b00c8a29d06a7b666562c3285e4d6fb5e73857e24604
HEAD_REF master
PATCHES
5864f397ccad30f6e73221b90bdac57a303b9752.patch
)

include(${CURRENT_HOST_INSTALLED_DIR}/share/boost-build/boost-modular-build.cmake)
boost_modular_build(SOURCE_PATH ${SOURCE_PATH})
include(${CURRENT_INSTALLED_DIR}/share/boost-vcpkg-helpers/boost-modular-headers.cmake)
boost_modular_headers(SOURCE_PATH ${SOURCE_PATH})
86 changes: 86 additions & 0 deletions cpp/third_party/vcpkg_overlays/boost-filesystem/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"$comment": "When changing this file also update and run scripts/boost/generate-ports.ps1",
"name": "boost-filesystem",
"version": "1.80.0",
"port-version": 1,
"description": "Boost filesystem module",
"homepage": "https://github.com/boostorg/filesystem",
"license": "BSL-1.0",
"supports": "!uwp",
"dependencies": [
{
"name": "boost-assert",
"version>=": "1.80.0#1"
},
{
"name": "boost-atomic",
"version>=": "1.80.0#1"
},
{
"name": "boost-build",
"host": true,
"version>=": "1.80.0#2"
},
{
"name": "boost-config",
"version>=": "1.80.0#1"
},
{
"name": "boost-container-hash",
"version>=": "1.80.0#1"
},
{
"name": "boost-core",
"version>=": "1.80.0#1"
},
{
"name": "boost-detail",
"version>=": "1.80.0#1"
},
{
"name": "boost-io",
"version>=": "1.80.0#1"
},
{
"name": "boost-iterator",
"version>=": "1.80.0#1"
},
{
"name": "boost-modular-build-helper",
"host": true,
"version>=": "1.80.0#2"
},
{
"name": "boost-predef",
"version>=": "1.80.0#1"
},
{
"name": "boost-smart-ptr",
"version>=": "1.80.0#1"
},
{
"name": "boost-system",
"version>=": "1.80.0#1"
},
{
"name": "boost-throw-exception",
"version>=": "1.80.0#1"
},
{
"name": "boost-type-traits",
"version>=": "1.80.0#1"
},
{
"name": "boost-vcpkg-helpers",
"version>=": "1.80.0#1"
},
{
"name": "boost-winapi",
"version>=": "1.80.0#1"
},
{
"name": "vcpkg-cmake",
"host": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 62fa03bc0c9eeb0b04f055bdb98847c6cf1b9908 Mon Sep 17 00:00:00 2001
From: Julien Jerphanion <[email protected]>
Date: Wed, 15 May 2024 10:21:39 +0200
Subject: [PATCH] Include missing headers

Signed-off-by: Julien Jerphanion <[email protected]>
---
folly/system/AtFork.h | 3 +++
1 file changed, 3 insertions(+)

diff --git a/folly/system/AtFork.h b/folly/system/AtFork.h
index da318ac01..009204465 100644
--- a/folly/system/AtFork.h
+++ b/folly/system/AtFork.h
@@ -21,6 +21,9 @@
#include <list>
#include <map>
#include <mutex>
+#include <stdexcept>
+#include <cstdlib>
+#include <system_error>

#include <folly/Function.h>

--
2.44.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From bbee87997214e3ac5a54ed0ae6a6915e176b3bf1 Mon Sep 17 00:00:00 2001
From: Julien Jerphanion <[email protected]>
Date: Wed, 15 May 2024 11:23:51 +0200
Subject: [PATCH] Workaround demangling callback

Signed-off-by: Julien Jerphanion <[email protected]>
---
folly/Demangle.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/folly/Demangle.cpp b/folly/Demangle.cpp
index 1af58f20c..b6c13ca6b 100644
--- a/folly/Demangle.cpp
+++ b/folly/Demangle.cpp
@@ -58,7 +58,8 @@ static constexpr auto cxxabi_demangle = static_cast<char* (*)(...)>(nullptr);
//
// in contrast with cxxabi, where there are certainly other referenced symbols

-#if __has_include(<demangle.h>)
+// See: https://github.com/microsoft/vcpkg/issues/25214#issuecomment-1154172978
+#if 0 // __has_include(<demangle.h>)

static constexpr auto liberty_demangle = cplus_demangle_v3_callback;

--
2.44.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
From 74ee7653eb77a0b39852c2a676cf1a064e1676b8 Mon Sep 17 00:00:00 2001
From: Julien Jerphanion <[email protected]>
Date: Wed, 15 May 2024 14:11:16 +0200
Subject: [PATCH] Set FOLLY_HAVE_SO_TIMESTAMPING to 0

Signed-off-by: Julien Jerphanion <[email protected]>
---
folly/net/NetOps.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/folly/net/NetOps.h b/folly/net/NetOps.h
index 23f23c145..7790848e9 100644
--- a/folly/net/NetOps.h
+++ b/folly/net/NetOps.h
@@ -120,7 +120,8 @@ struct mmsghdr {
#define FOLLY_HAVE_MSG_ERRQUEUE 1
#ifdef SCM_TIMESTAMPING
#ifndef FOLLY_HAVE_SO_TIMESTAMPING
-#define FOLLY_HAVE_SO_TIMESTAMPING 1
+// See: https://github.com/conda-forge/folly-feedstock/blob/1f44286ea5c104cfead0d5cdbe85b52bde2b3066/recipe/build.sh#L10-L11C30
+#define FOLLY_HAVE_SO_TIMESTAMPING 0
#endif
#ifndef TCP_ZEROCOPY_RECEIVE
#define TCP_ZEROCOPY_RECEIVE 35
--
2.44.0

26 changes: 26 additions & 0 deletions cpp/third_party/vcpkg_overlays/folly/0004-Do-not-use-PRId64.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
From 4f1f3f4646c6f68040ea78a8be4b7887076d857c Mon Sep 17 00:00:00 2001
From: Julien Jerphanion <[email protected]>
Date: Wed, 15 May 2024 14:47:36 +0200
Subject: [PATCH] Do not use PRId64

Signed-off-by: Julien Jerphanion <[email protected]>
---
folly/Benchmark.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/folly/Benchmark.cpp b/folly/Benchmark.cpp
index ffe4b41e2..6bbb40312 100644
--- a/folly/Benchmark.cpp
+++ b/folly/Benchmark.cpp
@@ -500,7 +500,7 @@ class BenchmarkResultsPrinter {
break;
case UserMetric::Type::CUSTOM:
default:
- printf(" %*" PRId64, int(name.length()), ptr->value);
+ printf(" %*lld", (long long) int(name.length()), ptr->value);
}
} else {
printf(" %*s", int(name.length()), "NaN");
--
2.44.0

4 changes: 4 additions & 0 deletions cpp/third_party/vcpkg_overlays/folly/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ vcpkg_from_github(
fix-deps.patch
dont-inherit-cpp-version.patch
ignore-uninitialized-local-variable-used.patch
0001-Include-missing-headers.patch
0002-Workaround-demangling-callback.patch
0003-Set-FOLLY_HAVE_SO_TIMESTAMPING-to-0.patch
0004-Do-not-use-PRId64.patch
)

file(REMOVE "${SOURCE_PATH}/CMake/FindFmt.cmake")
Expand Down

0 comments on commit e0aa4ea

Please sign in to comment.