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

Fix soxr for Apple Silicon architecture #14489

Merged
merged 10 commits into from
Jan 25, 2023
7 changes: 0 additions & 7 deletions recipes/soxr/all/CMakeLists.txt

This file was deleted.

10 changes: 6 additions & 4 deletions recipes/soxr/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ sources:
sha256: "b111c15fdc8c029989330ff559184198c161100a59312f5dc19ddeb9b5a15889"
patches:
"0.1.3":
- base_path: source_subfolder
patch_file: "patches/findpackage-openmp.patch"
- base_path: source_subfolder
patch_file: "patches/cmake-source-dir.patch"
- patch_file: "patches/findpackage-openmp.patch"
patch_description: make OpenMP required to fail when not found
patch_type: conan
- patch_file: "patches/cmake-source-dir.patch"
patch_description: point to the right source dir
patch_type: conan
81 changes: 41 additions & 40 deletions recipes/soxr/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import functools
import os
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, load, save, rmdir
from conan.tools.microsoft import msvc_runtime_flag, is_msvc
from conan.tools.scm import Version


required_conan_version = ">=1.45.0"
Linux13524 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -27,69 +29,68 @@ class SoxrConan(ConanFile):
"with_openmp": False,
"with_lsr_bindings": True
}
generators = "cmake"

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

@property
def _build_subfolder(self):
return "build_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

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.cppstd
del self.settings.compiler.libcxx
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 source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
def generate(self):
tc = CMakeToolchain(self)
# Honor BUILD_SHARED_LIBS from conan_toolchain (see https://github.com/conan-io/conan/issues/11840)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
if Version(self.version) < "3.21":
# silence warning
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0115"] = "OLD"
if is_msvc(self):
cmake.definitions["BUILD_SHARED_RUNTIME"] = msvc_runtime_flag(self) == "MD"
cmake.definitions["BUILD_TESTS"] = False
cmake.definitions["WITH_OPENMP"] = self.options.with_openmp
cmake.definitions["WITH_LSR_BINDINGS"] = self.options.with_lsr_bindings
cmake.configure(build_folder=self._build_subfolder)
return cmake
tc.variables["BUILD_SHARED_RUNTIME"] = msvc_runtime_flag(self) == "MD"
# Disable SIMD based resample engines for Apple Silicon architecture
if self.settings.os == "Macos" and self.settings.arch == "armv8":
tc.variables["WITH_CR32S"] = False
tc.variables["WITH_CR64S"] = False
tc.variables["BUILD_TESTS"] = False
tc.variables["WITH_OPENMP"] = self.options.with_openmp
tc.variables["WITH_LSR_BINDINGS"] = self.options.with_lsr_bindings
tc.generate()

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

def _extract_pffft_license(self):
pffft_c = tools.load(os.path.join(self._source_subfolder, "src", "pffft.c"))
pffft_c = load(self, os.path.join(self.source_folder, "src", "pffft.c"))
license_contents = pffft_c[pffft_c.find("/* Copyright")+3:pffft_c.find("modern CPUs.")+13]
tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents)
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), license_contents)

def package(self):
self.copy("LICENCE", dst="licenses", src=self._source_subfolder)
copy(self, "LICENCE", dst="licenses", src=self.source_folder)
self._extract_pffft_license()
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "doc"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.rmdir(os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "doc"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
# core component
self.cpp_info.components["core"].names["pkg_config"] = "soxr"
self.cpp_info.components["core"].set_property("pkg_config_name", "soxr")
self.cpp_info.components["core"].libs = ["soxr"]
if self.settings.os in ("FreeBSD", "Linux"):
self.cpp_info.components["core"].system_libs = ["m"]
Expand All @@ -108,7 +109,7 @@ def package_info(self):
self.cpp_info.components["core"].sharedlinkflags = openmp_flags
# lsr component
if self.options.with_lsr_bindings:
self.cpp_info.components["lsr"].names["pkg_config"] = "soxr-lsr"
self.cpp_info.components["lsr"].set_property("pkg_config_name", "soxr-lsr")
self.cpp_info.components["lsr"].libs = ["soxr-lsr"]
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.components["lsr"].defines.append("SOXR_DLL")
Expand Down
3 changes: 0 additions & 3 deletions recipes/soxr/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

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

find_package(soxr CONFIG REQUIRED)

add_executable(test_package_core test_package_core.c)
Expand Down
43 changes: 33 additions & 10 deletions recipes/soxr/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
import os
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import yaml


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
Linux13524 marked this conversation as resolved.
Show resolved Hide resolved
test_type = "explicit"

_tests_todo = []

@property
def _todos_filename(self):
return os.path.join(self.recipe_folder, self.folders.generators, "catch2_test_to_do.yml")
Linux13524 marked this conversation as resolved.
Show resolved Hide resolved

def requirements(self):
self.requires(self.tested_reference_str)

def generate(self):
# note: this is required as self.dependencies is not available in test()
self._tests_todo.append("test_package_core")
if self.dependencies[self.tested_reference_str].options.with_lsr_bindings:
self._tests_todo.append("test_package_lsr")

with open(self._todos_filename, "w", encoding="utf-8") as file:
yaml.dump(self._tests_todo, file)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
# core component
bin_path = os.path.join("bin", "test_package_core")
self.run(bin_path, run_environment=True)
# lsr component
if self.options["soxr"].with_lsr_bindings:
bin_path = os.path.join("bin", "test_package_lsr")
self.run(bin_path, run_environment=True)
with open(self._todos_filename, "r", encoding="utf-8") as file:
self._tests_todo = yaml.safe_load(file)
if can_run(self):
for test_name in self._tests_todo:
self.run(os.path.join(self.cpp.build.bindirs[0], test_name), env="conanrun")
15 changes: 15 additions & 0 deletions recipes/soxr/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

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

find_package(soxr CONFIG REQUIRED)

add_executable(test_package_core test_package_core.c)
target_link_libraries(test_package_core soxr::core)

if(TARGET soxr::lsr)
add_executable(test_package_lsr test_package_lsr.c)
target_link_libraries(test_package_lsr soxr::lsr)
endif()
21 changes: 21 additions & 0 deletions recipes/soxr/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from conans import ConanFile, CMake, tools

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
# core component
bin_path = os.path.join("bin", "test_package_core")
self.run(bin_path, run_environment=True)
# lsr component
if self.options["soxr"].with_lsr_bindings:
bin_path = os.path.join("bin", "test_package_lsr")
self.run(bin_path, run_environment=True)
7 changes: 7 additions & 0 deletions recipes/soxr/all/test_v1_package/test_package_core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <soxr.h>
#include <stdio.h>

int main() {
printf("soxr version: %s\n", soxr_version());
return 0;
}
7 changes: 7 additions & 0 deletions recipes/soxr/all/test_v1_package/test_package_lsr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <soxr-lsr.h>
#include <stdio.h>

int main() {
printf("soxr-lsr version: %s\n", src_get_version());
return 0;
}