From 76ec5d87d036a09e9752c50b47c4ea300480fc39 Mon Sep 17 00:00:00 2001 From: HikariTish <809456206@qq.com> Date: Wed, 2 Dec 2026 16:44:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=B8=BA=20compat.curl=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=8F=AF=E9=80=89=20HTTP/2=20=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mcpp.toml | 1 + pkgs/c/compat.curl.lua | 5 +++++ tests/examples/curl-http2/mcpp.toml | 9 +++++++++ tests/examples/curl-http2/tests/http2.cpp | 22 ++++++++++++++++++++++ tests/examples/curl/tests/transfer.cpp | 6 ++++++ 5 files changed, 43 insertions(+) create mode 100644 tests/examples/curl-http2/mcpp.toml create mode 100644 tests/examples/curl-http2/tests/http2.cpp diff --git a/mcpp.toml b/mcpp.toml index aadb413b..a26eec79 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -115,6 +115,7 @@ members = [ "tests/examples/cuda-curand", "tests/examples/cuda-driver", "tests/examples/curl", + "tests/examples/curl-http2", "tests/examples/djgpp-platform", "tests/examples/mcpp-platforms", "tests/examples/doctest", diff --git a/pkgs/c/compat.curl.lua b/pkgs/c/compat.curl.lua index 8398edc3..73a05363 100644 --- a/pkgs/c/compat.curl.lua +++ b/pkgs/c/compat.curl.lua @@ -110,6 +110,11 @@ package = { features = { ["default"] = { implies = { "staticlib" } }, ["staticlib"] = { defines = { "CURL_STATICLIB" } }, + ["http2"] = { + implies = { "staticlib" }, + defines = { "USE_NGHTTP2" }, + deps = { ["compat.nghttp2"] = "1.71.0" }, + }, }, cflags = { diff --git a/tests/examples/curl-http2/mcpp.toml b/tests/examples/curl-http2/mcpp.toml new file mode 100644 index 00000000..d9a87399 --- /dev/null +++ b/tests/examples/curl-http2/mcpp.toml @@ -0,0 +1,9 @@ +[package] +name = "curl-http2-tests" +version = "0.1.0" + +[dependencies.compat] +curl = { version = "8.21.0", features = ["http2"] } + +[indices] +compat = { path = "../../.." } diff --git a/tests/examples/curl-http2/tests/http2.cpp b/tests/examples/curl-http2/tests/http2.cpp new file mode 100644 index 00000000..c97e5e6c --- /dev/null +++ b/tests/examples/curl-http2/tests/http2.cpp @@ -0,0 +1,22 @@ +#include + +#include + +int main() { + if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK) return 1; + + const auto* info = curl_version_info(CURLVERSION_NOW); + const bool http2 = info && (info->features & CURL_VERSION_HTTP2) != 0; + CURL* handle = curl_easy_init(); + const bool configured = handle && + curl_easy_setopt(handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS) == CURLE_OK; + if (handle) curl_easy_cleanup(handle); + curl_global_cleanup(); + + if (!http2 || !configured) { + std::fprintf(stderr, "libcurl HTTP/2 support is unavailable\n"); + return 2; + } + std::puts("libcurl reports HTTP/2 and accepts CURL_HTTP_VERSION_2TLS"); + return 0; +} diff --git a/tests/examples/curl/tests/transfer.cpp b/tests/examples/curl/tests/transfer.cpp index 0c216445..e0552d8a 100644 --- a/tests/examples/curl/tests/transfer.cpp +++ b/tests/examples/curl/tests/transfer.cpp @@ -48,6 +48,12 @@ int main() { return 3; } + if ((info->features & CURL_VERSION_HTTP2) != 0) { + std::println("libcurl enabled HTTP/2 without the http2 feature"); + curl_global_cleanup(); + return 7; + } + bool haveHttps = false; bool haveHttp = false; for (const char* const* p = info->protocols; p != nullptr && *p != nullptr; ++p) { From 25982e10f3c3511626119027f7fd759dfa4910dc Mon Sep 17 00:00:00 2001 From: HikariTish <809456206@qq.com> Date: Wed, 2 Dec 2026 16:51:59 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20Windows=20=E4=B8=8B=20?= =?UTF-8?q?nghttp2=20=E6=97=A7=E5=9B=9E=E8=B0=83=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgs/c/compat.nghttp2.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/c/compat.nghttp2.lua b/pkgs/c/compat.nghttp2.lua index 7a67fc4d..dc251762 100644 --- a/pkgs/c/compat.nghttp2.lua +++ b/pkgs/c/compat.nghttp2.lua @@ -33,13 +33,13 @@ package = { ["mcpp_generated/include/nghttp2/nghttp2.h"] = [==[ #pragma once #if defined(_MSC_VER) -// Match the upstream CMake fallback for the legacy ssize_t API on MSVC. -# include +// Match the pointer-sized ssize_t used by Windows consumers such as curl. +# include # ifndef BUILDING_NGHTTP2 # pragma push_macro("ssize_t") # endif # undef ssize_t -# define ssize_t int +# define ssize_t SSIZE_T #endif #include #if defined(_MSC_VER) && !defined(BUILDING_NGHTTP2)