Skip to content

Commit 4ab79ad

Browse files
committed
refactor: Better IWYU correctness
1 parent 457584e commit 4ab79ad

File tree

14 files changed

+53
-27
lines changed

14 files changed

+53
-27
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ project(velocem LANGUAGES C CXX VERSION 0.0.13)
77
option(VELOCEM_USE_IO_URING "Use io_uring on Linux" ON)
88
option(VELOCEM_USE_IPO "Use interprocedural optimization if supported" ON)
99
option(VELOCEM_STRIP "Run system strip on compiled module" ON)
10+
option(VELOCEM_GEN_IWYU_MAPPINGS "Generate Python mappings for IWYU" OFF)
1011
set(VELOCEM_WIN_SDK_VER 0x0A00 CACHE STRING "Windows SDK macro version")
1112

1213
find_package(asio CONFIG REQUIRED)
1314
find_package(llhttp CONFIG REQUIRED)
14-
find_package(Python3 3.12 REQUIRED COMPONENTS Development.Module)
15+
16+
if(VELOCEM_GEN_IWYU_MAPPINGS)
17+
find_package(Python3 3.13 REQUIRED COMPONENTS Interpreter Development.Module)
18+
include(iwyu/GetIWYUMapGen.cmake)
19+
else()
20+
find_package(Python3 3.13 REQUIRED COMPONENTS Development.Module)
21+
endif()
1522

1623
Python3_add_library(velocem MODULE)
1724
target_link_libraries(velocem PRIVATE

iwyu/GetIWYUMapGen.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
include(FetchContent)
2+
3+
FetchContent_Declare(
4+
pythonMapGen
5+
URL https://raw.githubusercontent.com/include-what-you-use/include-what-you-use/e4dd555000b824f11783d99b93d4a713fe34dd1d/mapgen/iwyu-mapgen-cpython.py
6+
URL_HASH SHA512=ef1e39cd9c735ca218d45e1f643cf06f73327446cc1d8ec8ced86503a0db727ae6b53ee879a979b214d9a5fa6a333daf5a6bf4ef821fd4a43ad44b34df3448bc
7+
DOWNLOAD_NO_EXTRACT TRUE
8+
)
9+
FetchContent_MakeAvailable(pythonMapGen)
10+
11+
execute_process(
12+
COMMAND ${Python3_EXECUTABLE} ${pythonmapgen_SOURCE_DIR}/iwyu-mapgen-cpython.py ${Python3_INCLUDE_DIRS}
13+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/python_mappings.imp
14+
COMMAND_ECHO STDOUT
15+
)
16+
17+
list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE -Xiwyu --mapping_file=${CMAKE_BINARY_DIR}/python_mappings.imp)

src/HTTPParser.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
#include <cstring>
55
#include <span>
66
#include <stdexcept>
7-
#include <string_view>
8-
#include <utility>
7+
#include <vector>
98

10-
#include <asio.hpp>
9+
#include <asio/buffer.hpp>
1110
#include <llhttp.h>
1211

12+
#include "util/BalmStringView.hpp"
13+
#include "wsgi/Input.hpp"
1314
#include "wsgi/Request.hpp"
1415

1516
namespace velocem {

src/HTTPParser.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
#define VELOCEM_HTTP_PARSER_HPP
33

44
#include <cstddef>
5-
#include <cstring>
65
#include <span>
7-
#include <stdexcept>
8-
#include <string_view>
9-
#include <utility>
106

11-
#include <asio.hpp>
127
#include <llhttp.h>
138

14-
#include "wsgi/Request.hpp"
9+
namespace asio {
10+
class mutable_buffer;
11+
}
12+
namespace velocem {
13+
struct WSGIRequest;
14+
}
1515

1616
namespace velocem {
1717

src/plat/linux.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
2-
#include <asio.hpp>
3-
1+
#include <asio/ip/tcp.hpp>
42
#include <sys/socket.h>
53

64
int set_reuse_port(asio::ip::tcp::acceptor& sock) {

src/util/Constants.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#define VELOCEM_CONSTANTS_HPP
33

44
#include <array>
5-
#include <chrono>
6-
#include <format>
75
#include <string>
86
#include <string_view>
97

src/util/Util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Util.hpp"
22

3-
#include <cstdlib>
3+
#include <cstddef>
44
#include <stdexcept>
55
#include <string>
66
#include <vector>

src/util/Util.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#ifndef VELOCEM_UTIL_HPP
22
#define VELOCEM_UTIL_HPP
33

4+
#include <cstddef>
45
#include <string>
56
#include <vector>
67

7-
#include <asio.hpp>
8+
#include <asio/buffer.hpp>
89

910
#include <Python.h>
1011

src/wsgi/App.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#include "App.hpp"
22

3+
#include <array>
34
#include <charconv>
4-
#include <chrono>
55
#include <cstdlib>
6+
#include <format>
67
#include <optional>
78
#include <queue>
89
#include <ranges>
910
#include <stdexcept>
11+
#include <system_error>
12+
#include <tuple>
1013
#include <vector>
1114

1215
#include <Python.h>

src/wsgi/App.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
#include <Python.h>
88

9-
#include "Request.hpp"
9+
namespace velocem {
10+
struct WSGIRequest;
11+
}
1012

1113
namespace velocem {
1214

0 commit comments

Comments
 (0)