libaco: 添加1.2.4

This commit is contained in:
2025-12-15 13:04:19 +08:00
parent 0345c213e3
commit d97c6f754e
9 changed files with 572 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
sources:
"1.2.4":
url: "https://github.com/hnes/libaco/archive/refs/tags/v1.2.4.tar.gz"
sha256: "25e0777ec2c686cc8c8433537d9b3694d196b0287abe6df4f0c21f8605fa5a06"

View File

@@ -0,0 +1,103 @@
from conan import ConanFile
from conan.tools.files import get, copy
import os
class LibacoConanfile(ConanFile):
name = "libaco"
description = (
"A blazing fast and lightweight C asymmetric coroutine library 💎 ⛅🚀⛅🌞"
)
license = "Apache-2.0 license"
homepage = "https://github.com/hnes/libaco"
settings = "os", "compiler", "build_type", "arch"
topics = ("coroutine", "async", "c")
options = {
"shared": [True, False],
"fPIC": [True, False],
"m32": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"m32": False,
}
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def requirements(self):
pass
def build_requirements(self):
pass
def generate(self):
pass
def build(self):
cc = os.environ.get("CC") or {"gcc": "gcc", "clang": "clang"}.get(
str(self.settings.compiler), "cc"
)
ar = os.environ.get("AR") or {"gcc": "ar", "clang": "ar"}.get(
str(self.settings.compiler), "ar"
)
cflags = [
"-c",
"-O2",
"-Wall",
]
asflags = ["-Wa,--noexecstack"]
if self.options.get_safe("fPIC"):
cflags.append("-fPIC")
if self.options.m32:
cflags.append("-m32")
if self.settings.build_type == "Debug":
cflags.append("-g")
self.run(f"{cc} {' '.join(cflags)} -o aco.o aco.c")
self.run(f"{cc} {' '.join(cflags)} {' '.join(asflags)} -o acosw.o acosw.S")
if self.options.shared:
self.run(f"{cc} -shared -o libaco.so aco.o acosw.o")
else:
self.run(f"{ar} rcs libaco.a aco.o acosw.o")
def package(self):
copy(
self,
"aco.h",
src=self.source_folder,
dst=os.path.join(self.package_folder, "include"),
)
# 顺便把 license 拷过去
copy(
self,
"LICENSE*",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
)
# 把编译好的文件拷过去
if self.options.shared:
copy(
self,
"*.so",
src=self.build_folder,
dst=os.path.join(self.package_folder, "lib"),
)
else:
copy(
self,
"*.a",
src=self.build_folder,
dst=os.path.join(self.package_folder, "lib"),
)
def package_info(self):
self.cpp_info.libs = ["aco"]
# 提供 CMake 变量,保持 find_package 兼容
self.cpp_info.set_property("cmake_file_name", "libaco")
self.cpp_info.set_property("cmake_target_name", "libaco::libaco")

View File

@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.28)
project(test_package LANGUAGES C)
find_package(libaco REQUIRED)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE libaco::libaco)

View File

@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "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,8 @@
#include <stdio.h>
#include "aco.h"
int main(int argc, char *argv[])
{
aco_thread_init(NULL);
return 0;
}

View File

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