-
Notifications
You must be signed in to change notification settings - Fork 335
[vcpkg-tool] Replace curl command calls with libcurl #1660
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
Changes from 34 commits
d9cbe4a
d6aafe4
f5a89c7
5fc4d4e
7b40572
e7f40e1
da2529c
2865022
60b90a5
dfe1d47
8e0bd40
245480c
b280137
03f06ef
1517ce7
a12a086
293fe4e
e22b475
022d2b8
bc7816e
4433017
1daf219
622f98a
06cb1c3
f7172f4
2577dee
d76569b
5a2cd88
c50352d
e8f878d
60dd34d
9cc1edc
87b7169
8e2018b
1c53d79
fd741eb
a9c5782
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,35 @@ SOFTWARE. | |
| ========================================= | ||
| END OF CMakeRC NOTICES, INFORMATION, AND LICENSE | ||
|
|
||
| curl | ||
|
|
||
| %% curl NOTICES, INFORMATION, AND LICENSE BEGIN HERE | ||
| ========================================= | ||
| COPYRIGHT AND PERMISSION NOTICE | ||
|
|
||
| Copyright (C) Daniel Stenberg, <[email protected]>, and many | ||
| contributors, see the THANKS file. | ||
|
|
||
| All rights reserved. | ||
|
|
||
| Permission to use, copy, modify, and distribute this software for any purpose | ||
| with or without fee is hereby granted, provided that the above copyright | ||
| notice and this permission notice appear in all copies. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN | ||
| NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE | ||
| OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
||
| Except as contained in this notice, the name of a copyright holder shall not | ||
| be used in advertising or otherwise to promote the sale, use or other dealings | ||
| in this Software without prior written authorization of the copyright holder. | ||
| ========================================= | ||
| END OF curl NOTICES, INFORMATION, AND LICENSE | ||
|
|
||
| The following third party software is incorporated into vcpkg-artifacts: | ||
|
|
||
| --------------------------------------------------------- | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| if (WIN32) | ||
| option(VCPKG_DEPENDENCY_EXTERNAL_LIBCURL "Use an external version of the libcurl library" OFF) | ||
| else() | ||
| option(VCPKG_DEPENDENCY_EXTERNAL_LIBCURL "Use an external version of the libcurl library" ON) | ||
| endif() | ||
|
|
||
| if(POLICY CMP0135) | ||
| cmake_policy(SET CMP0135 NEW) | ||
| endif() | ||
|
|
||
| if (VCPKG_DEPENDENCY_EXTERNAL_LIBCURL) | ||
| find_package(CURL REQUIRED) | ||
| return() | ||
| endif() | ||
|
|
||
| # 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/releases/download/curl-8_17_0/curl-8.17.0.tar.gz") | ||
| endif() | ||
|
|
||
| include(FetchContent) | ||
| FetchContent_Declare( | ||
vicroms marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since curl is a nontrivial build should we consider trying to host ourselves rather than using FetchContent for this case? Our existing other dependencies don't really have meaningful builds which is why we never opened that can of worms. |
||
| LibCURL | ||
| URL "${VCPKG_LIBCURL_URL}" | ||
| URL_HASH "SHA512=88ab4b7aac12b26a6ad32fb0e1a9675288a45894438cb031102ef5d4ab6b33c2bc99cae0c70b71bdfa12eb49762827e2490555114c5eb4a6876b95e1f2a4eb74" | ||
| ) | ||
|
|
||
| if(NOT LibCURL_FIND_REQUIRED) | ||
| message(FATAL_ERROR "LibCURL must be REQUIRED") | ||
| endif() | ||
|
|
||
| # This is in function() so no need to backup the variables | ||
| function(get_libcurl) | ||
| set(BUILD_CURL_EXE OFF) | ||
| set(BUILD_LIBCURL_DOCS OFF) | ||
| set(BUILD_MISC_DOCS OFF) | ||
| set(BUILD_SHARED_LIBS OFF) | ||
| set(CURL_ENABLE_EXPORT_TARGET OFF) | ||
vicroms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| set(CURL_USE_LIBSSH2 OFF) | ||
| set(CURL_USE_LIBPSL OFF) | ||
| if (WIN32) | ||
| set(CURL_USE_SCHANNEL ON) | ||
| endif() | ||
| set(ENABLE_CURL_MANUAL OFF) | ||
| set(ENABLE_UNICODE ON) | ||
| set(PICKY_COMPILER OFF) | ||
| set(USE_NGHTTP2 OFF) | ||
| set(USE_LIBIDN2 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) | ||
| set(CMAKE_DISABLE_FIND_PACKAGE_Brotli ON) | ||
| set(CMAKE_DISABLE_FIND_PACKAGE_Zstd ON) | ||
|
Comment on lines
+55
to
+59
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another reason to consider hosting ourselves rather than FetchContent would be to more easily support ZLIB for Content-encoding: deflate or gzip. |
||
| set(CMAKE_DISABLE_FIND_PACKAGE_NGHTTP2 ON) | ||
| set(CMAKE_DISABLE_FIND_PACKAGE_Libidn2 ON) | ||
| if(MSVC) | ||
| 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 " /wd6287") | ||
| string(APPEND CMAKE_C_FLAGS " /wd6323") | ||
| string(APPEND CMAKE_C_FLAGS " /wd6385") | ||
| string(APPEND CMAKE_C_FLAGS " /wd6387") | ||
| string(APPEND CMAKE_C_FLAGS " /wd28182") | ||
| #string(APPEND CMAKE_C_FLAGS " /wd28183") | ||
vicroms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| string(APPEND CMAKE_C_FLAGS " /wd28251") | ||
| string(APPEND CMAKE_C_FLAGS " /wd28301") | ||
| else() | ||
| string(APPEND CMAKE_C_FLAGS " -Wno-error") | ||
| endif() | ||
| FetchContent_MakeAvailable(LibCURL) | ||
| endfunction() | ||
|
|
||
| get_libcurl() | ||
|
|
||
| if(NOT TARGET CURL::libcurl) | ||
| if(TARGET libcurl_static) | ||
| add_library(CURL::libcurl ALIAS libcurl_static) | ||
| target_compile_definitions(libcurl_static INTERFACE CURL_STATICLIB) | ||
| elseif(TARGET libcurl) | ||
| add_library(CURL::libcurl ALIAS libcurl) | ||
| if(NOT BUILD_SHARED_LIBS) | ||
| target_compile_definitions(libcurl INTERFACE CURL_STATICLIB) | ||
| endif() | ||
| else() | ||
| message(FATAL_ERROR "After FetchContent_MakeAvailable(LibCURL) no suitable curl target (libcurl or libcurl_static) was found.") | ||
| endif() | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #pragma once | ||
|
|
||
| #include <vcpkg/base/fwd/span.h> | ||
|
|
||
| #include <vcpkg/base/pragmas.h> | ||
|
|
||
| #include <vcpkg/commands.version.h> | ||
|
|
||
| VCPKG_MSVC_WARNING(push) | ||
| // note: disable warning triggered by curl headers | ||
| // ws2tcpip.h(968): warning C6101: Returning uninitialized memory '*Mtu': A successful path through the function does | ||
| // not set the named _Out_ parameter. | ||
| VCPKG_MSVC_WARNING(disable : 6101) | ||
| #include <curl/curl.h> | ||
| #include <curl/multi.h> | ||
| VCPKG_MSVC_WARNING(pop) | ||
|
|
||
| namespace vcpkg | ||
| { | ||
| CURLcode get_curl_global_init_status() noexcept; | ||
|
|
||
| struct CurlEasyHandle | ||
| { | ||
| CurlEasyHandle(); | ||
| CurlEasyHandle(CurlEasyHandle&& other) noexcept; | ||
| CurlEasyHandle& operator=(CurlEasyHandle&& other) noexcept; | ||
| ~CurlEasyHandle(); | ||
|
|
||
| CURL* get(); | ||
|
|
||
| private: | ||
| CURL* m_ptr = nullptr; | ||
| }; | ||
|
|
||
| struct CurlMultiHandle | ||
| { | ||
| CurlMultiHandle(); | ||
| CurlMultiHandle(CurlMultiHandle&& other) noexcept; | ||
| CurlMultiHandle& operator=(CurlMultiHandle&& other) noexcept; | ||
| ~CurlMultiHandle(); | ||
|
|
||
| // Adds an easy handle to the multi handle but doesn't take ownership of it. | ||
| // Makes sure that the easy handle is removed from the multi handle on cleanup. | ||
| void add_easy_handle(CurlEasyHandle& easy_handle); | ||
|
|
||
| CURLM* get(); | ||
|
|
||
| private: | ||
| CURLM* m_ptr = nullptr; | ||
| std::vector<CURL*> m_easy_handles; | ||
| }; | ||
|
|
||
| struct CurlHeaders | ||
| { | ||
| CurlHeaders(); | ||
vicroms marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| CurlHeaders(View<std::string> headers); | ||
| CurlHeaders(CurlHeaders&& other) noexcept; | ||
| CurlHeaders& operator=(CurlHeaders&& other) noexcept; | ||
| ~CurlHeaders(); | ||
|
|
||
| curl_slist* get() const; | ||
|
|
||
| private: | ||
| curl_slist* m_headers = nullptr; | ||
| }; | ||
|
|
||
| constexpr char vcpkg_curl_user_agent[] = | ||
| "vcpkg/" VCPKG_BASE_VERSION_AS_STRING "-" VCPKG_VERSION_AS_STRING " (curl)"; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems wrong that we care about which libcurl flavor we get?