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] Meson + freetype fail to cross compile #16529

Closed
Slashcash opened this issue Jun 23, 2024 · 5 comments
Closed

[question] Meson + freetype fail to cross compile #16529

Slashcash opened this issue Jun 23, 2024 · 5 comments
Assignees

Comments

@Slashcash
Copy link

Slashcash commented Jun 23, 2024

Hi, I am having an hard time to cross compile freetype since the recipe has been moved to Meson.

I am cross-compiling with an aarch-64 buildroot-provided toolchain. It is installed into the system with a custom recipe:

class Toolchain(ConanFile):
    name = "toolchain-linux-aarch64-gcc-11.3"
    version = "1.0"

    def source(self):
        get(self, "https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--glibc--stable-2022.08-1.tar.bz2",
                  **strip_root=True)

it gets downloaded and relocated within the context of the recipe then since the toolchain provides a cmake toolchain file I just do:

    def package_info(self):
        self.conf_info.append("tools.cmake.cmaketoolchain:user_toolchain", os.path.join(self.package_folder, "share", "buildroot", "toolchainfile.cmake"))

With this setup I have been able to cross-compile pretty much every dependency (without resorting to define variables to relocate compilers/linkers/...)

For this reason my host profile is pretty simple:

{% set os, arch, compiler, compiler_version, type = profile_name.split('-') %}
{% set toolchain = "toolchain-{}-{}-{}-{}/1.0".format(os, arch, compiler, compiler_version) %}

{% if type == "debug" %}
    {% set loglevel = "trace" %}
    {% set btype = "Debug" %}
{% else %}
    {% set loglevel = "info" %}
    {% set btype = "Release" %}
{% endif %}

[settings]
os={{ os.capitalize() }}
arch={{ arch }}
compiler={{ compiler }}
compiler.version={{ compiler_version }}
compiler.libcxx=libstdc++11
build_type={{ btype }}

[tool_requires]
{{ toolchain }}
cmake/3.27.0

[runenv]
SPDLOG_LEVEL={{ loglevel }}

[conf]
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=True

Apart from the jinja noise there is really nothing special.

When cross-compiling freetype with this toolchain/profile I get:

../src/meson.build:26:0: ERROR: 'c' compiler binary not defined in cross or native file

and surely enough the conan-generated conan_meson_cross.ini have empty definitions for both the c and the cpp compiler:

[properties]
needs_exe_wrapper = true

[constants]
preprocessor_definitions = []

[project options]
wrap_mode = 'nofallback'
bindir = 'bin'
sbindir = 'bin'
libexecdir = 'bin'
includedir = 'include'
libdir = 'lib'
brotli = 'enabled'
bzip2 = 'enabled'
harfbuzz = 'disabled'
png = 'enabled'
tests = 'disabled'
zlib = 'system'


[binaries]
c = ''
cpp = ''
pkgconfig = '/root/.conan2/p/pkgco03f8fb03aa80a/p/bin/pkgconf'
pkg-config = '/root/.conan2/p/pkgco03f8fb03aa80a/p/bin/pkgconf'

[built-in options]
buildtype = 'release'
default_library = 'static'
b_ndebug = 'true'
backend = 'ninja'
pkg_config_path = '/root/.conan2/p/b/freet0516abaf9bd52/b/build-release/conan'
# C/C++ arguments
c_args = [] + preprocessor_definitions
c_link_args = []
cpp_args = [] + preprocessor_definitions
cpp_link_args = []

[build_machine]
system = 'linux'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'armv8'
endian = 'little'

Am I doing something really wrong? I am experiencing this with Conan 2.4.1

@Slashcash Slashcash changed the title [bug] Meson + freetype fail to cross compile [question] Meson + freetype fail to cross compile Jun 23, 2024
@Slashcash
Copy link
Author

Probably not a bug so changing the title. Probably something related to the fact that I am missing a correctly generated MesonToolchain?

@franramirez688 franramirez688 self-assigned this Jun 24, 2024
@franramirez688
Copy link
Contributor

Hi @Slashcash - Thanks for opening the issue!

I think that we only need to set the compiler_executables in your profile:

your_host_profile

{% set os, arch, compiler, compiler_version, type = profile_name.split('-') %}
{% set toolchain = "toolchain-{}-{}-{}-{}/1.0".format(os, arch, compiler, compiler_version) %}
# .....

[conf]
tools.build:compiler_executables={'c': '/path/to/aarch64-gcc-11.3', 'cpp': '/path/to/aarch64-g++-11.3'}
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=True

Let me know if setting that solved your issue 😁

@Slashcash
Copy link
Author

Slashcash commented Jun 24, 2024

Hi @Slashcash - Thanks for opening the issue!

I think that we only need to set the compiler_executables in your profile:

your_host_profile

{% set os, arch, compiler, compiler_version, type = profile_name.split('-') %}
{% set toolchain = "toolchain-{}-{}-{}-{}/1.0".format(os, arch, compiler, compiler_version) %}
# .....

[conf]
tools.build:compiler_executables={'c': '/path/to/aarch64-gcc-11.3', 'cpp': '/path/to/aarch64-g++-11.3'}
tools.system.package_manager:mode=install
tools.system.package_manager:sudo=True

Let me know if setting that solved your issue 😁

I couldn't do this because the compiler path is unknown at profile-level (it ends up being deployed by Conan in a non predicible folder everytime)

But putting your suggestion in my toolchain recipe like this:

self.conf_info.define("tools.build:compiler_executables", {"c": os.path.join(compiler_path, compiler_c), "cpp": os.path.join(self.package_folder, compiler_cxx)})

works indeed! Thanks a lot!

Now I am confused a bit because I get why it was working up until now with CMake-based recipe. What I don't get is how it was magically working with make based recipe that I had in my dependencies. It's my understanding that this should have failed in a similar fashion! :D But that's another matter.

@franramirez688
Copy link
Contributor

works indeed! Thanks a lot!

That's great!

Now I am confused a bit because I get why it was working up until now with CMake-based recipe. What I don't get is how it was magically working with make based recipe that I had in my dependencies. It's my understanding that this should have failed in a similar fashion! :D But that's another matter.

It was working because of your toolchain-xxxx/1.0 as tool_requires injection. As the older versions were CMake-based, that toolchain was correctly injecting all the needed variables, but as it's Meson-based now, those variables are not affecting the freetype recipe 😓

@franramirez688
Copy link
Contributor

@Slashcash let me close the issue and put it as resolved.

Anyway, do not hesitate to reopen it if you have any other doubts.

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

2 participants