diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fd78339f98..571d9afb4d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -83,3 +83,13 @@ jobs: ${{ github.workspace }}/azure-pipelines/end-to-end-tests.ps1 -RunArtifactsTests env: VCPKG_ROOT: ${{ github.workspace }}/vcpkg-root + - name: Upload CMake logs on failure + if: failure() + uses: actions/upload-artifact@v4 + with: + name: cmake-logs + path: | + out/build/${{ matrix.preset }}/CMakeFiles/CMakeError.log + out/build/${{ matrix.preset }}/CMakeFiles/CMakeOutput.log + out/build/${{ matrix.preset }}/CMakeFiles/CMakeConfigureLog.yaml + diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f23f31bb7..8b5f894a62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -189,6 +189,7 @@ set(TEST_SCRIPT_ASSET_CACHE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/test-script find_package(fmt REQUIRED) find_package(CMakeRC REQUIRED) +find_package(LibCURL REQUIRED) # === Target: locale-resources === @@ -223,6 +224,8 @@ target_compile_definitions(vcpkglib PUBLIC _FILE_OFFSET_BITS=64 ) +target_link_libraries(vcpkglib PRIVATE CURL::libcurl) + if(VCPKG_STANDALONE_BUNDLE_SHA) target_compile_definitions(vcpkglib PUBLIC "VCPKG_STANDALONE_BUNDLE_SHA=${VCPKG_STANDALONE_BUNDLE_SHA}" @@ -495,6 +498,7 @@ if (BUILD_TESTING) "${CMAKE_CURRENT_SOURCE_DIR}/src/vcpkg.manifest" ) target_link_libraries(vcpkg-test PRIVATE vcpkglib) + set_property(TARGET vcpkg-test PROPERTY PDB_NAME "vcpkg-test${VCPKG_PDB_SUFFIX}") if(ANDROID) target_link_libraries(vcpkg-test PRIVATE log) @@ -504,7 +508,8 @@ if (BUILD_TESTING) if(CMAKE_VERSION GREATER_EQUAL "3.16") target_precompile_headers(vcpkg-test REUSE_FROM vcpkglib) - elseif(NOT MSVC) + target_compile_definitions(vcpkg-test PRIVATE CURL_STATICLIB) + elseif(NOT MSVC) target_compile_options(vcpkg-test PRIVATE -include "${CMAKE_CURRENT_SOURCE_DIR}/include/pch.h") endif() diff --git a/cmake/FindLibCURL.cmake b/cmake/FindLibCURL.cmake new file mode 100644 index 0000000000..123be82c80 --- /dev/null +++ b/cmake/FindLibCURL.cmake @@ -0,0 +1,67 @@ +option(VCPKG_DEPENDENCY_EXTERNAL_LIBCURL "Use an external version of the libcurl library" OFF) + +# This option exists to allow the URI to be replaced with a Microsoft-internal URI in official +# builds which have restricted internet access; see azure-pipelines/signing.yml +# Note that the SHA512 is the same, so vcpkg-tool contributors need not be concerned that we built +# with different content. +if(NOT VCPKG_LIBCURL_URL) + set(VCPKG_LIBCURL_URL "https://github.com/curl/curl/archive/refs/tags/curl-8_8_0.tar.gz") +endif() + +if(POLICY CMP0135) + cmake_policy(SET CMP0135 NEW) +endif() + +include(FetchContent) +FetchContent_Declare( + LibCURL + URL "${VCPKG_LIBCURL_URL}" + URL_HASH "SHA512=e66cbf9bd3ae7b9b031475210b80b883b6a133042fbbc7cf2413f399d1b38aa54ab7322626abd3c6f1af56e0d540221f618aa903bd6b463ac8324f2c4e92dfa8" +) + +if(NOT LibCURL_FIND_REQUIRED) + message(FATAL_ERROR "LibCURL must be REQUIRED") +endif() + +if(VCPKG_DEPENDENCY_EXTERNAL_LIBCURL) + find_package(CURL REQUIRED) +else() + function(get_libcurl) + set(BUILD_SHARED_LIBS OFF) + set(BUILD_STATIC_LIBS ON) + set(BUILD_CURL_EXE OFF) + set(CURL_DISABLE_INSTALL OFF) + #set(CURL_STATIC_CRT ON) + set(ENABLE_UNICODE ON) + set(CURL_ENABLE_EXPORT_TARGET OFF) + set(BUILD_LIBCURL_DOCS OFF) + set(BUILD_MISC_DOCS OFF) + set(ENABLE_CURL_MANUAL OFF) + set(PICKY_COMPILER OFF) + set(CMAKE_DISABLE_FIND_PACKAGE_Perl ON) + set(CMAKE_DISABLE_FIND_PACKAGE_ZLIB ON) + set(CMAKE_DISABLE_FIND_PACKAGE_LibPSL ON) + set(CMAKE_DISABLE_FIND_PACKAGE_LibSSH2 ON) + if(MSVC) # This is in function() so no need to backup the variables + string(APPEND CMAKE_C_FLAGS " /wd6101") + string(APPEND CMAKE_C_FLAGS " /wd6011") + string(APPEND CMAKE_C_FLAGS " /wd6054") + string(APPEND CMAKE_C_FLAGS " /wd6240") + string(APPEND CMAKE_C_FLAGS " /wd6239") + string(APPEND CMAKE_C_FLAGS " /wd6323") + string(APPEND CMAKE_C_FLAGS " /wd6387") + string(APPEND CMAKE_C_FLAGS " /wd28182") + string(APPEND CMAKE_C_FLAGS " /wd28183") + string(APPEND CMAKE_C_FLAGS " /wd28251") + else() + string(APPEND CMAKE_C_FLAGS " -Wno-error") + endif() + FetchContent_MakeAvailable(LibCURL) + endfunction() + get_libcurl() + if(NOT TARGET CURL::libcurl) + add_library(CURL::libcurl INTERFACE) + target_link_libraries(CURL::libcurl INTERFACE libcurl_static) + target_compile_options(CURL::libcurl INTERFACE CURL_STATICLIB) + endif() +endif() diff --git a/include/vcpkg/base/curl.h b/include/vcpkg/base/curl.h new file mode 100644 index 0000000000..d160c47b5a --- /dev/null +++ b/include/vcpkg/base/curl.h @@ -0,0 +1,11 @@ + +#ifdef _MSC_VER +#pragma warning(push) // Save current warning state +#pragma warning(disable : 6101) // Disable specific warning (e.g., warning 4996) +#endif + +#include + +#ifdef _MSC_VER +#pragma warning(pop) +#endif \ No newline at end of file diff --git a/src/vcpkg/base/downloads.cpp b/src/vcpkg/base/downloads.cpp index 572318a832..9bd463e1ec 100644 --- a/src/vcpkg/base/downloads.cpp +++ b/src/vcpkg/base/downloads.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -379,6 +380,7 @@ namespace vcpkg { #define GUID_MARKER "5ec47b8e-6776-4d70-b9b3-ac2a57bc0a1c" static constexpr StringLiteral guid_marker = GUID_MARKER; + // TODO: Replace with libcurl code. Command prefix_cmd{"curl"}; if (!prefixArgs.empty()) { diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index 8f2b4453e9..46a59f0c49 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -606,6 +607,7 @@ namespace vcpkg builder.string_arg(vcpkg_metrics_txt_path); cmd_execute_background(builder); #else + // TODO: replace with libcurl code cmd_execute_background(Command("curl") .string_arg("https://dc.services.visualstudio.com/v2/track") .string_arg("--max-time")