Skip to content

Commit 0fd0c99

Browse files
authored
Merge pull request microsoft#142 from wravery/master
Add GitHub Actions workflows for CI and PR validation
2 parents c0cdc00 + b92ce6f commit 0fd0c99

File tree

9 files changed

+226
-28
lines changed

9 files changed

+226
-28
lines changed

.github/workflows/linux.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Linux
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
gcc7:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
config: [Debug, Release]
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
submodules: true
18+
19+
- name: Install Dependencies
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -yq libgtest-dev libboost-program-options-dev rapidjson-dev ninja-build
23+
24+
- name: Build GTest
25+
run: |
26+
cmake -E make_directory gtest
27+
cd gtest
28+
cmake -DCMAKE_BUILD_TYPE=${{ matrix.config }} -G Ninja /usr/src/gtest
29+
cmake --build . -j -v
30+
sudo cmake --install .
31+
32+
- name: Create Build Environment
33+
run: cmake -E make_directory build
34+
35+
- name: Configure CMake
36+
shell: pwsh
37+
working-directory: build/
38+
run: |
39+
$cmakeBuildType = '${{ matrix.config }}'
40+
41+
cmake "-DCMAKE_BUILD_TYPE=$cmakeBuildType" -G Ninja ${{ github.workspace }}
42+
43+
- name: Build
44+
working-directory: build/
45+
run: cmake --build . -j -v
46+
47+
- name: Test
48+
working-directory: build/
49+
run: ctest --output-on-failure

.github/workflows/macos.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: macOS
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
xcode:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
config: [Debug, Release]
11+
12+
runs-on: macos-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
submodules: true
18+
19+
- name: Cache vcpkg
20+
uses: actions/cache@v2
21+
id: cache-vcpkg
22+
with:
23+
path: vcpkg/
24+
key: vcpkg-x64-osx
25+
26+
- name: Install Dependencies
27+
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
28+
shell: pwsh
29+
run: |
30+
git clone https://github.com/microsoft/vcpkg
31+
cd vcpkg
32+
./bootstrap-vcpkg.sh -allowAppleClang
33+
./vcpkg integrate install
34+
./vcpkg install boost-program-options rapidjson gtest
35+
36+
- name: Create Build Environment
37+
run: cmake -E make_directory build
38+
39+
- name: Configure
40+
shell: pwsh
41+
working-directory: build/
42+
run: |
43+
$vcpkgToolchain = Join-Path '../vcpkg' './scripts/buildsystems/vcpkg.cmake' -Resolve
44+
$cmakeBuildType = '${{ matrix.config }}'
45+
46+
cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DCMAKE_BUILD_TYPE=$cmakeBuildType" ${{ github.workspace }}
47+
48+
- name: Build
49+
working-directory: build/
50+
run: cmake --build . -j -v
51+
52+
- name: Test
53+
working-directory: build/
54+
run: ctest --output-on-failure

.github/workflows/windows.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Windows
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
vs2019:
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
arch: ['x86', 'x64']
11+
libs: ['shared', 'static']
12+
config: ['Debug', 'Release']
13+
14+
runs-on: windows-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
submodules: true
20+
21+
- name: Set target triplet
22+
id: set-variables
23+
shell: pwsh
24+
run: echo "::set-output name=vcpkg_triplet::${{ matrix.arch }}-windows$(if ('${{ matrix.libs }}' -eq 'static') { '-static' })"
25+
26+
- name: Cache vcpkg
27+
uses: actions/cache@v2
28+
id: cache-vcpkg
29+
with:
30+
path: vcpkg/
31+
key: vcpkg-${{ steps.set-variables.outputs.vcpkg_triplet }}
32+
33+
- name: Install Dependencies
34+
if: ${{ !steps.cache-vcpkg.outputs.cache-hit }}
35+
shell: pwsh
36+
run: |
37+
git clone https://github.com/microsoft/vcpkg
38+
cd vcpkg
39+
.\bootstrap-vcpkg.bat
40+
.\vcpkg integrate install
41+
.\vcpkg install boost-program-options rapidjson gtest --triplet ${{ steps.set-variables.outputs.vcpkg_triplet }}
42+
43+
- name: Create Build Environment
44+
run: cmake -E make_directory build
45+
46+
- name: Configure
47+
shell: pwsh
48+
working-directory: build/
49+
run: |
50+
$vcpkgToolchain = Join-Path '..\vcpkg' '.\scripts\buildsystems\vcpkg.cmake' -Resolve
51+
$vcpkgTriplet = '${{ steps.set-variables.outputs.vcpkg_triplet }}'
52+
$cmakeSharedLibs = $(if ('${{ matrix.libs }}' -eq 'shared') { 'ON' } else { 'OFF' })
53+
$msbuildArch = $(if ('${{ matrix.arch }}' -eq 'x64') { 'X64' } else { 'Win32' })
54+
55+
cmake "-DCMAKE_TOOLCHAIN_FILE=$vcpkgToolchain" "-DVCPKG_TARGET_TRIPLET=$vcpkgTriplet" "-DBUILD_SHARED_LIBS=$cmakeSharedLibs" -G "Visual Studio 16 2019" -A "$msbuildArch" ${{ github.workspace }}
56+
57+
- name: Build
58+
working-directory: build/
59+
run: cmake --build . --config ${{ matrix.config }} -j -v
60+
61+
- name: Test
62+
working-directory: build/
63+
run: ctest -C ${{ matrix.config }} --output-on-failure

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
cmake_minimum_required(VERSION 3.8.2)
55

6+
# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows.
7+
cmake_policy(SET CMP0091 NEW)
8+
69
# Default to the last updated version from version.txt.
710
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.txt" VERSION_FILE)
811
file(READ "${VERSION_FILE}" LATEST_VERSION)
@@ -36,6 +39,24 @@ set(GRAPHQL_INSTALL_CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES} CACHE STRING "Co
3639

3740
option(BUILD_SHARED_LIBS "Build shared libraries instead of static libs" OFF)
3841

42+
if(VCPKG_TARGET_TRIPLET)
43+
message(STATUS "Using ${VCPKG_TARGET_TRIPLET} triplet with vcpkg")
44+
45+
if(MSVC)
46+
# Match the MSVC runtime if we're using VCPKG with static libraries.
47+
if(VCPKG_TARGET_TRIPLET MATCHES [[^.+-static$]])
48+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
49+
message(STATUS "Using MSVC runtime static library")
50+
else()
51+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
52+
message(STATUS "Using MSVC runtime DLL")
53+
endif()
54+
55+
add_custom_target(output_msvc_runtime ALL
56+
${CMAKE_COMMAND} -E echo "Using ${CMAKE_MSVC_RUNTIME_LIBRARY} MSVC runtime to match ${VCPKG_TARGET_TRIPLET}")
57+
endif()
58+
endif()
59+
3960
function(add_bigobj_flag target)
4061
if(MSVC)
4162
# MSVC requires the /bigobj flag if the number of sections gets too big.

include/graphqlservice/GraphQLSchema.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class Schema : public std::enable_shared_from_this<Schema>
4545
GRAPHQLSERVICE_EXPORT void AddType(std::string_view name, std::shared_ptr<BaseType> type);
4646
GRAPHQLSERVICE_EXPORT const std::shared_ptr<const BaseType>& LookupType(
4747
std::string_view name) const;
48-
GRAPHQLSERVICE_EXPORT const std::shared_ptr<const BaseType>& WrapType(
49-
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType);
48+
GRAPHQLSERVICE_EXPORT std::shared_ptr<const BaseType> WrapType(
49+
introspection::TypeKind kind, std::shared_ptr<const BaseType> ofType);
5050
GRAPHQLSERVICE_EXPORT void AddDirective(std::shared_ptr<Directive> directive);
5151

5252
// Accessors
@@ -67,12 +67,12 @@ class Schema : public std::enable_shared_from_this<Schema>
6767
std::shared_ptr<const ObjectType> _query;
6868
std::shared_ptr<const ObjectType> _mutation;
6969
std::shared_ptr<const ObjectType> _subscription;
70-
std::unordered_map<std::string_view, size_t> _typeMap;
70+
internal::sorted_map<std::string_view, size_t> _typeMap;
7171
std::vector<std::pair<std::string_view, std::shared_ptr<const BaseType>>> _types;
7272
std::vector<std::shared_ptr<const Directive>> _directives;
73-
std::unordered_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
73+
internal::sorted_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
7474
_nonNullWrappers;
75-
std::unordered_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
75+
internal::sorted_map<std::shared_ptr<const BaseType>, std::shared_ptr<const BaseType>>
7676
_listWrappers;
7777
};
7878

@@ -282,7 +282,7 @@ class WrapperType : public BaseType
282282
explicit WrapperType(init&& params);
283283

284284
GRAPHQLSERVICE_EXPORT static std::shared_ptr<WrapperType> Make(
285-
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType);
285+
introspection::TypeKind kind, std::weak_ptr<const BaseType> ofType);
286286

287287
// Accessors
288288
GRAPHQLSERVICE_EXPORT const std::weak_ptr<const BaseType>& ofType() const noexcept final;
@@ -303,7 +303,7 @@ class Field : public std::enable_shared_from_this<Field>
303303

304304
GRAPHQLSERVICE_EXPORT static std::shared_ptr<Field> Make(std::string_view name,
305305
std::string_view description, std::optional<std::string_view> deprecationReason,
306-
const std::shared_ptr<const BaseType>& type,
306+
std::weak_ptr<const BaseType> type,
307307
std::initializer_list<std::shared_ptr<InputValue>> args = {});
308308

309309
// Accessors
@@ -333,7 +333,7 @@ class InputValue : public std::enable_shared_from_this<InputValue>
333333
explicit InputValue(init&& params);
334334

335335
GRAPHQLSERVICE_EXPORT static std::shared_ptr<InputValue> Make(std::string_view name,
336-
std::string_view description, const std::shared_ptr<const BaseType>& type,
336+
std::string_view description, std::weak_ptr<const BaseType> type,
337337
std::string_view defaultValue);
338338

339339
// Accessors

include/graphqlservice/GraphQLTree.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ class ast_node
5252
[[nodiscard]] bool is_type() const noexcept
5353
{
5454
const auto u = type_name<U>();
55-
const auto u_hash = type_hash<U>();
5655

57-
return _type_hash == u_hash
58-
&& ((_type.data() == u.data() && _type.size() == u.size()) || _type == u);
56+
// The pointer comparison doesn't work with shared libraries where the parse tree is
57+
// constructed in one module and consumed in another. So to optimize this comparison, check
58+
// the size first, then the hash (cached in a static local variable per specialization of
59+
// type_hash<U>()), then the pointer comparison with a full string compare as fallback.
60+
return _type.size() == u.size() && _type_hash == type_hash<U>()
61+
&& (_type.data() == u.data() || _type == u);
5962
}
6063

6164
template <typename... States>
@@ -115,6 +118,8 @@ class ast_node
115118
template <typename U>
116119
[[nodiscard]] static std::string_view type_name() noexcept
117120
{
121+
// This is cached in a static local variable per-specialization, but each module may have
122+
// its own instance of the specialization and the local variable.
118123
static const std::string_view name { tao::graphqlpeg::demangle<U>() };
119124

120125
return name;
@@ -123,6 +128,8 @@ class ast_node
123128
template <typename U>
124129
[[nodiscard]] static size_t type_hash() noexcept
125130
{
131+
// This is cached in a static local variable per-specialization, but each module may have
132+
// its own instance of the specialization and the local variable.
126133
static const size_t hash = std::hash<std::string_view>()(type_name<U>());
127134

128135
return hash;

samples/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ if(GRAPHQL_UPDATE_SAMPLES)
9999
DEPENDS
100100
${CMAKE_CURRENT_BINARY_DIR}/unified/TodaySchema.cpp
101101
${CMAKE_CURRENT_BINARY_DIR}/unified/TodaySchema.h
102+
${CMAKE_CURRENT_BINARY_DIR}/unified_nointrospection/TodaySchema.cpp
103+
${CMAKE_CURRENT_BINARY_DIR}/unified_nointrospection/TodaySchema.h
102104
${CMAKE_CURRENT_BINARY_DIR}/separate/today_schema_files
105+
${CMAKE_CURRENT_BINARY_DIR}/separate_nointrospection/today_schema_files
103106
${CMAKE_CURRENT_BINARY_DIR}/validation/ValidationSchema.cpp
104107
${CMAKE_CURRENT_BINARY_DIR}/validation/ValidationSchema.h
105108
COMMENT "Updating sample files")

0 commit comments

Comments
 (0)