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

[feature] new setting on compiler: arbitrary setting forcing additional compiler flags. #6878

Closed
1 task done
fulara opened this issue Apr 18, 2020 · 4 comments
Closed
1 task done
Assignees
Milestone

Comments

@fulara
Copy link
Contributor

fulara commented Apr 18, 2020

Sometimes there is a need to propagate a flags throughout the build tree and force rebuilding of the whole dependency tree.
These flags are usually very specific - and compiler dependent.
For example: march on gcc:
https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/x86-Options.html
We want to build a build that targets a sets of CPUs and using march would allow gcc to build the code with the extensions, unfortunatelly I dont think there is a good way of doing this in conan right now.

I think this could be solved by adding new setting: compiler.compilation_flags
compiler.compilation_flags : Any
compiler.linking_flags : Any
Yes I know that settings dont currently handle 'Any' but options do.. so settings could as well?
Anyway, not having 'Any' but a list of values would be fine like:
compiler.compilation_flags : ["-march=x86-64 -xyz", ..]

With this enabled I would imagine the conan would propagate these flags to compilation flags and linking flags.

We could use a workaround and just add an option and somehow before every build recognize whether these settings are set and then export environmental variables, but there is no strict binding that people would remember to build their projects with this flag.
If conan instead was doing that - then that would create a reliable contract.

Use cases known by me where this would be useful:

  1. sanitizers
  2. lto enabling
  3. defining arch.

This proposal could possibly affect these currently open issues:
#1346
#847

@jgsogo jgsogo self-assigned this Apr 23, 2020
@jgsogo
Copy link
Contributor

jgsogo commented Apr 23, 2020

Hi!

Here I see you need a couple of things:

  • First you need all your packages get a new packageID, so the build is triggered again (and those binaries are identified). Using a custom setting in the profile (adding it to settings.yml) seem the way to go.
  • Then you need to pass the proper flags to the compiler and here it is the tricky part. Our helpers cannot know about your custom setting so they won't take into account (does it make sense for Conan to have a compiler.cxx_flags and pass its value to the compiler?) but you can set an environment variable in your profile (CXX_FLAGS) that will be taken into account by your compiler.

Does it make sense for you?

@fulara
Copy link
Contributor Author

fulara commented Apr 23, 2020

Hello @jgsogo
Yes, I am very well aware of that.
I think your 1st point corresponds ot mine:

We could use a workaround and just add an option and somehow ...

I should have worded this differently (used setting word instead of option ) apologies.
But this is very brittle dont you think? And there is no contract at all between user setting setting and exporting variable.
I am using this for sanitizers build - but there are multiple cases and I think this is a common scenario, consider LTO.
If you want LTO to work properly all your projects have to be compiled with lto flag.

I was thinking of conan supported settings cxx_flags and ldd_flags that it would actually force to be environmental variables.
I think depending on the arch setting - it does sets some variables? but I may be wrong there.

@AndreyMlashkin
Copy link

For me it is a desired behaviour, that packages with different compilation flags have different packageID. Can I archive it somehow?

@memsharded memsharded added this to the 2.0 milestone Jun 29, 2022
@memsharded
Copy link
Member

Yes, this has been implemented in Conan 2.0:

  • tools.build:cxxflags are new conf values that will be automatically propagated to build system integrations (this is backported to Conan 1.X)
  • The conf tools.info.package_id:confs=["tools.build:cxxflags"] allows defining which specific conf values become part of the package_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants