From 5ccae346f404596368c8f8e6dc977ad6909ee795 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 2 Oct 2022 00:42:17 +0100 Subject: [PATCH 1/7] [libiconv] update to v2 toolchain --- recipes/libiconv/all/conandata.yml | 1 - recipes/libiconv/all/conanfile.py | 159 ++++++++++++----------------- 2 files changed, 66 insertions(+), 94 deletions(-) diff --git a/recipes/libiconv/all/conandata.yml b/recipes/libiconv/all/conandata.yml index c04401d66daca..445cf39835a93 100644 --- a/recipes/libiconv/all/conandata.yml +++ b/recipes/libiconv/all/conandata.yml @@ -11,4 +11,3 @@ sources: patches: "1.16": - patch_file: "patches/0001-libcharset-fix-linkage.patch" - base_path: "source_subfolder" diff --git a/recipes/libiconv/all/conanfile.py b/recipes/libiconv/all/conanfile.py index 4aa83c5f8ef6c..3a29916a7fbfe 100644 --- a/recipes/libiconv/all/conanfile.py +++ b/recipes/libiconv/all/conanfile.py @@ -1,11 +1,23 @@ -from conan.tools.files import rename -from conans import ConanFile, tools, AutoToolsBuildEnvironment -from conan.tools.microsoft import is_msvc -from contextlib import contextmanager import os -import functools -required_conan_version = ">=1.45.0" +from conan.tools.files import ( + apply_conandata_patches, + copy, + export_conandata_patches, + get, + rename, + replace_in_file, + rm, + rmdir +) +from conan import ConanFile +from conan.tools.env import VirtualBuildEnv +from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.layout import basic_layout +from conan.tools.microsoft import is_msvc, unix_path +from conan.tools.scm import Version + +required_conan_version = ">=1.52.0" class LibiconvConan(ConanFile): @@ -26,20 +38,16 @@ class LibiconvConan(ConanFile): } @property - def _source_subfolder(self): - return "source_subfolder" - - @property - def _use_winbash(self): - return tools.os_info.is_windows and (self.settings.compiler == "gcc" or tools.cross_building(self)) + def _is_clang_cl(self): + return (self.settings.compiler == "clang" and self.settings.os == "Windows") \ + or self.settings.get_safe("compiler.toolset") == "ClangCL" @property - def _is_clang_cl(self): - return self.settings.compiler == "clang" and self.settings.os == "Windows" + def _msvc_tools(self): + return ("clang-cl", "llvm-lib", "lld-link") if self._is_clang_cl else ("cl", "lib", "link") def export_sources(self): - 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": @@ -55,99 +63,64 @@ def configure(self): def _settings_build(self): return getattr(self, "settings_build", self.settings) - def build_requirements(self): - if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"): - self.build_requires("msys2/cci.latest") + def layout(self): + basic_layout(self, src_folder="src") - def source(self): - tools.get(**self.conan_data["sources"][self.version], destination=self._source_subfolder, strip_root=True) + def generate(self): + tc = AutotoolsToolchain(self) + env = tc.environment() - @contextmanager - def _build_context(self): - env_vars = {} if is_msvc(self) or self._is_clang_cl: - cc = "cl" if is_msvc(self) else os.environ.get("CC", "clang-cl") - cxx = "cl" if is_msvc(self) else os.environ.get("CXX", "clang-cl") - lib = "lib" if is_msvc(self) else os.environ.get("AR", "llvm-lib") - build_aux_path = os.path.join(self.build_folder, self._source_subfolder, "build-aux") - lt_compile = tools.unix_path(os.path.join(build_aux_path, "compile")) - lt_ar = tools.unix_path(os.path.join(build_aux_path, "ar-lib")) - env_vars.update({ - "CC": "{} {} -nologo".format(lt_compile, cc), - "CXX": "{} {} -nologo".format(lt_compile, cxx), - "LD": "link", - "STRIP": ":", - "AR": "{} {}".format(lt_ar, lib), - "RANLIB": ":", - "NM": "dumpbin -symbols" - }) - env_vars["win32_target"] = "_WIN32_WINNT_VISTA" - - if not tools.cross_building(self) or is_msvc(self) or self._is_clang_cl: - rc = None - if self.settings.arch == "x86": - rc = "windres --target=pe-i386" - elif self.settings.arch == "x86_64": - rc = "windres --target=pe-x86-64" - if rc: - env_vars["RC"] = rc - env_vars["WINDRES"] = rc - if self._use_winbash: - env_vars["RANLIB"] = ":" - - with tools.vcvars(self.settings) if (is_msvc(self) or self._is_clang_cl) else tools.no_op(): - with tools.chdir(self._source_subfolder): - with tools.environment_append(env_vars): - yield - - @functools.lru_cache(1) - def _configure_autotools(self): - host = None - build = None - if is_msvc(self) or self._is_clang_cl: - build = False - if self.settings.arch == "x86": - host = "i686-w64-mingw32" - elif self.settings.arch == "x86_64": - host = "x86_64-w64-mingw32" - - autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) - - configure_args = [] - if self.options.shared: - configure_args.extend(["--disable-static", "--enable-shared"]) - else: - configure_args.extend(["--enable-static", "--disable-shared"]) + cc, lib, link = self._msvc_tools + build_aux_path = os.path.join(self.source_folder, "build-aux") + lt_compile = unix_path(self, os.path.join(build_aux_path, "compile")) + lt_ar = unix_path(self, os.path.join(build_aux_path, "ar-lib")) + env.define("CC", f"{lt_compile} {cc} -nologo") + env.define("CXX", f"{lt_compile} {cc} -nologo") + env.define("LD", f"{link}") + env.define("STRIP", ":") + env.define("AR", f"{lt_ar} {lib}") + env.define("RANLIB", ":") + env.define("NM", "dumpbin -symbols") + env.define("win32_target", "_WIN32_WINNT_VISTA") + + if is_msvc(self) and Version(self.settings.compiler.version) >= "12": + tc.extra_cflags.append("-FS") + + tc.generate(env) + + env = VirtualBuildEnv(self) + env.generate() - if (self.settings.compiler == "Visual Studio" and tools.Version(self.settings.compiler.version) >= "12") or \ - self.settings.compiler == "msvc": - autotools.flags.append("-FS") + def build_requirements(self): + if self._settings_build.os == "Windows": + if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=bool): + self.tool_requires("msys2/cci.latest") + self.win_bash = True - autotools.configure(args=configure_args, host=host, build=build) - return autotools + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) def _patch_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) + apply_conandata_patches(self) # relocatable shared libs on macOS for configure in ["configure", os.path.join("libcharset", "configure")]: - tools.replace_in_file(os.path.join(self._source_subfolder, configure), + replace_in_file(self, os.path.join(self.source_folder, configure), "-install_name \\$rpath/", "-install_name @rpath/") def build(self): self._patch_sources() - with self._build_context(): - autotools = self._configure_autotools() - autotools.make() + autotools = Autotools(self) + autotools.configure() + autotools.make() def package(self): - self.copy("COPYING.LIB", src=self._source_subfolder, dst="licenses") - with self._build_context(): - autotools = self._configure_autotools() - autotools.install() + copy(self, "COPYING.LIB", self.source_folder, os.path.join(self.package_folder, "licenses")) + autotools = Autotools(self) + autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"]) - tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la") - tools.rmdir(os.path.join(self.package_folder, "share")) + rm(self, "*.la", os.path.join(self.package_folder, "lib")) + rmdir(self, os.path.join(self.package_folder, "share")) if (is_msvc(self) or self._is_clang_cl) and self.options.shared: for import_lib in ["iconv", "charset"]: From 61ece37fbec03525a541b6af18005d4dcaf49ac3 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 2 Oct 2022 10:35:41 +0100 Subject: [PATCH 2/7] [libiconv] update test packages vor v2 --- .../libiconv/all/test_package/CMakeLists.txt | 5 +--- .../libiconv/all/test_package/conanfile.py | 26 ++++++++++--------- .../all/test_v1_package/CMakeLists.txt | 10 +++++++ .../libiconv/all/test_v1_package/conanfile.py | 16 ++++++++++++ 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 recipes/libiconv/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/libiconv/all/test_v1_package/conanfile.py diff --git a/recipes/libiconv/all/test_package/CMakeLists.txt b/recipes/libiconv/all/test_package/CMakeLists.txt index 18f2a726df141..64fa90dede848 100644 --- a/recipes/libiconv/all/test_package/CMakeLists.txt +++ b/recipes/libiconv/all/test_package/CMakeLists.txt @@ -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(Iconv REQUIRED) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} Iconv::Iconv) +target_link_libraries(${PROJECT_NAME} PRIVATE Iconv::Iconv) diff --git a/recipes/libiconv/all/test_package/conanfile.py b/recipes/libiconv/all/test_package/conanfile.py index 715ff0b981f7c..a59ddb54af551 100644 --- a/recipes/libiconv/all/test_package/conanfile.py +++ b/recipes/libiconv/all/test_package/conanfile.py @@ -1,19 +1,20 @@ -from conans import ConanFile, CMake, tools import os +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout + class TestPackageConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake", "cmake_find_package" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) - 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 build(self): cmake = CMake(self) @@ -21,5 +22,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - self.run(os.path.join("bin", "test_package"), run_environment=True) + if not can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/libiconv/all/test_v1_package/CMakeLists.txt b/recipes/libiconv/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..780f84321c0d7 --- /dev/null +++ b/recipes/libiconv/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package C) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +find_package(Iconv REQUIRED) + +add_executable(${PROJECT_NAME} ../test_package/test_package.c) +target_link_libraries(${PROJECT_NAME} Iconv::Iconv) diff --git a/recipes/libiconv/all/test_v1_package/conanfile.py b/recipes/libiconv/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..a831367c532bc --- /dev/null +++ b/recipes/libiconv/all/test_v1_package/conanfile.py @@ -0,0 +1,16 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake", "cmake_find_package" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + self.run(os.path.join("bin", "test_package"), run_environment=True) From 100ccd6fad78f779295ab5a63d8b0d8b18809b0c Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 2 Oct 2022 13:56:43 +0100 Subject: [PATCH 3/7] [libiconv] fix cross building check --- recipes/libiconv/all/test_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libiconv/all/test_package/conanfile.py b/recipes/libiconv/all/test_package/conanfile.py index a59ddb54af551..12a4269e5efa4 100644 --- a/recipes/libiconv/all/test_package/conanfile.py +++ b/recipes/libiconv/all/test_package/conanfile.py @@ -22,6 +22,6 @@ def build(self): cmake.build() def test(self): - if not can_run(self): + if can_run(self): bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") self.run(bin_path, env="conanrun") From 0c030ef763f849f0d8696244f5b7392ebad6d938 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 2 Oct 2022 15:23:51 +0100 Subject: [PATCH 4/7] [libiconv] supply '-FS' flag for msvc debug --- recipes/libiconv/all/conanfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/recipes/libiconv/all/conanfile.py b/recipes/libiconv/all/conanfile.py index 3a29916a7fbfe..58f012639920b 100644 --- a/recipes/libiconv/all/conanfile.py +++ b/recipes/libiconv/all/conanfile.py @@ -85,7 +85,9 @@ def generate(self): env.define("win32_target", "_WIN32_WINNT_VISTA") if is_msvc(self) and Version(self.settings.compiler.version) >= "12": - tc.extra_cflags.append("-FS") + # tc.extra_cflags is not respected. + # See https://github.com/conan-io/conan/issues/12228 + env.define("CFLAGS", tc.cflags + ["-FS"]) tc.generate(env) From 5c3105932360bdfeecf1106108b08a0ad5c89fd5 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 2 Oct 2022 23:39:02 +0100 Subject: [PATCH 5/7] [libiconv] add destination to source method --- recipes/libiconv/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libiconv/all/conanfile.py b/recipes/libiconv/all/conanfile.py index 58f012639920b..c576cdc0219ad 100644 --- a/recipes/libiconv/all/conanfile.py +++ b/recipes/libiconv/all/conanfile.py @@ -101,7 +101,7 @@ def build_requirements(self): self.win_bash = True def source(self): - get(self, **self.conan_data["sources"][self.version], strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def _patch_sources(self): apply_conandata_patches(self) From 49cbf7f496c6079cbe890f57388f739a6aaaaada Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Mon, 3 Oct 2022 16:31:55 +0100 Subject: [PATCH 6/7] Update recipes/libiconv/all/test_v1_package/CMakeLists.txt Co-authored-by: Jordan Williams --- recipes/libiconv/all/test_v1_package/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libiconv/all/test_v1_package/CMakeLists.txt b/recipes/libiconv/all/test_v1_package/CMakeLists.txt index 780f84321c0d7..001545fa55362 100644 --- a/recipes/libiconv/all/test_v1_package/CMakeLists.txt +++ b/recipes/libiconv/all/test_v1_package/CMakeLists.txt @@ -7,4 +7,4 @@ conan_basic_setup(TARGETS) find_package(Iconv REQUIRED) add_executable(${PROJECT_NAME} ../test_package/test_package.c) -target_link_libraries(${PROJECT_NAME} Iconv::Iconv) +target_link_libraries(${PROJECT_NAME} PRIVATE Iconv::Iconv) From 7b97959cec66647ed61cfdb34cc2e0f7b2479216 Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Tue, 4 Oct 2022 16:37:17 +0100 Subject: [PATCH 7/7] [libiconv] handle msvc compiler version --- recipes/libiconv/all/conanfile.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/recipes/libiconv/all/conanfile.py b/recipes/libiconv/all/conanfile.py index c576cdc0219ad..773bef0933d46 100644 --- a/recipes/libiconv/all/conanfile.py +++ b/recipes/libiconv/all/conanfile.py @@ -67,7 +67,17 @@ def layout(self): basic_layout(self, src_folder="src") def generate(self): + def requires_fs_flag(): + # See https://github.com/conan-io/conan/issues/11158 + return (self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= "12") or \ + (self.settings.compiler == "msvc" and Version(self.settings.compiler.version) >= "180") + tc = AutotoolsToolchain(self) + if requires_fs_flag(): + # order of setting flags and environment vars is important + # See https://github.com/conan-io/conan/issues/12228 + tc.extra_cflags.append("-FS") + env = tc.environment() if is_msvc(self) or self._is_clang_cl: @@ -84,10 +94,6 @@ def generate(self): env.define("NM", "dumpbin -symbols") env.define("win32_target", "_WIN32_WINNT_VISTA") - if is_msvc(self) and Version(self.settings.compiler.version) >= "12": - # tc.extra_cflags is not respected. - # See https://github.com/conan-io/conan/issues/12228 - env.define("CFLAGS", tc.cflags + ["-FS"]) tc.generate(env)