[Support] Move HTTP client/server to new LLVMSupportHTTP lib (NFC) (#184572)

Relocate HTTPClient and HTTPServer from the Debuginfod library to
llvm/Support/HTTP so they can be reused by other components.

---------

Co-authored-by: Alexandre Ganea <aganea@havenstudios.com>
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
This commit is contained in:
Stefan Gränitz 2026-03-09 07:17:16 +01:00 committed by GitHub
parent 8b0a9d081f
commit 04dbbd414f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 73 additions and 56 deletions

View File

@ -15,7 +15,7 @@
#include "lldb/Utility/Log.h"
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Support/HTTP/HTTPClient.h"
using namespace lldb;
using namespace lldb_private;

View File

@ -20,12 +20,11 @@
#ifndef LLVM_DEBUGINFOD_DEBUGINFOD_H
#define LLVM_DEBUGINFOD_DEBUGINFOD_H
#include "HTTPServer.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/BuildID.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/HTTP/HTTPServer.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/RWMutex.h"

View File

@ -1,4 +1,4 @@
//===-- llvm/Support/HTTPClient.h - HTTP client library ---------*- C++ -*-===//
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -12,8 +12,8 @@
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFOD_HTTPCLIENT_H
#define LLVM_DEBUGINFOD_HTTPCLIENT_H
#ifndef LLVM_SUPPORT_HTTP_HTTPCLIENT_H
#define LLVM_SUPPORT_HTTP_HTTPCLIENT_H
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
@ -85,4 +85,4 @@ public:
} // end namespace llvm
#endif // LLVM_DEBUGINFOD_HTTPCLIENT_H
#endif // LLVM_SUPPORT_HTTP_HTTPCLIENT_H

View File

@ -1,4 +1,4 @@
//===-- llvm/Debuginfod/HTTPServer.h - HTTP server library ------*- C++ -*-===//
//===--- HTTPServer.h - HTTP server library ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -13,8 +13,8 @@
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_DEBUGINFOD_HTTPSERVER_H
#define LLVM_DEBUGINFOD_HTTPSERVER_H
#ifndef LLVM_SUPPORT_HTTP_HTTPSERVER_H
#define LLVM_SUPPORT_HTTP_HTTPSERVER_H
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
@ -130,4 +130,4 @@ public:
};
} // end namespace llvm
#endif // LLVM_DEBUGINFOD_HTTPSERVER_H
#endif // LLVM_SUPPORT_HTTP_HTTPSERVER_H

View File

@ -1,13 +1,3 @@
# Link LibCURL if the user wants it
if (LLVM_ENABLE_CURL)
set(imported_libs CURL::libcurl)
endif()
# Link cpp-httplib if the user wants it
if (LLVM_ENABLE_HTTPLIB)
set(imported_libs ${imported_libs} httplib::httplib)
endif()
# Make sure pthread is linked if this is a unix host
if (CMAKE_HOST_UNIX)
set(imported_libs ${imported_libs} ${LLVM_PTHREAD_LIB})
@ -18,8 +8,6 @@ endif()
add_llvm_library(LLVMDebuginfod
BuildIDFetcher.cpp
Debuginfod.cpp
HTTPClient.cpp
HTTPServer.cpp
ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/Debuginfod
@ -29,6 +17,7 @@ add_llvm_library(LLVMDebuginfod
LINK_COMPONENTS
Support
SupportHTTP
Symbolize
DebugInfoDWARF
BinaryFormat

View File

@ -27,7 +27,6 @@
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Object/BuildID.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/CachePruning.h"
@ -35,6 +34,7 @@
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/ThreadPool.h"

View File

@ -135,6 +135,7 @@ if (UNIX AND "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
endif()
add_subdirectory(BLAKE3)
add_subdirectory(HTTP)
add_llvm_component_library(LLVMSupport
ABIBreak.cpp

View File

@ -0,0 +1,20 @@
# Link LibCURL if the user wants it
if (LLVM_ENABLE_CURL)
set(imported_libs CURL::libcurl)
endif()
# Link cpp-httplib if the user wants it
if (LLVM_ENABLE_HTTPLIB)
set(imported_libs ${imported_libs} httplib::httplib)
endif()
add_llvm_library(LLVMSupportHTTP
HTTPClient.cpp
HTTPServer.cpp
LINK_LIBS
${imported_libs}
LINK_COMPONENTS
Support
)

View File

@ -1,4 +1,4 @@
//===-- llvm/Debuginfod/HTTPClient.cpp - HTTP client library ----*- C++ -*-===//
//===--- HTTPClient.cpp - HTTP client library -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -12,11 +12,13 @@
///
//===----------------------------------------------------------------------===//
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#ifdef LLVM_ENABLE_CURL
#include <curl/curl.h>
@ -39,7 +41,7 @@ class HTTPClientCleanup {
public:
~HTTPClientCleanup() { HTTPClient::cleanup(); }
};
static const HTTPClientCleanup Cleanup;
ManagedStatic<HTTPClientCleanup> Cleanup;
#ifdef LLVM_ENABLE_CURL

View File

@ -1,4 +1,4 @@
//===-- llvm/Debuginfod/HTTPServer.cpp - HTTP server library -----*- C++-*-===//
//===--- HTTPServer.cpp - HTTP server library -----------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -13,7 +13,8 @@
///
//===----------------------------------------------------------------------===//
#include "llvm/Debuginfod/HTTPServer.h"
#include "llvm/Support/HTTP/HTTPServer.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Errc.h"
@ -187,12 +188,8 @@ Expected<unsigned> HTTPServer::bind(const char *HostInterface) {
return make_error<HTTPServerError>("no httplib");
}
Error HTTPServer::listen() {
return make_error<HTTPServerError>("no httplib");
}
Error HTTPServer::listen() { return make_error<HTTPServerError>("no httplib"); }
void HTTPServer::stop() {
llvm_unreachable("no httplib");
}
void HTTPServer::stop() { llvm_unreachable("no httplib"); }
#endif // LLVM_ENABLE_HTTPLIB

View File

@ -24,13 +24,13 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Debuginfod/BuildIDFetcher.h"
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Object/BuildID.h"
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"

View File

@ -19,10 +19,10 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Debuginfod/BuildIDFetcher.h"
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/LLVMDriver.h"

View File

@ -18,10 +18,10 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/LLVMDriver.h"
#include "llvm/Support/ThreadPool.h"

View File

@ -34,7 +34,6 @@
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
#include "llvm/Debuginfod/BuildIDFetcher.h"
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
@ -66,6 +65,7 @@
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/LLVMDriver.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"

View File

@ -14,7 +14,6 @@
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Object/Binary.h"
#include "llvm/ProfileData/DataAccessProf.h"
@ -35,6 +34,7 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/MemoryBuffer.h"

View File

@ -25,7 +25,6 @@
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
#include "llvm/Debuginfod/BuildIDFetcher.h"
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
@ -34,6 +33,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/LLVMDriver.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/StringSaver.h"

View File

@ -1,9 +1,9 @@
add_llvm_unittest(DebuginfodTests
HTTPServerTests.cpp
DebuginfodTests.cpp
)
target_link_libraries(DebuginfodTests PRIVATE
LLVMDebuginfod
LLVMSupportHTTP
LLVMTestingSupport
)

View File

@ -1,4 +1,4 @@
//===-- llvm/unittest/Support/DebuginfodTests.cpp - unit tests ------------===//
//===--- DebuginfodTests.cpp - unit tests ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -7,8 +7,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/Debuginfod/Debuginfod.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/Path.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"

View File

@ -128,6 +128,7 @@ add_llvm_unittest(SupportTests
intrinsics_gen
)
add_subdirectory(HTTP)
add_subdirectory(LSP)
target_link_libraries(SupportTests PRIVATE LLVMTestingSupport)

View File

@ -0,0 +1,8 @@
add_llvm_unittest(SupportHTTPTests
HTTPServerTests.cpp
)
target_link_libraries(SupportHTTPTests PRIVATE
LLVMSupportHTTP
LLVMTestingSupport
)

View File

@ -1,4 +1,4 @@
//===-- llvm/unittest/Support/HTTPServer.cpp - unit tests -------*- C++ -*-===//
//===-- HTTPServerTests.cpp - unit tests ----------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@ -7,9 +7,9 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringExtras.h"
#include "llvm/Debuginfod/HTTPClient.h"
#include "llvm/Debuginfod/HTTPServer.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/HTTP/HTTPClient.h"
#include "llvm/Support/HTTP/HTTPServer.h"
#include "llvm/Support/ThreadPool.h"
#include "llvm/Testing/Support/Error.h"
#include "gmock/gmock.h"
@ -237,15 +237,15 @@ TEST_F(HTTPClientServerTest, ClientTimeout) {
TEST_F(HTTPClientServerTest, PathMatching) {
HTTPServer Server;
EXPECT_THAT_ERROR(
Server.get(R"(/abc/(.*)/(.*))",
[&](HTTPServerRequest &Request) {
EXPECT_EQ(Request.UrlPath, "/abc/1/2");
ASSERT_THAT(Request.UrlPathMatches,
testing::ElementsAre("1", "2"));
Request.setResponse({200u, "text/plain", Request.UrlPath});
}),
Succeeded());
EXPECT_THAT_ERROR(Server.get(R"(/abc/(.*)/(.*))",
[&](HTTPServerRequest &Request) {
EXPECT_EQ(Request.UrlPath, "/abc/1/2");
ASSERT_THAT(Request.UrlPathMatches,
testing::ElementsAre("1", "2"));
Request.setResponse(
{200u, "text/plain", Request.UrlPath});
}),
Succeeded());
EXPECT_THAT_ERROR(Server.get(UrlPathPattern,
[&](HTTPServerRequest &Request) {
llvm_unreachable(