conan-io / conan

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

[question] How to use MinGW as build profile on Windows? #16131

Open elvisdukaj opened 2 months ago

elvisdukaj commented 2 months ago

What is your question?

It's already a full day and I think I am missing some very basic knowledge about conan.

What I want to achieve:

I am setting up a private conan-center-index and I am preparing the build environment. I would like to avoid installing Visual C++ as it's not needed. We are mainly targeting Android, and the host can be Windows, Linux or MacOS. Some packages requires a native build (i.e. ninja, protobuf, grpc). I was thinking that I can use MinGW as build profile for buildiing the requirements. But I also would like to execute unit tests on Windows as well. So MinGW would be used both as host and build profile. I don't want to install the toolchain on the host, conan has already a mingw-builds package and that's enough.

What I've tried:

I took the most naive approach:

mingw profile used for building the host packages:

Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=20
compiler.libcxx=libstdc++
compiler.version=12.2
os=Windows
[tool_requires]
*: mingw-builds/12.2.0
*: ninja/1.11.1
*: cmake/3.28.1
[conf]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
tools.env.virtualenv:powershell=False

mingw_build used for building tool requirments:

Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=20
compiler.libcxx=libstdc++
compiler.version=12.2
os=Windows
[tool_requires]
*: mingw-builds/12.2.0
[conf]
tools.cmake.cmaketoolchain:generator=Ninja Multi-Config
tools.env.virtualenv:powershell=False

Now the issue is that conan is detecting a cycle/loop in the graph, indeed mingw-builds is there twice. How can I solve this problem? What options do I have? Do I need to a pre-installed toolchain?

How I would like to use the two profiles:

The tools should be built only with the build profile:

conan create recipes/ninja/all --version 1.11.1 -pr:h mingw12.2_build -pr:b mingw12.2_build

The packages should be built in a similar way:

conan create recipes/ninja/all --version 1.11.1 -pr:h mingw12.2 -pr:b mingw12.2_build

Would that be possible?

Have you read the CONTRIBUTING guide?

elvisdukaj commented 2 months ago

It seems a bumpy road. I tried also to dupplicate the mingw-builds recipes, remove the 7z build dependency and use this profile for building but I have other issues while running the tests. the libstdc++.dll library is not found in the system. Using MinGW as default toolchain seems problematic as the c++ standard library is not found during the run.

memsharded commented 2 months ago

I am setting up a private conan-center-index and I am preparing the build environment.

Plese read https://blog.conan.io/2024/04/23/Introducing-local-recipes-index-remote.html, it might help

Some packages requires a native build (i.e. ninja, protobuf, grpc). I was thinking that I can use MinGW as build profile for buildiing the requirements. But I also would like to execute unit tests on Windows as well. So MinGW would be used both as host and build profile.

Support for ConanCenter recipes in conan-center-index for msvc compiler will be much better than for MinGW because ConanCenter only builds and test packages in Windows for msvc. So even if contributors submit patches to support MinGW, the support will be generally inferior. Probably it is not

Now the issue is that conan is detecting a cycle/loop in the graph, indeed mingw-builds is there twice. How can I solve this problem? What options do I have? Do I need to a pre-installed toolchain?

Yes, this is expected, if mingw is a build-require and there is a

[tool_requires]
*: mingw-builds/12.2.0

in the profile, it will try to add that tool-requires to all tool-requires, including itself, in an infinite loop. You can define other patterns to break the loop, something like:

[tool_requires]
ninja/*: mingw-builds/12.2.0

If you need something more complex you can use jinja templates.

conan create recipes/ninja/all --version 1.11.1 -pr:h mingw12.2_build -pr:b mingw12.2_build

There are some UX improvements you can do here:

Using MinGW as default toolchain seems problematic as the c++ standard library is not found during the run.

This might be a recipe-related issue, more than a Conan one, trying with conan new templates first to triage issues is recommended.