|
| 1 | +from conan import ConanFile |
| 2 | +from conan.tools.files import load, copy |
| 3 | +from conan.errors import ConanInvalidConfiguration |
| 4 | +from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps |
| 5 | +import conan.tools.files as cfiles |
| 6 | +from pathlib import Path |
| 7 | +import tarfile, os |
| 8 | + |
| 9 | +# for compatibility |
| 10 | +release_arch = { |
| 11 | + # "windows": { |
| 12 | + # "x86_64": "x64", |
| 13 | + # }, |
| 14 | + "linux": { |
| 15 | + "x86_64": "x64", |
| 16 | + }, |
| 17 | + "android": { |
| 18 | + "x86_64": "x86_64", |
| 19 | + "armv8": "arm64-v8a", |
| 20 | + "armv7": "armeabi-v7a", |
| 21 | + }, |
| 22 | + "macos": { |
| 23 | + "x86_64": "x64", |
| 24 | + "armv8": "arm64", |
| 25 | + }, |
| 26 | + # "ios": { |
| 27 | + # "x86_64": "x64", |
| 28 | + # "armv8": "arm64", |
| 29 | + # }, |
| 30 | +} |
| 31 | + |
| 32 | +class fhel(ConanFile): |
| 33 | + name = "fhel" |
| 34 | + settings = "os", "arch", "compiler", "build_type" |
| 35 | + exports_sources = "src/*", "include/*", "test/*", "CMakeLists.txt" |
| 36 | + options = { |
| 37 | + "ci": [True, False], |
| 38 | + } |
| 39 | + |
| 40 | + default_options = { |
| 41 | + "ci": False, |
| 42 | + } |
| 43 | + |
| 44 | + def set_version(self): |
| 45 | + if not self.recipe_folder: |
| 46 | + raise ConanInvalidConfiguration("recipe_folder not set") |
| 47 | + |
| 48 | + if not self.version: |
| 49 | + version_file = Path( |
| 50 | + os.path.join(self.recipe_folder, "dart" , "binary.version") |
| 51 | + ) |
| 52 | + if not version_file.exists(): |
| 53 | + raise ConanInvalidConfiguration("binary.version file not found") |
| 54 | + |
| 55 | + self.version = load(self, version_file).strip(); |
| 56 | + |
| 57 | + def generate(self): |
| 58 | + "Generate the cmake toolchain file" |
| 59 | + tc = CMakeToolchain(self) |
| 60 | + tc.generate() |
| 61 | + |
| 62 | + def seal_negative_args(self) -> list[str]: |
| 63 | + """ |
| 64 | + Append negative options to the cmake command, |
| 65 | + e.g. -DSEAL_USE_MSGZL=OFF (default is ON) |
| 66 | + """ |
| 67 | + args = [] |
| 68 | + if self.settings.os == "Android": |
| 69 | + if self.settings.arch != "armv7": |
| 70 | + args.append("-DSEAL_BUILD_SEAL_C=1") # 64-bit only |
| 71 | + args.append("-DSEAL_USE_INTRIN=1") |
| 72 | + args.append("-DSEAL_ARM64_EXITCODE=0") |
| 73 | + args.append("-DSEAL_ARM64_EXITCODE__TRYRUN_OUTPUT=''") |
| 74 | + args.append("-DSEAL___BUILTIN_CLZLL_FOUND_EXITCODE=0") |
| 75 | + args.append("-DSEAL___BUILTIN_CLZLL_FOUND_EXITCODE__TRYRUN_OUTPUT=''") |
| 76 | + args.append("-DSEAL__ADDCARRY_U64_FOUND_EXITCODE=0") |
| 77 | + args.append("-DSEAL__ADDCARRY_U64_FOUND_EXITCODE__TRYRUN_OUTPUT=''") |
| 78 | + args.append("-DSEAL__SUBBORROW_U64_FOUND_EXITCODE=0") |
| 79 | + args.append("-DSEAL__SUBBORROW_U64_FOUND_EXITCODE__TRYRUN_OUTPUT=''") |
| 80 | + return args |
| 81 | + |
| 82 | + def build(self): |
| 83 | + "Compile libfhel dynamic library" |
| 84 | + cmake = CMake(self) |
| 85 | + cmake.configure(cli_args=self.seal_negative_args()) |
| 86 | + cmake.build() |
| 87 | + |
| 88 | + def copy_files(self): |
| 89 | + "Copy the library to the package folder" |
| 90 | + if not self.source_folder: |
| 91 | + raise ConanInvalidConfiguration("source_folder not set") |
| 92 | + if not self.package_folder: |
| 93 | + raise ConanInvalidConfiguration("package_folder not set") |
| 94 | + |
| 95 | + copy(self, |
| 96 | + pattern=f"libfhel*", |
| 97 | + src=self.source_folder, |
| 98 | + dst=self.package_folder, |
| 99 | + ) |
| 100 | + |
| 101 | + def package(self): |
| 102 | + "Package the compiled library" |
| 103 | + self.copy_files() |
| 104 | + if self.options.ci: |
| 105 | + with open(os.environ['GITHUB_OUTPUT'], "a+") as f: |
| 106 | + print(f'conan_package_path={self.package_folder}', file=f) |
0 commit comments