conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.29k stars 982 forks source link

[bug] Adding mold linker to conanfile causes dependency loop #17333

Open rdong8 opened 2 days ago

rdong8 commented 2 days ago

Describe the bug

OS: Fedora 41 Compiler: Clang 19.1.0 Conan version: 2.9.2

How to reproduce it

Add the sections from this page to your conanfile. Then run your conan install, ie.:

BUILD_DIR=build conan install . -b missing -pr:b local -pr:h default -s build_type=Release -s "&:build_type=Debug"     │

Result:

======== Input profiles ========
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=26
compiler.libcxx=libc++
compiler.version=19
os=Linux
&:build_type=Debug
[platform_tool_requires]
cmake/3.31.0
[conf]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
[buildenv]
CC=clang
CXX=clang++

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=26
compiler.libcxx=libc++
compiler.version=19
os=Linux
[tool_requires]
*: mold/[*]
[conf]
tools.build:exelinkflags=['-fuse-ld=mold']
tools.build:sharedlinkflags=['-fuse-ld=mold']

======== Computing dependency graph ========
Graph root
    conanfile.py: /home/rd8/Projects/cpp_project/conanfile.py
Requirements
    boost/1.86.0#46c984e8737c8b910597294db3838f3b - Cache
    bzip2/1.0.8#d00dac990f08d991998d624be81a9526 - Cache
    libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1 - Cache
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache
Build requirements
    b2/5.2.1#91bc73931a0acb655947a81569ed8b80 - Cache
    mold/2.34.1#4d062e19dee8474c93eddf2af9ea3dfe - Cache
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache
Resolved version ranges
    b2/[>=5.2 <6]: b2/5.2.1
    mold/[*]: mold/2.34.1
    zlib/[>=1.2.11 <2]: zlib/1.3.1
ERROR: There is a cycle/loop in the graph:
    Initial ancestor: mold/2.34.1
    Require: mold/2.34.1
    Dependency: mold/2.34.1
AbrilRBS commented 2 days ago

Hi @rdong8 thanks a lot for taking the time to report this

This is probably not a bug, but expected behaviour.

Your [tool_requires] section on the build profile reads

[tool_requires]
*: mold/[*]

This means that every package in the build context will have mold injected as an extra tool_require.

As * also matches mold, this means that mold is getting itself injected as a tool_require

2 things to note here:

Let me know if this helps :)

rdong8 commented 2 days ago

Hey, thanks for the response. I have made the following changes:

build:

[buildenv]
CC=clang
CXX=clang++

[conf]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config

[platform_tool_requires]
cmake/3.31.0

[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=26
compiler.libcxx=libstdc++11
compiler.version=19
os=Linux

host:

[buildenv]
CC=clang
CXX=clang++

[conf]
tools.build:exelinkflags=['-fuse-ld=mold']
tools.build:sharedlinkflags=['-fuse-ld=mold']

[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=26
compiler.libcxx=libc++
compiler.version=19
os=Linux

[tool_requires]
!mold/*: mold/[*]

However I still do have the issue with the dependency loop:

======== Computing dependency graph ========
Graph root
    conanfile.py: /home/rd8/Projects/cpp_project/conanfile.py
Requirements
    boost/1.86.0#46c984e8737c8b910597294db3838f3b - Cache
    bzip2/1.0.8#d00dac990f08d991998d624be81a9526 - Cache
    catch2/3.7.1#431d772165ed0bc5adaabaa44a9f53ca - Cache
    libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1 - Cache
    spdlog/1.14.1#4fd40d9cbc1978247443a10d2ace58fd - Cache
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache
Build requirements
    b2/5.2.1#91bc73931a0acb655947a81569ed8b80 - Cache
    cmake/3.31.0 - Platform
    mold/2.34.1#4d062e19dee8474c93eddf2af9ea3dfe - Cache
    xxhash/0.8.2#03fd1c9a839b3f9cdf5ea9742c312187 - Cache
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2 - Cache
Resolved version ranges
    b2/[>=5.2 <6]: b2/5.2.1
    mold/[*]: mold/2.34.1
    zlib/[>=1.2.11 <2]: zlib/1.3.1

======== Computing necessary packages ========
spdlog/1.14.1: Main binary package '4c4d5237d406fd4c79c7bef05af533c8939e3c58' missing
spdlog/1.14.1: Checking 5 compatible configurations
spdlog/1.14.1: Compatible configurations not found in cache, checking servers
spdlog/1.14.1: '6679d20ab72b8fd423ecd46d0746e46c39770bcf': compiler.cppstd=20
spdlog/1.14.1: '60e040ab069a2b5d5c85ecd731af4cf86f9c230c': compiler.cppstd=gnu20
spdlog/1.14.1: '603d38981bae7e65f2e73ff7f9f51e59a201279e': compiler.cppstd=23
spdlog/1.14.1: '494d27793e5f9f33c2929a3b7c28a43c29aead3f': compiler.cppstd=gnu23
spdlog/1.14.1: '0b9f5ef239a0d52320e31bb08c49326c6a4621c3': compiler.cppstd=gnu26
boost/1.86.0: Main binary package 'c123612e482b0a8ecc61a6ddb0a62d25e7578366' missing
boost/1.86.0: Checking 5 compatible configurations
boost/1.86.0: Compatible configurations not found in cache, checking servers
boost/1.86.0: 'af3e0258503efbefd0af55b4f2db656adc861436': compiler.cppstd=20
boost/1.86.0: '3427da6b3ac26939436d8224d9e5ec48f192a412': compiler.cppstd=gnu20
boost/1.86.0: 'cbf236643def2491b4668a4a48b7a8131c6d5623': compiler.cppstd=23
boost/1.86.0: 'c9e387a2d958cc83509b4521866344929375614a': compiler.cppstd=gnu23
boost/1.86.0: '728d5f8f5ab862ab57258b1bfca76baba484a027': compiler.cppstd=gnu26
Requirements
    boost/1.86.0#46c984e8737c8b910597294db3838f3b:c123612e482b0a8ecc61a6ddb0a62d25e7578366 - Build
    bzip2/1.0.8#d00dac990f08d991998d624be81a9526:ab19b9bfc1b47ea17e1a675221a2f0b1e27ebba5 - Build
    catch2/3.7.1#431d772165ed0bc5adaabaa44a9f53ca:882cd1aca82e6fa218c2563f3d8e8bee421ac4a8 - Build
    libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1:035983102d94f5d9d7256017a5fd89651d1294c3 - Build
    spdlog/1.14.1#4fd40d9cbc1978247443a10d2ace58fd:4c4d5237d406fd4c79c7bef05af533c8939e3c58 - Build
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2:035983102d94f5d9d7256017a5fd89651d1294c3 - Build
Build requirements
    b2/5.2.1#91bc73931a0acb655947a81569ed8b80:63fead0844576fc02943e16909f08fcdddd6f44b#f9c46d924270b1920fa5398114be2576 - Download (conancenter)
    cmake/3.31.0 - Platform
    mold/2.34.1#4d062e19dee8474c93eddf2af9ea3dfe:77dc507434abadcc87e1517333a94365a4b99b07 - Build
    xxhash/0.8.2#03fd1c9a839b3f9cdf5ea9742c312187:aa3784fb750b4514cd847a028afd1f7efa4e7711 - Build
    zlib/1.3.1#f52e03ae3d251dec704634230cd806a2:035983102d94f5d9d7256017a5fd89651d1294c3 - Build
ERROR: There is a loop in the graph (some packages already ommitted):
zlib/1.3.1 (Build) -> ['mold/2.34.1']
mold/2.34.1 (Build) -> ['zlib/1.3.1', 'xxhash/0.8.2', 'cmake/3.31.0']
bzip2/1.0.8 (Build) -> ['mold/2.34.1']
catch2/3.7.1 (Build) -> ['mold/2.34.1']
libbacktrace/cci.20210118 (Build) -> ['mold/2.34.1']
spdlog/1.14.1 (Build) -> ['mold/2.34.1']
boost/1.86.0 (Build) -> ['zlib/1.3.1', 'bzip2/1.0.8', 'libbacktrace/cci.20210118', 'b2/5.2.1', 'mold/2.34.1']

This graph is ill-formed, and cannot be installed
Most common cause is having dependencies both in build and host contexts
forming a cycle, due to tool_requires having transitive requires.
Check your profile [tool_requires] and recipe tool and regular requires
You might inspect the dependency graph with:
  $ conan graph info . --format=html > graph.html

Would it help if I installed mold external to conan and somehow just told conan to use that? I'm not sure if I follow fully but it seems like part of the problem is mold itself needing to be built.