Skip to content

Commit

Permalink
(#20415) iowow: add recipe
Browse files Browse the repository at this point in the history
* iowow: add recipe

* fix description, homepage attribute

* appy patch for macOS

* fix uint64_t format

* set CMAKE_BUILD_TYPE

* drop support msvc
  • Loading branch information
toge authored Oct 19, 2023
1 parent abd2223 commit 81cd6c7
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 0 deletions.
13 changes: 13 additions & 0 deletions recipes/iowow/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sources:
"1.4.16":
url: "https://github.com/Softmotions/iowow/archive/refs/tags/v1.4.16.tar.gz"
sha256: "6e3b92b6c342ef6ef4a2731ca2d43368749d66ca876b24b773587364cff01003"
patches:
"1.4.16":
- patch_file: "patches/1.4.16-0001-some-fix-for-macOS.patch"
patch_description: "Some fixes for macOS"
patch_type: "portability"
patch_source: "https://github.com/Softmotions/iowow/pull/56"
- patch_file: "patches/1.4.16-0002-fix-uint64_t-format.patch"
patch_description: "fix uint64_t printf format"
patch_type: "portability"
78 changes: 78 additions & 0 deletions recipes/iowow/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import get, copy, rmdir, export_conandata_patches, apply_conandata_patches
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.microsoft import is_msvc
import os

required_conan_version = ">=1.53.0"

class IowowConan(ConanFile):
name = "iowow"
description = "A C utility library and persistent key/value storage engine."
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://iowow.softmotions.com/"
topics = ("database", "nosql", "key-value", "kvstore", "skiplist", "ejdb")
package_type = "library"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": 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 validate(self):
if is_msvc(self):
raise ConanInvalidConfiguration(f"{self.ref} is not supported on Visual Studio")

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

def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_BUILD_TYPE"] = self.settings.build_type
tc.variables["BUILD_EXAMPLES"] = False
tc.variables["PACKAGE_ZIP"] = False
tc.variables["PACKAGE_TGZ"] = False
tc.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()

rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.libs = ["iowow-1"]
self.cpp_info.set_property("pkg_config_name", "package")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("pthread")
self.cpp_info.system_libs.append("m")
148 changes: 148 additions & 0 deletions recipes/iowow/all/patches/1.4.16-0001-some-fix-for-macOS.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
diff --git a/a/src/CMakeLists.txt b/b/src/CMakeLists.txt
index 7fd40ff..6c5990e 100644
--- a/a/src/CMakeLists.txt
+++ b/b/src/CMakeLists.txt
@@ -184,7 +184,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
-Wno-sign-compare -Wno-unused-parameter \
-Wno-implicit-fallthrough -Wno-unknown-pragmas -Wno-unused-function -Wno-missing-field-initializers \
-Wno-missing-braces")
-if (APPLE)
+if (APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-shorten-64-to-32")
endif()

diff --git a/a/src/platform/unix/unix.c b/b/src/platform/unix/unix.c
index 96b4920..0f8ceb4 100644
--- a/a/src/platform/unix/unix.c
+++ b/b/src/platform/unix/unix.c
@@ -348,6 +348,7 @@ iwrc iwp_exec_path(char *opath, size_t opath_maxlen) {
if (ret < 0) {
return iwrc_set_errno(IW_ERROR_ERRNO, errno);
}
+ return 0;
#else
// TODO:
return IW_ERROR_NOT_IMPLEMENTED;
diff --git a/a/src/utils/iwhmap.c b/b/src/utils/iwhmap.c
index 07ae953..757e31f 100644
--- a/a/src/utils/iwhmap.c
+++ b/b/src/utils/iwhmap.c
@@ -109,13 +109,13 @@ IW_INLINE uint32_t _hash_uint64(uint64_t x) {
}

IW_INLINE uint32_t _hash_uint64_key(const void *key) {
- if (sizeof(uintptr_t) >= sizeof(uint64_t)) {
+#ifdef IW_64
return _hash_uint64((uint64_t) key);
- } else {
+#else
uint64_t lv;
memcpy(&lv, key, sizeof(lv));
return _hash_uint64(lv);
- }
+#endif
}

IW_INLINE uint32_t _hash_uint32_key(const void *key) {
diff --git a/a/src/utils/murmur3.c b/b/src/utils/murmur3.c
index c09bf73..7f3a066 100644
--- a/a/src/utils/murmur3.c
+++ b/b/src/utils/murmur3.c
@@ -7,7 +7,7 @@
#include "murmur3.h"
#include <string.h>

-#if !defined(__x86_64__) || defined(IW_TESTS)
+#if !defined(IW64) || defined(IW_TESTS)

IW_INLINE uint32_t rotl32(uint32_t x, int8_t r) {
return (x << r) | (x >> (32 - r));
@@ -22,10 +22,28 @@ IW_INLINE uint64_t rotl64(uint64_t x, int8_t r) {
#define ROTL32(x, y) rotl32(x, y)
#define ROTL64(x, y) rotl64(x, y)

+IW_INLINE uint32_t getblock32 (const uint32_t * p, size_t i)
+{
+#ifndef IW_BIGENDIAN
+ return p[i];
+#else
+ return IW_SWAB32(p[i]);
+#endif
+}
+
+IW_INLINE uint64_t getblock64 (const uint64_t * p, size_t i)
+{
+#ifndef IW_BIGENDIAN
+ return p[i];
+#else
+ return IW_SWAB64(p[i]);
+#endif
+}
+
static uint32_t seed_value = 0x2fa1bca;

// Finalization mix - force all bits of a hash block to avalanche
-#if !defined(__x86_64__) || defined(IW_TESTS)
+#if !defined(IW64) || defined(IW_TESTS)

IW_INLINE uint32_t fmix32(uint32_t h) {
h ^= h >> 16;
@@ -47,7 +65,7 @@ IW_INLINE uint64_t fmix64(uint64_t k) {
return k;
}

-#if !defined(__x86_64__) || defined(IW_TESTS)
+#if !defined(IW64) || defined(IW_TESTS)

void murmur3_x86_32(const void *key, size_t len, uint32_t seed, void *out) {
const uint8_t *data = (const uint8_t*) key;
@@ -59,9 +77,7 @@ void murmur3_x86_32(const void *key, size_t len, uint32_t seed, void *out) {

const uint32_t *blocks = (const uint32_t*) (data + nblocks * 4);
for (i = -nblocks; i; i++) {
- uint32_t k1;
-
- memcpy(&k1, blocks + i, sizeof(k1));
+ uint32_t k1 = getblock32(blocks, i);

k1 *= c1;
k1 = ROTL32(k1, 15);
@@ -113,12 +129,10 @@ void murmur3_x86_128(const void *key, const size_t len, uint32_t seed, void *out
const uint32_t *blocks = (const uint32_t*) (data + nblocks * 16);

for (i = -nblocks; i; i++) {
- uint32_t k1, k2, k3, k4;
-
- memcpy(&k1, blocks + i * 4 + 0, sizeof(k1));
- memcpy(&k2, blocks + i * 4 + 1, sizeof(k2));
- memcpy(&k3, blocks + i * 4 + 2, sizeof(k3));
- memcpy(&k4, blocks + i * 4 + 3, sizeof(k4));
+ uint32_t k1 = getblock32(blocks, i * 4 + 0);
+ uint32_t k2 = getblock32(blocks, i * 4 + 1);
+ uint32_t k3 = getblock32(blocks, i * 4 + 2);
+ uint32_t k4 = getblock32(blocks, i * 4 + 3);

k1 *= c1;
k1 = ROTL32(k1, 15);
@@ -264,10 +278,8 @@ void murmur3_x64_128(const void *key, const size_t len, const uint32_t seed, voi

const uint64_t *blocks = (const uint64_t*) (data);
for (i = 0; i < nblocks; i++) {
- uint64_t k1, k2;
-
- memcpy(&k1, blocks + i * 2 + 0, sizeof(k1));
- memcpy(&k2, blocks + i * 2 + 1, sizeof(k2));
+ uint64_t k1 = getblock64(blocks, i * 2 + 0);
+ uint64_t k2 = getblock64(blocks, i * 2 + 1);

k1 *= c1;
k1 = ROTL64(k1, 31);
@@ -358,7 +370,7 @@ void murmur3_x64_128(const void *key, const size_t len, const uint32_t seed, voi
}

uint32_t murmur3(const char *keyptr, size_t len) {
-#ifdef __x86_64__
+#ifdef IW_64
uint64_t hash[2];
murmur3_x64_128(keyptr, len, seed_value, hash);
return (uint32_t) hash[1];
13 changes: 13 additions & 0 deletions recipes/iowow/all/patches/1.4.16-0002-fix-uint64_t-format.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/a/src/fs/iwfsmfile.c b/b/src/fs/iwfsmfile.c
index 75cc4d5..6ee3f7e 100644
--- a/a/src/fs/iwfsmfile.c
+++ b/b/src/fs/iwfsmfile.c
@@ -1338,7 +1338,7 @@ static iwrc _fsm_read_meta_lr(struct fsm *fsm) {
fsm->bmlen = llv;
if (llv & (64 - 1)) {
rc = IWFS_ERROR_INVALID_FILEMETA;
- iwlog_ecode_error(rc, "Free-space bitmap length is not 64bit aligned: %" PRIuMAX "", fsm->bmlen);
+ iwlog_ecode_error(rc, "Free-space bitmap length is not 64bit aligned: %" PRIx64 "", fsm->bmlen);
}
rp += sizeof(llv);

8 changes: 8 additions & 0 deletions recipes/iowow/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES C)

find_package(iowow REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE iowow::iowow)
target_compile_features(${PROJECT_NAME} PRIVATE c_std_11)
26 changes: 26 additions & 0 deletions recipes/iowow/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.bindir, "test_package")
self.run(bin_path, env="conanrun")
14 changes: 14 additions & 0 deletions recipes/iowow/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "iowow/iwkv.h"

int main() {
IWKV_OPTS opts = {
.path = "example1.db",
.oflags = IWKV_TRUNC // Cleanup database before open
};
IWKV iwkv;
iwrc rc = iwkv_open(&opts, &iwkv);

iwkv_close(&iwkv);

return 0;
}
3 changes: 3 additions & 0 deletions recipes/iowow/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.4.16":
folder: all

0 comments on commit 81cd6c7

Please sign in to comment.