Skip to content

Add support for C++20 modules #313

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
merged 42 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
64452a3
fix: replace C-style size_t with std::size_t
wravery Sep 12, 2024
1996b5a
chore(cleanup): remove support for experimental coroutines
wravery Sep 12, 2024
1d24695
chore(modules): try building internal headers as modules
wravery Sep 12, 2024
decc8e6
fix(cmake): update the check_coroutine_impl function
wravery Sep 12, 2024
1d3a536
fix(buiild): remove duplicate includes and specify C++20
wravery Sep 12, 2024
a9120e4
fix(modules): consistent Internal.Version module usage
wravery Sep 12, 2024
591275a
fix(includes): move redundant headers to header that uses them
wravery Sep 12, 2024
836e5b1
fix: ignore vc140.pdb that VS keeps dropping
wravery Sep 12, 2024
85053f5
fix(includes): try moving all imports after system includes
wravery Sep 12, 2024
0e74aae
chore: disable macOS build on each push
wravery Sep 13, 2024
e587a4b
feat(modules): finish wrapping modules around headers
wravery Sep 13, 2024
7e8d6f8
chore(cmake): install headers and module interfaces together
wravery Sep 13, 2024
bf6b48d
chore(modules): move primary interface to internal/Module.ixx
wravery Sep 13, 2024
5980cb9
fix(modules): separate modules instead of partitioning for ICE
wravery Sep 13, 2024
4d9c874
fix(modules): re-exporting all of the modules together seems to be wh…
wravery Sep 13, 2024
f45e744
fix(modules): add interface modules for include/graphqlservice/intros…
wravery Sep 13, 2024
c928aa4
feat(modules): generate public interface modules in schemagen
wravery Sep 13, 2024
d68dbcc
feat(modules): generate public interface modules in clientgen
wravery Sep 13, 2024
954520c
fix(modules): simplify exports with using statements
wravery Sep 13, 2024
fbcd728
feat(modules): wrap public headers in interface modules
wravery Sep 13, 2024
d0e48fd
chore(modules): test with TodayMock as a module
wravery Sep 13, 2024
efd938d
fix(modules): try re-exporting modules referenced in TodayMock.ixx
wravery Sep 13, 2024
ac63319
fix(modules): try to fix CI build breaks in MSVC and GCC
wravery Sep 13, 2024
ba0dd2d
fix(modules): change import order so TodaySchema is last
wravery Sep 13, 2024
957f6a3
fix(modules): get rid of intermediate exported namespaces
wravery Sep 13, 2024
c06996c
fix(include): include algorithm for std::sort
wravery Sep 13, 2024
c850bbc
fix(modules): make sure all consumers of todaygraphql use C++20
wravery Sep 13, 2024
22ed39d
fix(modules): try making lambdas noexcept for GCC mangling
wravery Sep 14, 2024
5dc0f90
fix(gcc): try specifying -fabi-version=0
wravery Sep 14, 2024
de35976
fix(gcc): try -fabi-compat-version
wravery Sep 14, 2024
81bf6bc
fix(cmake): ignore CMakeUserPresets.json
wravery Sep 14, 2024
ec2a29d
fix(modules): wrap JSONResponse and TodayMock
wravery Sep 15, 2024
31150a2
fix(modules): re-export transitive module dependencies
wravery Sep 15, 2024
63af1a8
fix(cmake): remove old try_compile tests
wravery Sep 16, 2024
598d627
feat(cmake): add a project CMakePresets.json file
wravery Sep 16, 2024
3f53e2b
fix(workflow): switch the Linux CI to clang-18 presets
wravery Sep 16, 2024
a954052
fix(ci): suppress vcpkg toolchain file on Linux CI
wravery Sep 16, 2024
b52d9a3
fix(ci): use preset from source directory
wravery Sep 16, 2024
4c94d19
fix(ci): reenable gcc-14 by turning off modules
wravery Sep 16, 2024
26db35e
fix(ci): reenable macOS CI by disabling modules
wravery Sep 16, 2024
763c136
fix(ci): switch macOS CI back to Ninja
wravery Sep 16, 2024
c30fcf1
fix(ci): build header only libs as OBJECT instead of STATIC
wravery Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ name: Linux
on: [push, pull_request]

jobs:
gcc14:
Linux:
strategy:
fail-fast: false
matrix:
config: [Debug, Release]
compiler: [gcc-14, clang-18]
config: [debug, release]

runs-on: ubuntu-24.04

Expand All @@ -18,38 +19,26 @@ jobs:

- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get upgrade
sudo add-apt-repository -y universe
sudo apt-get update
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build gcc-14 g++-14
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build

- name: Build GTest
run: |
cmake -E make_directory gtest
cd gtest
cmake -DCMAKE_BUILD_TYPE=${{ matrix.config }} -G Ninja /usr/src/gtest
cmake -DCMAKE_BUILD_TYPE=${{ matrix.config == 'debug' && 'Debug' || 'Release' }} -G Ninja /usr/src/gtest
cmake --build . -j -v
sudo cmake --install .

- name: Create Build Environment
run: cmake -E make_directory build

- name: Configure CMake
shell: pwsh
env:
CC: gcc-14
CXX: g++-14
working-directory: build/
run: |
$cmakeBuildType = '${{ matrix.config }}'

cmake "-DCMAKE_BUILD_TYPE=$cmakeBuildType" -G Ninja ${{ github.workspace }}
run: cmake --preset ${{ matrix.compiler }}-${{ matrix.config }} -DCMAKE_TOOLCHAIN_FILE=

- name: Build
working-directory: build/
run: cmake --build . -j -v
run: cmake --build --preset ${{ matrix.compiler }}-${{ matrix.config }} -j -v

- name: Test
working-directory: build/
run: ctest --output-on-failure
run: ctest --preset ${{ matrix.compiler }}-${{ matrix.config }} --output-on-failure
4 changes: 2 additions & 2 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: macOS
on: [push, pull_request]

jobs:
xcode:
apple-clang:
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
$env:VCPKG_BINARY_SOURCES = "clear;files,$cachedBinaries,$cacheAccess"

$env:PATH = "${env:PATH}:${{ github.workspace }}/ninja-build"
cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DCMAKE_BUILD_TYPE=$cmakeBuildType" -G Ninja ${{ github.workspace }}
cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DCMAKE_BUILD_TYPE=$cmakeBuildType" "-DGRAPHQL_BUILD_MODULES=OFF" -G Ninja ${{ github.workspace }}

- name: Build
working-directory: build/
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CMakeSettings.json
CMakeCache.txt
CTestCostData.txt
CTestTestfile.cmake
CMakeUserPresets.json
DartConfiguration.tcl
install_manifest.txt
LastTest.log
Expand All @@ -40,3 +41,4 @@ settings.json
build/
install/
isenseconfig/
vc140.pdb
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
endif()
endif()

option(GRAPHQL_BUILD_MODULES "Build the C++20 module interface libraries." ON)
option(GRAPHQL_BUILD_SCHEMAGEN "Build the schemagen tool." ON)
option(GRAPHQL_BUILD_CLIENTGEN "Build the clientgen tool." ON)
option(GRAPHQL_BUILD_TESTS "Build the tests and sample schema library." ON)
Expand Down
120 changes: 120 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
{
"version": 8,
"configurePresets": [
{
"hidden": true,
"name": "ninja-generator",
"binaryDir": "build/${presetName}",
"toolchainFile": "${sourceDir}/vcpkg/scripts/buildsystems/vcpkg.cmake",
"generator": "Ninja"
},
{
"name": "debug",
"inherits": [ "ninja-generator" ],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"inherits": [ "ninja-generator" ],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "gcc-14-debug",
"inherits": [ "debug" ],
"condition": {
"type": "notEquals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "/usr/bin/gcc-14",
"CMAKE_CXX_COMPILER": "/usr/bin/g++-14",
"GRAPHQL_BUILD_MODULES": false
}
},
{
"name": "gcc-14-release",
"inherits": [ "gcc-14-debug" ],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "clang-18-debug",
"inherits": [ "debug" ],
"condition": {
"type": "notEquals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "/usr/bin/clang-18",
"CMAKE_CXX_COMPILER": "/usr/bin/clang++-18",
"CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS": "/usr/bin/clang-scan-deps-18"
}
},
{
"name": "clang-18-release",
"inherits": [ "clang-18-debug" ],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
},
{
"name": "gcc-14-debug",
"configurePreset": "gcc-14-debug"
},
{
"name": "gcc-14-release",
"configurePreset": "gcc-14-release"
},
{
"name": "clang-18-debug",
"configurePreset": "clang-18-debug"
},
{
"name": "clang-18-release",
"configurePreset": "clang-18-release"
}
],
"testPresets": [
{
"name": "debug",
"configurePreset": "debug"
},
{
"name": "release",
"configurePreset": "release"
},
{
"name": "gcc-14-debug",
"configurePreset": "gcc-14-debug"
},
{
"name": "gcc-14-release",
"configurePreset": "gcc-14-release"
},
{
"name": "clang-18-debug",
"configurePreset": "clang-18-debug"
},
{
"name": "clang-18-release",
"configurePreset": "clang-18-release"
}
]
}
11 changes: 8 additions & 3 deletions cmake/Version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
#ifndef GRAPHQLVERSION_H
#define GRAPHQLVERSION_H

#include <cstddef>
#include <string_view>

namespace graphql::internal {

inline namespace version {

constexpr std::string_view FullVersion { "@PROJECT_VERSION@" };

constexpr size_t MajorVersion = @PROJECT_VERSION_MAJOR@;
constexpr size_t MinorVersion = @PROJECT_VERSION_MINOR@;
constexpr size_t PatchVersion = @PROJECT_VERSION_PATCH@;
constexpr std::size_t MajorVersion = @PROJECT_VERSION_MAJOR@;
constexpr std::size_t MinorVersion = @PROJECT_VERSION_MINOR@;
constexpr std::size_t PatchVersion = @PROJECT_VERSION_PATCH@;

} // namespace version

} // namespace graphql::internal

Expand Down
22 changes: 22 additions & 0 deletions cmake/cppgraphqlgen-functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,19 @@ function(add_graphql_schema_target SCHEMA_TARGET)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${SCHEMA_TARGET}_schema_files SCHEMA_FILES)
add_library(${SCHEMA_TARGET}_schema STATIC ${SCHEMA_FILES})
add_dependencies(${SCHEMA_TARGET}_schema ${SCHEMA_TARGET}_update_schema)
target_compile_features(${SCHEMA_TARGET}_schema PUBLIC cxx_std_20)
target_include_directories(${SCHEMA_TARGET}_schema PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${SCHEMA_TARGET}_schema PUBLIC cppgraphqlgen::graphqlservice)
file(GLOB SCHEMA_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${SCHEMA_HEADERS})
if(GRAPHQL_BUILD_MODULES)
file(GLOB SCHEMA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx)
target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET CXX_MODULES
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${SCHEMA_MODULES})
endif()
endif()
endfunction()

Expand Down Expand Up @@ -88,7 +99,18 @@ function(add_graphql_client_target CLIENT_TARGET)
file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/${CLIENT_TARGET}_client_files CLIENT_FILES)
add_library(${CLIENT_TARGET}_client STATIC ${CLIENT_FILES})
add_dependencies(${CLIENT_TARGET}_client ${CLIENT_TARGET}_update_client)
target_compile_features(${CLIENT_TARGET}_client PUBLIC cxx_std_20)
target_include_directories(${CLIENT_TARGET}_client PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
target_link_libraries(${CLIENT_TARGET}_client PUBLIC cppgraphqlgen::graphqlclient)
file(GLOB CLIENT_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.h)
target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${CLIENT_HEADERS})
if(GRAPHQL_BUILD_MODULES)
file(GLOB CLIENT_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx)
target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET CXX_MODULES
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
FILES ${CLIENT_MODULES})
endif()
endif()
endfunction()
8 changes: 4 additions & 4 deletions cmake/cppgraphqlgen-update-client-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ get_filename_component(REQUEST_GRAPHQL "${CLIENT_SOURCE_DIR}/${REQUEST_GRAPHQL}"
file(MAKE_DIRECTORY ${CLIENT_BINARY_DIR})

# Cleanup all of the stale files in the binary directory
file(GLOB PREVIOUS_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.cpp
file(GLOB PREVIOUS_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.ixx ${CLIENT_BINARY_DIR}/*.cpp
${CLIENT_BINARY_DIR}/${CLIENT_TARGET}_client_files)
foreach(PREVIOUS_FILE ${PREVIOUS_FILES})
file(REMOVE ${PREVIOUS_FILE})
Expand All @@ -30,7 +30,7 @@ execute_process(

# Get the up-to-date list of files in the binary directory
set(FILE_NAMES "")
file(GLOB NEW_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.cpp)
file(GLOB NEW_FILES ${CLIENT_BINARY_DIR}/*.h ${CLIENT_BINARY_DIR}/*.ixx ${CLIENT_BINARY_DIR}/*.cpp)
foreach(NEW_FILE ${NEW_FILES})
get_filename_component(NEW_FILE ${NEW_FILE} NAME)
list(APPEND FILE_NAMES "${NEW_FILE}")
Expand All @@ -45,11 +45,11 @@ endif()
cmake_policy(SET CMP0057 NEW)

# Remove stale files in the source directory
file(GLOB OLD_FILES ${CLIENT_SOURCE_DIR}/*.h ${CLIENT_SOURCE_DIR}/*.cpp)
file(GLOB OLD_FILES ${CLIENT_SOURCE_DIR}/*.h ${CLIENT_SOURCE_DIR}/*.ixx ${CLIENT_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
if(NOT OLD_FILE IN_LIST FILE_NAMES)
if(OLD_FILE MATCHES "Client\\.h$" OR OLD_FILE MATCHES "Client\\.cpp$")
if(OLD_FILE MATCHES "Client\\.h$" OR OLD_FILE MATCHES "Client\\.ixx$" OR OLD_FILE MATCHES "Client\\.cpp$")
file(REMOVE "${CLIENT_SOURCE_DIR}/${OLD_FILE}")
else()
message(WARNING "Unexpected file in ${CLIENT_TARGET} client sources: ${OLD_FILE}")
Expand Down
9 changes: 5 additions & 4 deletions cmake/cppgraphqlgen-update-schema-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ get_filename_component(SCHEMA_GRAPHQL "${SCHEMA_SOURCE_DIR}/${SCHEMA_GRAPHQL}" A
file(MAKE_DIRECTORY ${SCHEMA_BINARY_DIR})

# Cleanup all of the stale files in the binary directory
file(GLOB PREVIOUS_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.cpp
file(GLOB PREVIOUS_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.ixx ${SCHEMA_BINARY_DIR}/*.cpp
${SCHEMA_BINARY_DIR}/${SCHEMA_TARGET}_schema_files)
foreach(PREVIOUS_FILE ${PREVIOUS_FILES})
file(REMOVE ${PREVIOUS_FILE})
Expand All @@ -29,7 +29,7 @@ execute_process(

# Get the up-to-date list of files in the binary directory
set(FILE_NAMES "")
file(GLOB NEW_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.cpp)
file(GLOB NEW_FILES ${SCHEMA_BINARY_DIR}/*.h ${SCHEMA_BINARY_DIR}/*.ixx ${SCHEMA_BINARY_DIR}/*.cpp)
foreach(NEW_FILE ${NEW_FILES})
get_filename_component(NEW_FILE ${NEW_FILE} NAME)
list(APPEND FILE_NAMES "${NEW_FILE}")
Expand All @@ -44,13 +44,14 @@ endif()
cmake_policy(SET CMP0057 NEW)

# Remove stale files in the source directory
file(GLOB OLD_FILES ${SCHEMA_SOURCE_DIR}/*.h ${SCHEMA_SOURCE_DIR}/*.cpp)
file(GLOB OLD_FILES ${SCHEMA_SOURCE_DIR}/*.h ${SCHEMA_SOURCE_DIR}/*.ixx ${SCHEMA_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
if(NOT OLD_FILE IN_LIST FILE_NAMES)
if(OLD_FILE MATCHES "Object\\.h$" OR OLD_FILE MATCHES "Object\\.cpp$")
if(OLD_FILE MATCHES "Object\\.h$" OR OLD_FILE MATCHES "Object\\.ixx$" OR OLD_FILE MATCHES "Object\\.cpp$")
file(REMOVE "${SCHEMA_SOURCE_DIR}/${OLD_FILE}")
elseif(NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.h" AND
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.ixx" AND
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.cpp")
message(WARNING "Unexpected file in ${SCHEMA_TARGET} GraphQL schema sources: ${OLD_FILE}")
endif()
Expand Down
15 changes: 0 additions & 15 deletions cmake/test_boost_beast.cpp

This file was deleted.

Loading