conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
963 stars 1.77k forks source link

[package] yasm/1.3.0: build fails on Windows with MSVC #24648

Open elvisdukaj opened 3 months ago

elvisdukaj commented 3 months ago

Description

I am trying to build yasm with msvc but I have build errors.

Package and Environment Details

Conan profile

======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=msvc compiler.cppstd=17 compiler.runtime=dynamic compiler.runtime_type=Release compiler.version=193 os=Windows [tool_requires] *: ninja/1.11.1, cmake/3.28.1 [conf] tools.cmake.cmaketoolchain:generator=Ninja Multi-Config tools.env.virtualenv:powershell=False

Profile build: [settings] arch=x86_64 build_type=Release compiler=msvc compiler.cppstd=20 compiler.runtime=dynamic compiler.runtime_type=Release compiler.version=193 os=Windows [conf] tools.cmake.cmaketoolchain:generator=Ninja tools.env.virtualenv:powershell=False

Steps to reproduce

conan create conan/center-index/recipes/yasm/all --version=1.3.0 --build=missing

Logs

Click to expand log ``` ======== Input profiles ======== Profile host: [settings] arch=x86_64 build_type=Release compiler=msvc compiler.cppstd=17 compiler.runtime=dynamic compiler.runtime_type=Release compiler.version=193 os=Windows [tool_requires] *: ninja/1.11.1, cmake/3.28.1 [conf] tools.cmake.cmaketoolchain:generator=Ninja Multi-Config tools.env.virtualenv:powershell=False Profile build: [settings] arch=x86_64 build_type=Release compiler=msvc compiler.cppstd=20 compiler.runtime=dynamic compiler.runtime_type=Release compiler.version=193 os=Windows [conf] tools.cmake.cmaketoolchain:generator=Ninja tools.env.virtualenv:powershell=False ======== Computing dependency graph ======== Graph root cli Requirements yasm/1.3.0#f8b676849bfc7f0fb8c099374c4dd32e - Cache Build requirements cmake/3.28.1#6a1e0a2ffe43d562b8228c1a5aaaac61 - Cache ninja/1.11.1#cd30ca226f2040a979c359ebca4817d5 - Cache ======== Computing necessary packages ======== Requirements yasm/1.3.0#f8b676849bfc7f0fb8c099374c4dd32e:723257509aee8a72faf021920c2874abc738e029 - Build Build requirements cmake/3.28.1#6a1e0a2ffe43d562b8228c1a5aaaac61:522dcea5982a3f8a5b624c16477e47195da2f84f#29e6903b5006c2b2f81003c9ebf7551b - Cache ninja/1.11.1#cd30ca226f2040a979c359ebca4817d5:723257509aee8a72faf021920c2874abc738e029#1a592c653c6d8742bf921f77d92580f4 - Cache ======== Installing packages ======== cmake/3.28.1: Already installed! (1 of 3) cmake/3.28.1: Appending PATH environment variable: C:\Users\edukaj\.conan2\p\b\cmake658582c322d1b\p\bin cmake/3.28.1: Appending PATH environment variable: C:\Users\edukaj\.conan2\p\b\cmake658582c322d1b\p\bin ninja/1.11.1: Already installed! (2 of 3) yasm/1.3.0: Calling source() in C:\Users\edukaj\.conan2\p\yasm50c65a0373958\s\src -------- Installing package yasm/1.3.0 (3 of 3) -------- yasm/1.3.0: Building from source yasm/1.3.0: Package yasm/1.3.0:723257509aee8a72faf021920c2874abc738e029 yasm/1.3.0: Copying sources to build folder yasm/1.3.0: Building your package in C:\Users\edukaj\.conan2\p\b\yasm0a1497e8cfb40\b yasm/1.3.0: Calling generate() yasm/1.3.0: Generators folder: C:\Users\edukaj\.conan2\p\b\yasm0a1497e8cfb40\b\build\generators yasm/1.3.0: CMakeToolchain generated: conan_toolchain.cmake yasm/1.3.0: CMakeToolchain generated: C:\Users\edukaj\.conan2\p\b\yasm0a1497e8cfb40\b\build\generators\CMakePresets.json yasm/1.3.0: CMakeToolchain generated: C:\Users\edukaj\.conan2\p\b\yasm0a1497e8cfb40\b\src\CMakeUserPresets.json yasm/1.3.0: Generating aggregated env files yasm/1.3.0: Generated aggregated env files: ['conanbuild.bat', 'conanrun.bat'] yasm/1.3.0: Calling build() yasm/1.3.0: Apply patch (conan): CMake 3.0+ compatibility yasm/1.3.0: Running CMake.configure() yasm/1.3.0: RUN: cmake -G "Ninja Multi-Config" -DCMAKE_TOOLCHAIN_FILE="generators/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="C:/Users/edukaj/.conan2/p/b/yasm0a1497e8cfb40/p" -DYASM_BUILD_TESTS="OFF" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" "C:/Users/edukaj/.conan2/p/b/yasm0a1497e8cfb40/b/src" conanvcvars.bat: Activating environment Visual Studio 17 - amd64 - winsdk_version=None - vcvars_ver=14.3 [vcvarsall.bat] Environment initialized for: 'x64' CMake Deprecation Warning at CMakeLists.txt:1 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 3.5 will be removed from a future version of CMake. Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions. -- Using Conan toolchain: C:/Users/edukaj/.conan2/p/b/yasm0a1497e8cfb40/b/build/generators/conan_toolchain.cmake -- The C compiler identification is MSVC 19.39.33523.0 -- The CXX compiler identification is MSVC 19.39.33523.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.39.33519/bin/Hostx64/x64/cl.exe - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for locale.h -- Looking for locale.h - found -- Looking for libgen.h -- Looking for libgen.h - not found -- Looking for unistd.h -- Looking for unistd.h - not found -- Looking for direct.h -- Looking for direct.h - found -- Looking for stdint.h -- Looking for stdint.h - found -- Looking for abort -- Looking for abort - found -- Looking for getcwd -- Looking for getcwd - found -- Looking for toascii -- Looking for toascii - not found -- Looking for dlopen in dl -- Looking for dlopen in dl - not found CMake Warning (dev) at ConfigureChecks.cmake:37 (INCLUDE): Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules are removed. Run "cmake --help-policy CMP0148" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Call Stack (most recent call first): CMakeLists.txt:36 (INCLUDE) This warning is for project developers. Use -Wno-dev to suppress it. -- Found PythonInterp: C:/Users/edukaj/.virtualenvs/conan-center-index-778lw3h1/Scripts/python.exe (found version "3.11.3") -- Standard modules: arch_lc3b;arch_x86;listfmt_nasm;parser_gas;parser_nasm;preproc_nasm;preproc_raw;preproc_cpp;preproc_gas;dbgfmt_cv8;dbgfmt_dwarf2;dbgfmt_null;dbgfmt_stabs;objfmt_dbg;objfmt_bin;objfmt_elf;objfmt_elf32;objfmt_elf64;objfmt_elfx32;objfmt_coff;objfmt_win32;objfmt_win64;objfmt_macho;objfmt_macho32;objfmt_macho64;objfmt_rdf;objfmt_xdf -- Generating standard plugin initialization file -- Configuring done (14.6s) -- Generating done (0.2s) -- Build files have been written to: C:/Users/edukaj/.conan2/p/b/yasm0a1497e8cfb40/b/build yasm/1.3.0: Running CMake.build() yasm/1.3.0: RUN: cmake --build "C:\Users\edukaj\.conan2\p\b\yasm0a1497e8cfb40\b\build" --config Release -- -j8 conanvcvars.bat: Activating environment Visual Studio 17 - amd64 - winsdk_version=None - vcvars_ver=14.3 [vcvarsall.bat] Environment initialized for: 'x64' ninja: error: 'cmake_object_order_depends_target_yasmstd_DEBUG', needed by 'C:/Users/edukaj/.conan2/p/b/yasm0a1497e8cfb40/b/build/modules/init_plugin.c', missing and no known rule to make it yasm/1.3.0: ERROR: Package '723257509aee8a72faf021920c2874abc738e029' build failed yasm/1.3.0: WARN: Build folder C:\Users\edukaj\.conan2\p\b\yasm0a1497e8cfb40\b\build ERROR: yasm/1.3.0: Error in build() method, line 86 cmake.build() ConanException: Error 1 while executing ```
elvisdukaj commented 3 months ago

Interesting: to fix the issue I had to remove the ninja and cmake from the tool requires. So with the following recipe:

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
tools.env.virtualenv:powershell=False

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.runtime_type=Release
compiler.version=193
os=Windows
[conf]
tools.cmake.cmaketoolchain:generator=Ninja
tools.env.virtualenv:powershell=False

It builds fine

elvisdukaj commented 3 months ago

Reporting the discussion from https://github.com/conan-io/conan/issues/16689#issuecomment-2233697696 for reference.

@memsharded replied with:

ninja: error: 'cmake_object_order_depends_target_yasmstd_DEBUG', needed by 'C:/Users/edukaj/.co

this would look like an issue in Ninja Multi-Config, because the Release configuration is being built but Ninja is looking for Debug somehow. Probably is not because of the [tool_requires], but because the change in tools.cmake.cmaketoolchain:generator=Ninja from Ninja Multi-Config

I confirm @memsharded assumption is correct: https://github.com/conan-io/conan/issues/16689#issuecomment-2235794753

memsharded commented 2 months ago

This wouldn't be an issue of the Conan recipe, but an issue in the upstream CMakeLists.txt, defining the CMAKE_BUILD_TYPE, which will confuse the CMake Ninja Multi-Config generator, see https://github.com/yasm/yasm/blob/121ab150b3577b666c79a79f4a511798d7ad2432/CMakeLists.txt#L24

That CMakeLists.txt is apparently 10 years old, Ninja Multi-Config wasn't a thing back then, but it seems unlikely it will be fixed in the upstream if it hasn't been updated in 10 years.

I suspect that Ninja Multi-Config would be an issue in many other packages in ConanCenter doing similar outdated practices, I am not sure it is worth fighting this battle.

memsharded commented 2 months ago

I have tried to do a patch to remove the IF(NOT CMAKE_BUILD_TYPE) logic completely, but it seems not enough, there might be something else in the build of the library that disallows using Ninja Multi-Config.

memsharded commented 2 months ago

The following fixes it:

diff --git a/recipes/yasm/all/conanfile.py b/recipes/yasm/all/conanfile.py
index 7e50843bcd..de3dc02d90 100644
--- a/recipes/yasm/all/conanfile.py
+++ b/recipes/yasm/all/conanfile.py
@@ -1,7 +1,7 @@
 from conan import ConanFile
 from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
 from conan.tools.env import VirtualBuildEnv
-from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
+from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir, replace_in_file
 from conan.tools.gnu import Autotools, AutotoolsToolchain
 from conan.tools.layout import basic_layout
 from conan.tools.microsoft import is_msvc
@@ -49,6 +49,7 @@ class YASMConan(ConanFile):
     def source(self):
         get(self, **self.conan_data["sources"][self.version][0],
                   destination=self.source_folder, strip_root=True)
+        replace_in_file(self, "modules/CMakeLists.txt", "SET_SOURCE_FILES_PROPERTIES(init_plugin.c GENERATED)", "")

     def _generate_autotools(self):
         env = VirtualBuildEnv(self)

The problem is marking a file as GENERATED without adding the origin makes CMake + Ninja Multi-Config to introduce an apparently incorrect dependency on the different build-type targets: https://gitlab.kitware.com/cmake/cmake/-/issues/20608

From that ticket:

The purpose of those order-only dependencies is to say "nothing told CMake what generates this file, so we assume that something in one of the targets on which the target that compiles the source file depends will generate it". If we leave out the order-only dependencies, Ninja may try compiling the source file before it is generated.

To fix this, the "Assume dependencies for generated source file" section may need to be generated separately for each configuration. If that is too disruptive, I'd be okay with just telling projects they have to fix this to work with the new generator. The fix will improve behavior with plain Ninja too. It really is a case of needed dependency information not being provided to CMake.

Doing this would be a large change in yasm build scripts, probably not worth it.

elvisdukaj commented 2 months ago

Thank you @memsharded for the investigation! Yes probably the fix it's too invasive but we can submit a PR to the upstream project 😀