(#14608) libaio: add recipe

* libaio: add recipe

* add license attribute
This commit is contained in:
toge
2022-12-14 04:06:41 +09:00
committed by GitHub
parent 72301a672f
commit 6bcf0d042d
8 changed files with 236 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
sources:
"0.3.113":
url: "https://pagure.io/libaio/archive/libaio-0.3.113/libaio-libaio-0.3.113.tar.gz"
sha256: "716c7059703247344eb066b54ecbc3ca2134f0103307192e6c2b7dab5f9528ab"

View File

@@ -0,0 +1,77 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.env import VirtualRunEnv
from conan.tools.files import copy, get, chdir, rm
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
import os
required_conan_version = ">=1.53.0"
class LibaioConan(ConanFile):
name = "libaio"
description = "libaio provides the Linux-native API for async I/O."
license = "LGPL-2.1-only"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://pagure.io/libaio"
topics = ("asynchronous", "aio", "async")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)
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):
basic_layout(self, src_folder="src")
def validate(self):
if self.info.settings.os != "Linux":
raise ConanInvalidConfiguration(f"{self.ref} is not supported on {self.info.settings.os}.")
def source(self):
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)
def generate(self):
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")
tc = AutotoolsToolchain(self)
tc.generate()
def build(self):
autotools = Autotools(self)
with chdir(self, self.source_folder):
autotools.make(target="all")
def package(self):
copy(self, pattern="COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
autotools = Autotools(self)
with chdir(self, self.source_folder):
autotools.make(target="install", args=["prefix=" + self.package_folder])
if self.options.shared:
rm(self, "libaio.a", os.path.join(self.package_folder, "lib"))
else:
rm(self, "libaio.so*", os.path.join(self.package_folder, "lib"))
def package_info(self):
self.cpp_info.libs = ["aio"]

View File

@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
find_package(libaio REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE libaio::libaio)

View File

@@ -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 layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
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")

View File

@@ -0,0 +1,93 @@
#include <unistd.h>
#include <fcntl.h>
#include <libaio.h>
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#define FATAL(...)\
do {\
fprintf(stderr, __VA_ARGS__);\
fprintf(stderr, "\n");\
assert(0);\
exit(-1);\
} while (0)
static const void handle_error(int err) {
#define DECL_ERR(X) case -X: FATAL("Error "#X"\n"); break;
switch (err) {
DECL_ERR(EFAULT);
DECL_ERR(EINVAL);
DECL_ERR(ENOSYS);
DECL_ERR(EAGAIN);
};
if (err < 0) FATAL("Unknown error");
#undef DECL_ERR
}
#define IO_RUN(F, ...)\
do {\
int err = F(__VA_ARGS__);\
handle_error(err);\
} while (0)
#define MB(X) (X * 1024 * 1024)
#define SZ MB(50)
static const int maxEvents = 10;
char *dst = NULL; // data we are reading
char *src = NULL; // data we are writing
int fd = -1; // file to open
void check(io_context_t ctx, struct iocb *iocb, long res, long res2) {
size_t i;
if (res2 || res != SZ) FATAL("Error in async IO");
for (i = 0; i < SZ; ++i)
if (dst[i] != src[i]) FATAL("Error in async copy");
printf("DONE\n");
fflush(stdout);
}
int main (int argc, char *argv[]) {
size_t i;
/* Create a file and fill it with random crap */
FILE *file = fopen("crap.dat", "wb");
if (file == NULL) FATAL("Unable to create crap.dat");
src = (char*)malloc(sizeof(char) * SZ);
for (i = 0; i < SZ; ++i) src[i] = rand();
size_t nr = fwrite(src, SZ, 1, file);
if (nr != 1) FATAL("Unable to fill crap.dat");
fclose(file);
/* Prepare the file to read */
int fd = open("crap.dat", O_NONBLOCK, 0);
if (fd < 0) FATAL("Error opening file");
dst = (char*)malloc(sizeof(char) * SZ);
/* Now use *real* asynchronous IO to read back the file */
io_context_t ctx;
memset(&ctx, 0, sizeof(ctx));
IO_RUN (io_queue_init, maxEvents, &ctx);
/* This is the read job we asynchronously run */
struct iocb *job = (struct iocb*)malloc(sizeof(struct iocb) * 1);
io_prep_pread(job, fd, dst, SZ, 0);
io_set_callback(job, check);
/* Issue it now */
IO_RUN (io_submit, ctx, 1, &job);
/* Wait for it */
struct io_event evt;
IO_RUN (io_getevents, ctx, 1, 1, &evt, NULL);
check(ctx, evt.obj, evt.res, evt.res2);
close(fd);
free(src);
free(dst);
free(job);
io_destroy(ctx);
return 0;
}

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
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/)

View File

@@ -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)

View File

@@ -0,0 +1,3 @@
versions:
"0.3.113":
folder: all