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

ls-qpack: add recipe #15125

Merged
merged 5 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions recipes/ls-qpack/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
"2.5.1":
url: "https://github.com/litespeedtech/ls-qpack/archive/refs/tags/v2.5.1.tar.gz"
sha256: "dae1c159afc8541d51c12f5ad78209fe092815d37cb621b5ee46a9db049a283f"

patches:
"2.5.1":
- patch_file: "patches/0001-use-cci-package.patch"
patch_description: "use cci packages"
patch_type: "conan"
- patch_file: "patches/0002-add-installer.patch"
patch_description: "add installer"
patch_type: "conan"
77 changes: 77 additions & 0 deletions recipes/ls-qpack/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
import os

required_conan_version = ">=1.53.0"

class LsQpackConan(ConanFile):
name = "ls-qpack"
description = "QPACK compression library for use with HTTP/3"
license = "MIT",
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/litespeedtech/ls-qpack/"
topics = ("compression", "quic", "http3", "qpack")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_xxh": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_xxh": True,
}

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.with_xxh:
self.requires("xxhash/0.8.1")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.variables["LSQPACK_TESTS"] = False
tc.variables["LSQPACK_BIN"] = False
tc.variables["LSQPACK_XXH"] = self.options.with_xxh
tc.generate()

dpes = CMakeDeps(self)
dpes.generate()

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

def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["ls-qpack"]
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.system_libs = ["m"]
if self.settings.os == "Windows":
self.cpp_info.includedirs.append(os.path.join("include", "wincompat"))
16 changes: 16 additions & 0 deletions recipes/ls-qpack/all/patches/0001-use-cci-package.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d9d9aa3..826e99b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,9 +20,10 @@ add_library(ls-qpack "")
target_include_directories(ls-qpack PUBLIC .)
target_sources(ls-qpack PRIVATE lsqpack.c)

-target_include_directories(ls-qpack PRIVATE deps/xxhash/)
if(LSQPACK_XXH)
+ find_package(xxHash REQUIRED CONFIG)
target_sources(ls-qpack PRIVATE deps/xxhash/xxhash.c)
+ target_link_libraries(ls-qpack PUBLIC xxHash::xxhash)
endif()

if(MSVC)
23 changes: 23 additions & 0 deletions recipes/ls-qpack/all/patches/0002-add-installer.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/a/CMakeLists.txt b/b/CMakeLists.txt
index 670ea97..f2dd257 100644
--- a/a/CMakeLists.txt
+++ b/b/CMakeLists.txt
@@ -100,3 +100,18 @@ endif()
if(LSQPACK_BIN)
add_subdirectory(bin)
endif()
+
+include(GNUInstallDirs)
+
+install(
+ TARGETS ls-qpack
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+)
+
+install(FILES lsqpack.h DESTINATION include)
+
+if(WIN32)
+ install(DIRECTORY wincompat DESTINATION include)
+endif()
7 changes: 7 additions & 0 deletions recipes/ls-qpack/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

find_package(ls-qpack REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE ls-qpack::ls-qpack)
26 changes: 26 additions & 0 deletions recipes/ls-qpack/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")
80 changes: 80 additions & 0 deletions recipes/ls-qpack/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#include "lsqpack.h"

int
lsqpack_dec_int (const unsigned char **src_p, const unsigned char *src_end,
unsigned prefix_bits, uint64_t *value_p,
struct lsqpack_dec_int_state *state);


struct int_test
{
int it_lineno;
unsigned it_prefix_bits;
unsigned char it_encoded[20];
size_t it_enc_sz;
uint64_t it_decoded;
int it_dec_retval;
};

static const struct int_test tests[] =
{

{ .it_lineno = __LINE__,
.it_prefix_bits = 7,
.it_encoded = { 0x7F, 0x02, },
.it_enc_sz = 2,
.it_decoded = 0x81,
.it_dec_retval = 0,
},
};

int
main (void)
{
struct lsqpack_enc enc;
size_t dec_sz;
int s;
unsigned i;
const unsigned char *p;
uint64_t val;
struct lsqpack_dec_int_state state;
unsigned char dec_buf[LSQPACK_LONGEST_SDTC];

const struct {
unsigned peer_max_size; /* Value provided by peer */
unsigned our_max_size; /* Value to use */
int expected_tsu; /* Expecting TSU instruction? */
} tests[] = {
{ 0x1000, 0x1000, 1, },
{ 0x1000, 1, 1, },
{ 0x100, 0x100, 1, },
{ 0x1000, 0, 0, },
};

for (i = 0; i < sizeof(tests) / sizeof(tests[0]); ++i)
{
dec_sz = sizeof(dec_buf);
s = lsqpack_enc_init(&enc, stderr, tests[i].peer_max_size,
tests[i].our_max_size, 0, 0, dec_buf, &dec_sz);
assert(s == 0);
if (tests[i].expected_tsu)
{
assert(dec_sz > 0);
assert((dec_buf[0] & 0xE0) == 0x20);
p = dec_buf;
state.resume = 0;
s = lsqpack_dec_int(&p, p + dec_sz, 5, &val, &state);
assert(s == 0);
assert(val == tests[i].our_max_size);
}
else
assert(dec_sz == 0);
lsqpack_enc_cleanup(&enc);
}
return 0;
}
8 changes: 8 additions & 0 deletions recipes/ls-qpack/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

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/ls-qpack/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/ls-qpack/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.5.1":
folder: all