Skip to content

Commit

Permalink
Merge pull request #3215 from canonical/use-vcpkg-to-build-modules
Browse files Browse the repository at this point in the history
[build] Use vcpkg to build modules
  • Loading branch information
luis4a0 authored Mar 19, 2024
2 parents 2701b66 + 185a920 commit fdf670f
Show file tree
Hide file tree
Showing 32 changed files with 2,466 additions and 80 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/linux-Coverage.patch
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
index a72d9f09a..d23ed58e3 100644
index 039b7e2ff..c35bb76c8 100644
--- a/snap/snapcraft.yaml
+++ b/snap/snapcraft.yaml
@@ -121,6 +121,7 @@ parts:
- pkg-config
- qt6-base-dev
- qt6-base-dev-tools
@@ -113,6 +113,7 @@ parts:
- build-essential
- ccache
- git
+ - lcov
stage-packages:
- apparmor
- on amd64: [libgl1]
@@ -139,9 +140,8 @@ parts:
- dnsmasq-utils
- libapparmor-dev
- libgl1-mesa-dev
- libsystemd-dev
@@ -141,9 +142,8 @@ parts:
- qt6-qpa-plugins
source: .
cmake-parameters:
- - -DCMAKE_BUILD_TYPE=Release
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
env:
SNAPCRAFT_BUILD_INFO: 1

timeout-minutes: 60
timeout-minutes: 120
steps:
- name: Install Snapcraft
uses: samuelmeuli/action-snapcraft@v2
Expand Down Expand Up @@ -107,6 +107,12 @@ jobs:
[ ! -f ${PATCH_PREFIX}.patch ] || patch -p1 --no-backup-if-mismatch < ${PATCH_PREFIX}.patch
[ ! -f ${PATCH_PREFIX}-${{ matrix.build-type }}.patch ] || patch -p1 --no-backup-if-mismatch < ${PATCH_PREFIX}-${{ matrix.build-type }}.patch
- name: Set up vcpkg
id: setup-vcpkg
uses: lukka/run-vcpkg@v11
with:
vcpkgDirectory: '${{ github.workspace }}/3rd-party/vcpkg'

- name: Set up CCache
id: setup-ccache
run: |
Expand Down Expand Up @@ -141,6 +147,18 @@ jobs:
# Inject the build label.
sed -i "/cmake-parameters:/a \ - -DMULTIPASS_BUILD_LABEL=${{ steps.build-params.outputs.label }}" snap/snapcraft.yaml
# Inject vcpkg GH Actions cache env vars if they exist
if [ -n "$ACTIONS_CACHE_URL" ]; then
sed -i "/build-environment:/a \ - ACTIONS_CACHE_URL: ${ACTIONS_CACHE_URL}" snap/snapcraft.yaml
fi
if [ -n "ACTIONS_RUNTIME_TOKEN" ]; then
sed -i "/build-environment:/a \ - ACTIONS_RUNTIME_TOKEN: ${ACTIONS_RUNTIME_TOKEN}" snap/snapcraft.yaml
fi
if [ -n "VCPKG_BINARY_SOURCES" ]; then
sed -i "/build-environment:/a \ - VCPKG_BINARY_SOURCES: ${VCPKG_BINARY_SOURCES}" snap/snapcraft.yaml
fi
# Build the `multipass` part.
/snap/bin/snapcraft build --use-lxd multipass
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
[submodule "3rd-party/fmt"]
path = 3rd-party/fmt
url = https://github.com/fmtlib/fmt.git
[submodule "3rd-party/poco"]
path = 3rd-party/poco
url = https://github.com/pocoproject/poco.git
[submodule "3rd-party/vcpkg"]
path = 3rd-party/vcpkg
url = https://github.com/microsoft/vcpkg
67 changes: 6 additions & 61 deletions 3rd-party/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)

FetchContent_Declare(gRPC
GIT_REPOSITORY https://github.com/CanonicalLtd/grpc.git
GIT_TAG e3acf245
GIT_SHALLOW TRUE
GIT_SUBMODULES "third_party/abseil-cpp third_party/cares/cares third_party/protobuf third_party/re2 third_party/zlib"
GIT_SUBMODULES_RECURSE false
GIT_PROGRESS TRUE
)
set(gRPC_SSL_PROVIDER "package" CACHE STRING "Provider of ssl library")

FetchContent_MakeAvailable(gRPC)

# Workaround for zlib placing its generated zconf.h file in the build dir,
# and protobuf not knowing so finding the system version instead
include_directories(${grpc_SOURCE_DIR}/third_party/zlib)

set_property(DIRECTORY ${grpc_SOURCE_DIR} PROPERTY EXCLUDE_FROM_ALL YES)
set(BUILD_SHARED_LIBS OFF)

if (MSVC)
add_compile_options(-wd5045) #Disable warning about Spectre mitigation
Expand Down Expand Up @@ -53,9 +34,9 @@ function(generate_grpc_cpp SRCS DEST)
"${DEST}/${FIL_WE}.grpc.pb.h"
"${DEST}/${FIL_WE}.pb.cc"
"${DEST}/${FIL_WE}.pb.h"
COMMAND $<TARGET_FILE:protoc>
ARGS --grpc_out=${DEST} --cpp_out=${DEST} --proto_path=${FIL_DIR} --proto_path=${grpc_SOURCE_DIR}/third_party/protobuf/src --plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin> ${ABS_FIL}
DEPENDS ${ABS_FIL} protoc grpc_cpp_plugin
COMMAND $<TARGET_FILE:protobuf::protoc>
ARGS --grpc_out=${DEST} --cpp_out=${DEST} --proto_path=${FIL_DIR} --proto_path=${grpc_SOURCE_DIR}/third_party/protobuf/src --plugin=protoc-gen-grpc=$<TARGET_FILE:gRPC::grpc_cpp_plugin> ${ABS_FIL}
DEPENDS ${ABS_FIL}
COMMENT "Running gRPC C++ protocol buffer compiler on ${FIL}"
VERBATIM)
endforeach ()
Expand All @@ -66,14 +47,9 @@ endfunction()

add_library(gRPC INTERFACE)

target_include_directories(gRPC INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/grpc/include
${CMAKE_CURRENT_SOURCE_DIR}/grpc/third_party/protobuf/src)

target_link_libraries(gRPC INTERFACE
grpc++
libprotobuf
zlibstatic)
gRPC::grpc++
protobuf::libprotobuf)

if (NOT MSVC)
target_compile_options(gRPC INTERFACE "-Wno-unused-parameter" "-Wno-non-virtual-dtor" "-Wno-pedantic")
Expand Down Expand Up @@ -117,7 +93,6 @@ target_compile_definitions(scope_guard INTERFACE
SG_REQUIRE_NOEXCEPT_IN_CPP17)

# semver library
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(semver EXCLUDE_FROM_ALL)
target_include_directories(semver INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/semver/include)
Expand All @@ -127,33 +102,3 @@ add_subdirectory(xz-decoder EXCLUDE_FROM_ALL)

# qhotkey config
add_subdirectory(qhotkey EXCLUDE_FROM_ALL)

# POCO library
# Suppress CMake CMP0077 warning in POCO - see `cmake --help-policy CMP0077`
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(BUILD_SHARED_LIBS ON)
option(ENABLE_NETSSL OFF)
option(ENABLE_CRYPTO OFF)
option(ENABLE_JWT OFF)
option(ENABLE_ENCODINGS OFF)
option(ENABLE_XML OFF)
option(ENABLE_JSON OFF)
option(ENABLE_MONGODB OFF)
option(ENABLE_DATA_SQLITE OFF)
option(ENABLE_REDIS OFF)
option(ENABLE_UTIL OFF)
option(ENABLE_NET OFF)
option(ENABLE_PAGECOMPILER OFF)
option(ENABLE_PAGECOMPILER_FILE2PAGE OFF)
option(ENABLE_ACTIVERECORD_COMPILER OFF)
option(ENABLE_ACTIVERECORD OFF)
option(ENABLE_DATA OFF)
option(ENABLE_PROMETHEUS OFF)

add_subdirectory(poco EXCLUDE_FROM_ALL)

install(TARGETS Foundation Zip LIBRARY COMPONENT multipassd)

# Undo some settings that POCO sets to avoid polluting the rest of our build
set(CMAKE_DEBUG_POSTFIX "" CACHE STRING "Set Debug library postfix" FORCE)
set(BUILD_SHARED_LIBS OFF)
1 change: 0 additions & 1 deletion 3rd-party/poco
Submodule poco deleted from 121161
1 change: 1 addition & 0 deletions 3rd-party/vcpkg
Submodule vcpkg added at ca7b1b
16 changes: 16 additions & 0 deletions 3rd-party/vcpkg-ports/grpc/00002-static-linking-in-linux.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8f78306f77..e09f8fcc1e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -211,6 +211,11 @@ if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
endif()
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

+if (gRPC_STATIC_LINKING AND NOT _gRPC_PLATFORM_WINDOWS)
+ # Force to static link
+ set(CMAKE_EXE_LINKER_FLAGS "-Bstatic")
+endif()
+
if(MSVC)
include(cmake/msvc_static_runtime.cmake)
add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
13 changes: 13 additions & 0 deletions 3rd-party/vcpkg-ports/grpc/00003-undef-base64-macro.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/core/lib/transport/transport.cc b/src/core/lib/transport/transport.cc
index 5d74ec2..89494b5 100644
--- a/src/core/lib/transport/transport.cc
+++ b/src/core/lib/transport/transport.cc
@@ -77,6 +77,8 @@ void grpc_stream_ref_init(grpc_stream_refcount* refcount, int /*initial_refs*/,
: nullptr);
}

+#undef move64
+
static void move64bits(uint64_t* from, uint64_t* to) {
*to += *from;
*from = 0;
13 changes: 13 additions & 0 deletions 3rd-party/vcpkg-ports/grpc/00004-link-gdi32-on-windows.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 25990a5d8a..8a632d2289 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -404,7 +404,7 @@ if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/third_party/xds)
endif()

if(WIN32)
- set(_gRPC_BASELIB_LIBRARIES ws2_32 crypt32)
+ set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32 crypt32 gdi32)
endif()

# Create directory for proto source files
47 changes: 47 additions & 0 deletions 3rd-party/vcpkg-ports/grpc/00005-fix-uwp-error.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc
index b0d3a6465b..5c48f1aa30 100644
--- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc
+++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc
@@ -1037,7 +1037,7 @@ class HPackParser::Parser {

private:
void GPR_ATTRIBUTE_NOINLINE LogHeader(const HPackTable::Memento& memento) {
- const char* type;
+ const char* type = nullptr;
switch (log_info_.type) {
case LogInfo::kHeaders:
type = "HDR";
diff --git a/src/core/lib/slice/slice.cc b/src/core/lib/slice/slice.cc
index 898a62823c..6b31cdc082 100644
--- a/src/core/lib/slice/slice.cc
+++ b/src/core/lib/slice/slice.cc
@@ -188,6 +188,7 @@ grpc_slice grpc_slice_from_moved_buffer(grpc_core::UniquePtr<char> p,
size_t len) {
uint8_t* ptr = reinterpret_cast<uint8_t*>(p.get());
grpc_slice slice;
+ memset(&slice, 0, sizeof(grpc_slice));
if (len <= sizeof(slice.data.inlined.bytes)) {
slice.refcount = nullptr;
slice.data.inlined.length = len;
@@ -206,7 +207,7 @@ grpc_slice grpc_slice_from_moved_string(grpc_core::UniquePtr<char> p) {
}

grpc_slice grpc_slice_from_cpp_string(std::string str) {
- grpc_slice slice;
+ grpc_slice slice = { 0 };
if (str.size() <= sizeof(slice.data.inlined.bytes)) {
slice.refcount = nullptr;
slice.data.inlined.length = str.size();
diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc
index 141b16e345..89d9d6dafd 100644
--- a/src/core/lib/surface/server.cc
+++ b/src/core/lib/surface/server.cc
@@ -902,7 +902,7 @@ grpc_call_error Server::QueueRequestedCall(size_t cq_idx, RequestedCall* rc) {
FailCall(cq_idx, rc, GRPC_ERROR_CREATE("Server Shutdown"));
return GRPC_CALL_OK;
}
- RequestMatcherInterface* rm;
+ RequestMatcherInterface* rm = nullptr;
switch (rc->type) {
case RequestedCall::Type::BATCH_CALL:
rm = unregistered_request_matcher_.get();
Loading

0 comments on commit fdf670f

Please sign in to comment.