Skip to content
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

add picohttpparser #19034

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions recipes/picohttpparser/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sources:
"cci.20230804":
url: "https://github.com/h2o/picohttpparser/archive/066d2b1e9ab820703db0837a7255d92d30f0c9f5.tar.gz"
sha256: "637ff2ab6f5c7f7e05a5b5dc393d5cf2fea8d4754fcaceaaf935ffff5c1323ee"
patches:
"cci.20230804":
- patch_file: "patches/cci.20230804-0001-add-cmake.patch"
patch_description: "add CMakeLists.txt"
patch_type: "conan"
41 changes: 41 additions & 0 deletions recipes/picohttpparser/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration

Check warning on line 2 in recipes/picohttpparser/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Unused ConanInvalidConfiguration imported from conan.errors
from conan.tools.files import get, apply_conandata_patches, export_conandata_patches
from conan.tools.cmake import CMakeToolchain, CMake
from conan.tools.layout import basic_layout

required_conan_version = ">=1.51.1"

class PicohttpparserConan(ConanFile):
name = "picohttpparser"
description = "tiny HTTP parser written in C (used in HTTP::Parser::XS et al.)"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/h2o/picohttpparser"
topics = ("http", "parser")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

def layout(self):
basic_layout(self, src_folder="src")
pwqbot marked this conversation as resolved.
Show resolved Hide resolved

def export_sources(self):
export_conandata_patches(self)

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def package(self):
cmake = CMake(self)
cmake.install()

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package_info is missing.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the project is abandoned, but still I'll ask you to send this CMake support the upstream first.

To use here, please, do not use as a patch, but use export_sources instead. Take a look in tgc recipe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I will try to send this patch to upstream

new file mode 100644
index 0000000..45a748c
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,19 @@
+cmake_minimum_required(VERSION 3.16)
+project(picohttpparser)
+
+# Set the C standard
+set(CMAKE_C_STANDARD 99)
+
+# Build the library from picohttpparser.c
+add_library(picohttpparser STATIC picohttpparser.c)
+
+# Include the current directory to find picohttpparser.h
+target_include_directories(picohttpparser PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+
+# Install the library and headers
+install(TARGETS picohttpparser
+ ARCHIVE DESTINATION lib
+ LIBRARY DESTINATION lib)
+install (
+ FILES picohttpparser.h
+ DESTINATION include)
7 changes: 7 additions & 0 deletions recipes/picohttpparser/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.12)
project(test_package LANGUAGES CXX)

find_package(picohttpparser REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE picohttpparser::picohttpparser)
26 changes: 26 additions & 0 deletions recipes/picohttpparser/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
41 changes: 41 additions & 0 deletions recipes/picohttpparser/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <picohttpparser.h>
#include <assert.h>
#include <stdio.h>

#define REQ \
"GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg " \
"HTTP/1.1\r\n" \
"Host: www.kittyhell.com\r\n" \
"User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; " \
"rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 " \
"Pathtraq/0.9\r\n" \
"Accept: " \
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" \
"Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n" \
"Accept-Encoding: gzip,deflate\r\n" \
"Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n" \
"Keep-Alive: 115\r\n" \
"Connection: keep-alive\r\n" \
"Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; " \
"__utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; " \
"__utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader." \
"livedoor.com|utmcct=/reader/|utmcmd=referral\r\n" \
"\r\n"

int main(int argc, char **) {
const char *method;
size_t method_len;
const char *path;
size_t path_len;
int minor_version;
struct phr_header headers[32];
size_t num_headers;
int i, ret;

num_headers = sizeof(headers) / sizeof(headers[0]);
ret =
phr_parse_request(REQ, sizeof(REQ) - 1, &method, &method_len, &path,
&path_len, &minor_version, headers, &num_headers, 0);
assert(ret == sizeof(REQ) - 1);
return 0;
}
9 changes: 9 additions & 0 deletions recipes/picohttpparser/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.12)

project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
18 changes: 18 additions & 0 deletions recipes/picohttpparser/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


class TestPackageV1Conan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
3 changes: 3 additions & 0 deletions recipes/picohttpparser/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20230804":
folder: all