Commit eeb93d83 authored by Kenton Varda's avatar Kenton Varda Committed by GitHub

Merge pull request #451 from sandstorm-io/cmake-http

Add kj-http to cmake build.
parents 561fe0f5 b34a7206
...@@ -126,6 +126,22 @@ if(NOT CAPNP_LITE) ...@@ -126,6 +126,22 @@ if(NOT CAPNP_LITE)
install(FILES ${kj-async_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj") install(FILES ${kj-async_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj")
endif() endif()
# kj-http ======================================================================
set(kj-http_sources
compat/http.c++
)
set(kj-http_headers
compat/http.h
)
if(NOT CAPNP_LITE)
add_library(kj-http ${kj-http_sources})
add_library(CapnProto::kj-http ALIAS kj-http)
target_link_libraries(kj-http kj-async kj)
install(TARGETS kj-http ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES ${kj-http_headers} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/kj/compat")
endif()
# Tests ======================================================================== # Tests ========================================================================
if(BUILD_TESTING) if(BUILD_TESTING)
...@@ -161,8 +177,9 @@ if(BUILD_TESTING) ...@@ -161,8 +177,9 @@ if(BUILD_TESTING)
one-of-test.c++ one-of-test.c++
function-test.c++ function-test.c++
threadlocal-pthread-test.c++ threadlocal-pthread-test.c++
compat/http-test.c++
) )
target_link_libraries(kj-heavy-tests kj-async kj-test kj) target_link_libraries(kj-heavy-tests kj-http kj-async kj-test kj)
add_dependencies(check kj-heavy-tests) add_dependencies(check kj-heavy-tests)
add_test(NAME kj-heavy-tests-run COMMAND kj-heavy-tests) add_test(NAME kj-heavy-tests-run COMMAND kj-heavy-tests)
......
...@@ -215,7 +215,11 @@ struct HeaderNameHash { ...@@ -215,7 +215,11 @@ struct HeaderNameHash {
// TODO(perf): I wonder if we can beat strcasecmp() by masking bit 0x20 from each byte. We'd // TODO(perf): I wonder if we can beat strcasecmp() by masking bit 0x20 from each byte. We'd
// need to prohibit one of the technically-legal characters '^' or '~' from header names // need to prohibit one of the technically-legal characters '^' or '~' from header names
// since they'd otherwise be ambiguous, but otherwise there is no ambiguity. // since they'd otherwise be ambiguous, but otherwise there is no ambiguity.
#if _MSC_VER
return _stricmp(a.cStr(), b.cStr()) == 0;
#else
return strcasecmp(a.cStr(), b.cStr()) == 0; return strcasecmp(a.cStr(), b.cStr()) == 0;
#endif
} }
}; };
......
...@@ -152,6 +152,13 @@ constexpr inline CharGroup_ charRange(char first, char last) { ...@@ -152,6 +152,13 @@ constexpr inline CharGroup_ charRange(char first, char last) {
return CharGroup_().orRange(first, last); return CharGroup_().orRange(first, last);
} }
#if _MSC_VER
#define anyOfChars(chars) CharGroup_().orAny(chars)
// TODO(msvc): MSVC ICEs on the proper definition of `anyOfChars()`, which in turn prevents us from
// building the compiler or schema parser. We don't know why this happens, but Harris found that
// this horrible, horrible hack makes things work. This is awful, but it's better than nothing.
// Hopefully, MSVC will get fixed soon and we'll be able to remove this.
#else
constexpr inline CharGroup_ anyOfChars(const char* chars) { constexpr inline CharGroup_ anyOfChars(const char* chars) {
// Returns a parser that accepts any of the characters in the given string (which should usually // Returns a parser that accepts any of the characters in the given string (which should usually
// be a literal). The returned parser is of the same type as returned by `charRange()` -- see // be a literal). The returned parser is of the same type as returned by `charRange()` -- see
...@@ -159,6 +166,7 @@ constexpr inline CharGroup_ anyOfChars(const char* chars) { ...@@ -159,6 +166,7 @@ constexpr inline CharGroup_ anyOfChars(const char* chars) {
return CharGroup_().orAny(chars); return CharGroup_().orAny(chars);
} }
#endif
// ======================================================================================= // =======================================================================================
......
...@@ -298,11 +298,15 @@ public: ...@@ -298,11 +298,15 @@ public:
explicit constexpr Sequence_(T&& firstSubParser, U&&... rest) explicit constexpr Sequence_(T&& firstSubParser, U&&... rest)
: first(kj::fwd<T>(firstSubParser)), rest(kj::fwd<U>(rest)...) {} : first(kj::fwd<T>(firstSubParser)), rest(kj::fwd<U>(rest)...) {}
// TODO(msvc): MSVC ICEs on the return types of operator() and parseNext() unless SubParsers is
// wrapped in `decltype(instance<SubParsers>())`. This is similar to the workaround in
// KJ_CONTEXT().
template <typename Input> template <typename Input>
auto operator()(Input& input) const -> auto operator()(Input& input) const ->
Maybe<decltype(tuple( Maybe<decltype(tuple(
instance<OutputType<FirstSubParser, Input>>(), instance<OutputType<FirstSubParser, Input>>(),
instance<OutputType<SubParsers, Input>>()...))> { instance<OutputType<decltype(instance<SubParsers>()), Input>>()...))> {
return parseNext(input); return parseNext(input);
} }
...@@ -311,7 +315,7 @@ public: ...@@ -311,7 +315,7 @@ public:
Maybe<decltype(tuple( Maybe<decltype(tuple(
kj::fwd<InitialParams>(initialParams)..., kj::fwd<InitialParams>(initialParams)...,
instance<OutputType<FirstSubParser, Input>>(), instance<OutputType<FirstSubParser, Input>>(),
instance<OutputType<SubParsers, Input>>()...))> { instance<OutputType<decltype(instance<SubParsers>()), Input>>()...))> {
KJ_IF_MAYBE(firstResult, first(input)) { KJ_IF_MAYBE(firstResult, first(input)) {
return rest.parseNext(input, kj::fwd<InitialParams>(initialParams)..., return rest.parseNext(input, kj::fwd<InitialParams>(initialParams)...,
kj::mv(*firstResult)); kj::mv(*firstResult));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment