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

libdeflate: conan v2 support #13759

Merged
merged 9 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
6 changes: 0 additions & 6 deletions recipes/libdeflate/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,25 @@ sources:
patches:
"1.14":
- patch_file: "patches/1.14-0001-fix-makefiles.patch"
base_path: "source_subfolder"
patch_description: "disable optimization and apply compiler settings on conan recipe"
patch_type: "conan"
"1.12":
- patch_file: "patches/1.12-0001-fix-makefiles.patch"
base_path: "source_subfolder"
patch_description: "disable optimization and apply compiler settings on conan recipe"
patch_type: "conan"
"1.10":
- patch_file: "patches/1.9-0001-fix-makefiles.patch"
base_path: "source_subfolder"
patch_description: "disable optimization and apply compiler settings on conan recipe"
patch_type: "conan"
"1.9":
- patch_file: "patches/1.9-0001-fix-makefiles.patch"
base_path: "source_subfolder"
patch_description: "disable optimization and apply compiler settings on conan recipe"
patch_type: "conan"
"1.8":
- patch_file: "patches/1.7-0001-fix-makefiles.patch"
base_path: "source_subfolder"
patch_description: "disable optimization and apply compiler settings on conan recipe"
patch_type: "conan"
"1.7":
- patch_file: "patches/1.7-0001-fix-makefiles.patch"
base_path: "source_subfolder"
patch_description: "disable optimization and apply compiler settings on conan recipe"
patch_type: "conan"
66 changes: 39 additions & 27 deletions recipes/libdeflate/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from conan import ConanFile
from conan.tools.microsoft import is_msvc
from conan.tools.microsoft import is_msvc, VCVars, unix_path
from conan.tools.files import export_conandata_patches, apply_conandata_patches, get, chdir, rmdir, copy, rm
from conan.tools.env import Environment
from conans import MSBuild, AutoToolsBuildEnvironment, VisualStudioBuildEnvironment
from conans.tools import vcvars, environment_append
from conan.tools.env import VirtualBuildEnv
from conan.tools.layout import basic_layout
from conan.tools.gnu import Autotools, AutotoolsToolchain
import os

required_conan_version = ">=1.52.0"
Expand All @@ -26,10 +26,6 @@ class LibdeflateConan(ConanFile):
"fPIC": True,
}

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

@property
def _is_clangcl(self):
return self.settings.compiler == "clang" and self.settings.os == "Windows"
Expand Down Expand Up @@ -60,51 +56,67 @@ def configure(self):
except Exception:
pass

def layout(self):
basic_layout(self, src_folder="src")

def build_requirements(self):
if self._settings_build.os == "Windows" and not is_msvc(self):
if "CONAN_BASH_PATH" not in Environment().vars(self, scope="build").keys():
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str):
self.tool_requires("msys2/cci.latest")

def source(self):
get(self, **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)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()

if is_msvc(self) or self._is_clangcl:
vc = VCVars(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does VirtualBuildEnv automatically handle VCVars?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so.

https://docs.conan.io/en/latest/reference/conanfile/tools/microsoft.html?highlight=vcvars#msbuild

It only handles msbuild stuff. VirtualBuildEnv is more related to environment variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does building most packages work then, when I'm not in a Visual Studio Developer Command Prompt? I figured they would fail.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The msbuild helper does that step 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwillikers one of the reasons I want to upgrade these recipes is so I can build everything in my git-bash-SDK-msys terminal on windows. And so far, the new recipes seem to be doing it well.

vc.generate()
else:
tc = AutotoolsToolchain(self)
tc.generate()

def _build_msvc(self):
with chdir(self, self._source_subfolder):
with vcvars(self), environment_append(VisualStudioBuildEnvironment(self).vars):
target = "libdeflate.dll" if self.options.shared else "libdeflatestatic.lib"
self.run("nmake /f Makefile.msc {}".format(target))
def _build_nmake(self):
with chdir(self, self.source_folder):
target = "libdeflate.dll" if self.options.shared else "libdeflatestatic.lib"
self.run(f"nmake /f Makefile.msc {target}")

def _build_make(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=(self._settings_build.os == "Windows"))
with chdir(self, self._source_subfolder):
autotools = Autotools(self)
with chdir(self, self.source_folder):
autotools.make()

def build(self):
apply_conandata_patches(self)
if is_msvc(self) or self._is_clangcl:
self._build_msvc()
self._build_nmake()
else:
self._build_make()

def _package_windows(self):
self.copy("libdeflate.h", dst="include", src=self._source_subfolder)
copy(self, "libdeflate.h", dst=os.path.join(self.package_folder, "include"), src=self.source_folder)
if self.options.shared:
self.copy("*deflate.lib", dst="lib", src=self._source_subfolder)
self.copy("*deflate.dll", dst="bin", src=self._source_subfolder)
copy(self, "*deflate.lib", dst=os.path.join(self.package_folder, "lib"), src=self.source_folder)
copy(self, "*deflate.dll", dst=os.path.join(self.package_folder, "bin"), src=self.source_folder)
else:
self.copy("*deflatestatic.lib", dst="lib", src=self._source_subfolder)
copy(self, "*deflatestatic.lib", dst=os.path.join(self.package_folder, "lib"), src=self.source_folder)

def _package_make(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=(self._settings_build.os == "Windows"))
with chdir(self, self._source_subfolder):
autotools.install(args=["PREFIX={}".format(self.package_folder)])
autotools = Autotools(self)
with chdir(self, self.source_folder):
# TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed
# Note that PREFIX=/ also appears to be required on Linux.
autotools.install(args=["PREFIX=/", f"DESTDIR={unix_path(self, self.package_folder)}"])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwillikers @uilianries continuing from other comment,

I get messages like:

install -m755 libdeflate.so.0 /build/conandata/conan-data/libdeflate/1.14/ccitest/test1/package/0582ee0920dad9fef631620d3ef80b963208d3a1/usr/local/lib;

Note it installs to /usr/local/lib

and then, [HOOK - conan-center.py] post_package(): ERROR: [DEFAULT PACKAGE LAYOUT (KB-H013)] Unknown folder 'usr' in the package (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H013)

and CMake Error at build/generators/cmakedeps_macros.cmake:39 (message): Library 'deflate' not found in package. If 'deflate' is a system library, declare it with 'cpp_info.system_libs' property Call Stack (most recent call first):

I know autotools adds PREFIX=/ to configure calls, but it didn't seem to be done this time.
Weirdly, it works on Windows without PREFIX=/

Copy link
Contributor

@jwillikers jwillikers Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, this is a Makefile project and not actually Autotools, right? AutotoolsToolchain passes --prefix to the Autotools configure script. You wouldn't have that here so you'd have to use PREFIX or whatever the Makefile might expect. You can probably drop the DESTDIR then. I'm sorry for the confusion. We might need a dedicated generator for Makefile projects that doesn't require using things with Autotools in the name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, dropped and just use PREFIX

rmdir(self, os.path.join(self.package_folder, "bin"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rm(self, "*.a" if self.options.shared else "*.[so|dylib]*", os.path.join(self.package_folder, "lib") )

def package(self):
copy(self, "COPYING",
src=os.path.join(self.source_folder, self._source_subfolder),
src=os.path.join(self.source_folder, self.source_folder),
dst=os.path.join(self.package_folder, "licenses"
))
if self.settings.os == "Windows":
Expand All @@ -116,6 +128,6 @@ def package_info(self):
self.cpp_info.set_property("pkg_config_name", "libdeflate")
prefix = "lib" if self.settings.os == "Windows" else ""
suffix = "static" if self.settings.os == "Windows" and not self.options.shared else ""
self.cpp_info.libs = ["{0}deflate{1}".format(prefix, suffix)]
self.cpp_info.libs = [f"{prefix}deflate{suffix}"]
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.defines = ["LIBDEFLATE_DLL"]
7 changes: 2 additions & 5 deletions recipes/libdeflate/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

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

find_package(libdeflate REQUIRED CONFIG)

add_executable(test_package test_package.c)
target_link_libraries(test_package PRIVATE libdeflate::libdeflate)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE libdeflate::libdeflate)
26 changes: 13 additions & 13 deletions recipes/libdeflate/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from conans import ConanFile, CMake, tools
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 = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
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 not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/libdeflate/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
17 changes: 17 additions & 0 deletions recipes/libdeflate/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(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 tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)