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

cpu_features: fix cross-build arm64 on Apple OS and fix bundle install #6233

Merged
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
4 changes: 4 additions & 0 deletions recipes/cpu_features/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ sources:
"0.6.0":
url: "https://github.com/google/cpu_features/archive/refs/tags/v0.6.0.tar.gz"
sha256: "95a1cf6f24948031df114798a97eea2a71143bd38a4d07d9a758dda3924c1932"
patches:
"0.6.0":
- patch_file: "patches/0001-fix-bundle-install.patch"
base_path: "source_subfolder"
23 changes: 12 additions & 11 deletions recipes/cpu_features/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration

required_conan_version = ">=1.33.0"

Expand All @@ -15,40 +14,42 @@ class CpuFeaturesConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
exports_sources = ["CMakeLists.txt"]
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake",
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

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

def validate(self):
if hasattr(self, 'settings_build') and tools.cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross-building not implemented")

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def source(self):
tools.get(**self.conan_data["sources"][self.version],
strip_root=True, destination=self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_PIC"] = self.options.get_safe("fPIC", True)
# TODO: should be handled by CMake helper
if tools.is_apple_os(self.settings.os) and self.settings.arch in ["armv8", "armv8_32", "armv8.3"]:
self._cmake.definitions["CMAKE_SYSTEM_PROCESSOR"] = "aarch64"
self._cmake.configure() # Does not support out of source builds
return self._cmake

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
cmake.build()

Expand Down
10 changes: 10 additions & 0 deletions recipes/cpu_features/all/patches/0001-fix-bundle-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -233,6 +233,7 @@ install(TARGETS cpu_features list_cpu_features
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(EXPORT CpuFeaturesTargets
NAMESPACE CpuFeatures::
3 changes: 2 additions & 1 deletion recipes/cpu_features/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(TARGETS)

find_package(CpuFeatures CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.c)
Expand Down
42 changes: 34 additions & 8 deletions recipes/cpu_features/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
#include <cpu_features_macros.h>
#if defined(CPU_FEATURES_ARCH_X86)
#include <cpuinfo_x86.h>
#elif defined(CPU_FEATURES_ARCH_ARM)
#include <cpuinfo_arm.h>
#elif defined(CPU_FEATURES_ARCH_AARCH64)
#include <cpuinfo_aarch64.h>
#elif defined(CPU_FEATURES_ARCH_MIPS)
#include <cpuinfo_mips.h>
#elif defined(CPU_FEATURES_ARCH_PPC)
#include <ccpuinfo_ppc.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <cpuinfo_x86.h>

int main()
{
X86Features features = GetX86Info().features;
if (features.aes) {
printf("AES is available\n");
} else {
printf("AES isn't available\n");
}
return EXIT_SUCCESS;
#if defined(CPU_FEATURES_ARCH_X86)
X86Features features = GetX86Info().features;
#elif defined(CPU_FEATURES_ARCH_ARM)
ArmFeatures features = GetArmInfo().features;
#elif defined(CPU_FEATURES_ARCH_AARCH64)
Aarch64Features features = GetAarch64Info().features;
#elif defined(CPU_FEATURES_ARCH_MIPS)
MipsFeatures features = GetMipsInfo().features;
#elif defined(CPU_FEATURES_ARCH_PPC)
PPCFeatures features = GetPPCInfo().features;
#endif

#if defined(CPU_FEATURES_ARCH_X86) || defined(CPU_FEATURES_ARCH_ARM) || defined(CPU_FEATURES_ARCH_AARCH64)
printf("AES is%s available\n", features.aes ? "" : "n't");
#elif defined(CPU_FEATURES_ARCH_MIPS)
printf("EVA is%s available\n", features.eva ? "" : "n't");
#elif defined(CPU_FEATURES_ARCH_PPC)
printf("SPE is%s available\n", features.spe ? "" : "n't");
#endif

return EXIT_SUCCESS;
}