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

[bug] AutotoolsToolchain does not respect extra_cflags or extra_cxxflags when used with environment vars. #12228

Open
planetmarshall opened this issue Oct 2, 2022 · 4 comments
Assignees

Comments

@planetmarshall
Copy link
Contributor

planetmarshall commented Oct 2, 2022

AutotoolsToolchain does not respect the extra_cflags attribute when used with the environment.

Environment Details (include every applicable attribute)

  • Operating System+version: Ubuntu 22.04
  • Compiler+version: clang 14
  • Conan version: 1.52
  • Python version: 3.10

Steps to reproduce

conan new at/1.0.0 -t -m autotools_lib

Edit the conanfile generate method to add

def generate(self):
  ...  
  env = at_toolchain.environment()
  at_toolchain.extra_cxxflags.append("-march=native")
  at_toolchain.generate(env)
  ...

Run

$ conan create . > log.txt
$ grep march log.txt

Expected result

The -march=native flag should be present in the compiler command line:

/bin/bash ../libtool  --tag=CXX   --mode=link clang++  -stdlib=libc++ -m64 -fPIC -O3 -march=native  -m64 -o libat.la -rpath //lib at.lo

Actual result

The additional flag is not preset

/bin/bash ../libtool  --tag=CXX   --mode=link clang++  -stdlib=libc++ -m64 -fPIC -O3  -m64 -o libat.la -rpath //lib at.lo

Workaround

Use

def generate(self):
  at_toolchain = AutotoolsToolchain(self)
  env = at_toolchain.environment()
  env.define("CXXFLAGS", at_toolchain.cxxflags + ["-march=native"])
  at_toolchain.generate(env)

The flag is present in the output as expected.

@memsharded
Copy link
Member

Hi @planetmarshall

I was checking the unit tests and they seem to cover this functionality.
I also tried manually, and seems to be working fine, I added a random flag and got:

cl : Command line warning D9002 : ignoring unknown option '-someflags'

Apparently it is working fine, could you please re-check?

@planetmarshall
Copy link
Contributor Author

Hi @planetmarshall

Apparently it is working fine, could you please re-check?

If you only use the extra_cflags functionality, it works. If you also use the environment, it doesn't. For example:

def generate(self):
  tc = AutotoolsToolchain(self)
  tc.cflags.append("-someflags")
  tc.generate()

Adds the flag - whereas:

def generate(self):
  tc = AutotoolsToolchain(self)
  env = tc.environment()
  tc.cflags.append("-someflags")
  tc.generate(env)

Does not.

See conan-io/conan-center-index#13263 for a full example

@planetmarshall planetmarshall changed the title [bug] AutotoolsToolchain does not respect extra_cflags or extra_cxxflags [bug] AutotoolsToolchain does not respect extra_cflags or extra_cxxflags when used with environment vars. Oct 3, 2022
@jcar87
Copy link
Contributor

jcar87 commented Oct 3, 2022

Hi @planetmarshall - thank you for reporting this.

I believe this is caused by "capturing" the state of the environment (env = tc.environment()) before manipulating the extra flags, and then passing that variable to tc.generate() - which will in essence override with the values in env instead.

Does it work if you swap the order around?, e.g.:

def generate(self):
  tc = AutotoolsToolchain(self)
  tc.extra_cxxflags.append("-march=native")
  env = tc.environment()
  tc.generate(env)

@planetmarshall
Copy link
Contributor Author

Hi @planetmarshall - thank you for reporting this.

Does it work if you swap the order around?, e.g.:

Yes this works, thanks.

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

3 participants