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

[question] How to cross build to the same os/arch combination when using autotools. #14947

Closed
1 task done
CMelanie opened this issue Oct 16, 2023 · 7 comments
Closed
1 task done
Assignees

Comments

@CMelanie
Copy link
Contributor

What is your question?

Using Conan 1.60.0, I'm working on a cross build from Linux to a different Linux system (so same settings.os and settings.arch, but different glibc, etc.). To differentiate between these builds, some extra subsettings to settings.os were added. Building works fine this way for cmake in combination with a custom toolchain.

However, using the template from the conan center for autotools builds, it doesn't work correctly. Looking at the cross_building check, I see it only takes os and arch into account, and not the extra subsettings, so I'm guessing this is not the way to do it.
So I'm wondering, what would be the right approach to cross build to the same os/arch combination when using the autotools toolchain?

Have you read the CONTRIBUTING guide?

  • I've read the CONTRIBUTING guide
@memsharded
Copy link
Member

Hi @CMelanie

Thanks for your question.

The template for ConanCenter autotools contains a lot of things, including some backwards compatibility for the case when not using 2 profiles (which is very recommended for cross-building).
It would be great to reduce the problem scope a bit, and reduce it to the conan new pkg/0.1 -m=autotools_lib if possible.

I suspect that the main issue is the cross_building() usage inside AutotoolsToolchain, that is not working fine in the cross-build scenario when both os and arch match exactly, could you please confirm this is the case? Thanks!

@CMelanie
Copy link
Contributor Author

Hello @memsharded ,

thank you for your answer.

I'm using two profiles, indeed. A standard Linux one as build profile, and a host profile which is setting the environment with a different compiler and such, and defines the os along the lines of:

os=Linux
os.custom_distro="my_custom_distro"
os.custom_distro_version="1.2"

Indeed, the template contains a lot (they're very handy, though, great starting point!), but I trimmed down what I thought wasn't needed (hopefully I didn't trim down too much).
With this in the conan file:

    # [...]

    def configure(self):
        # Plain C library.
        self.settings.rm_safe("compiler.libcxx")
        self.settings.rm_safe("compiler.cppstd")
    
    def generate(self):
        autotools_toolchain = AutotoolsToolchain(self)
        autotools_toolchain.fpic = True
        autotools_toolchain.configure_args.extend( <a bunch of package specific settings>)
        autotools_toolchain.generate()

    def build(self):
        autotools = Autotools(self)
        autotools.autoreconf()
        autotools.configure()
        autotools.make()

    # [...]

it builds correctly if the host arch is different from the build arch. However, if the arch is the same, it fails due to mixing up glibc.
(So I started experimenting with setting the environment as shown in the template, and running into cross_building() not picking up that it's cross buiding, hence my question.)

@jcar87
Copy link
Contributor

jcar87 commented Oct 17, 2023

Hi @CMelanie, I believe this could be caused by Conan computing the triplet based on only os/arch - so it has no way of defining a different one in this case.

However, you could try defining the tools.gnu:host_triplet to a value that is different from the "build" value - anything that is valid but different should cause autotools to use the "cross-build" path.

You can define it in the command line with -c tools.gnu:host_triplet= or in the profile in the [conf] section.

@CMelanie
Copy link
Contributor Author

Hello @jcar87 ,

thank you for the suggestion. I've tried adding this:

[conf]
tools.gnu:host_triplet=powerpc-linux-gnu

to the host profile (using powerpc for the sake of experiment). However, I keep having the same error where it's using the wrong glibc.

@franramirez688
Copy link
Contributor

franramirez688 commented Oct 17, 2023

Hi @CMelanie ,

I think something that could work for that (given the limitations of that cross_building() function) is to define directly the flag variables for the build context and/or overwrite any triplets/configuration arguments:

    def generate(self):
        autotools_toolchain = AutotoolsToolchain(self)
        autotools_toolchain.fpic = True
        autotools_toolchain.configure_args.extend( [
                 <a bunch of package specific settings>,
        ])
        # Update any `configure_arg` introduced by Conan:
        autotools_toolchain.update_configure_args.extend( {
                 "--host": "your_triplet",
                 "--build": "your_build_triplet",
        })
        # Also, these flags will be appended to the default Conan ones in build time
        autotools_toolchain.extra_cxxflags.append("--flagxxx")
        autotools_toolchain.extra_cflags.append("--flagxxx")
        autotools_toolchain.extra_ldflags.append("--flagxxx")
        autotools_toolchain.extra_defines.append("-Ddef")
       # build scope by default. Otherwise, use autotools_toolchain.generate(env="host") instead
        autotools_toolchain.generate()

Could this help to solve the issue?

@CMelanie
Copy link
Contributor Author

Hello @franramirez688 ,

That works if I use a fake triplet (powerpc-linux-gnu instead of x86_64) for the --build option. Great!

Thank you very much for your help, all!

@franramirez688
Copy link
Contributor

So glad to hear that @CMelanie 👏
Closing the issue as it seems solved. Don't hesitate to open it again if you face any other related problems.
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

4 participants