mesonbuild / meson

The Meson Build System

Home Page:http://mesonbuild.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing sys_root to the --sysroot compiler argument

cyuria opened this issue · comments

To set up a basic cross compilation environment for a c project, the following cross compilation file is required.

[binaries]
...

[host_machine]
...

[built-in options]
c_args = [ '--sysroot=/path/to/sysroot/' ]
c_link_args = [ '--sysroot=/path/to/sysroot/' ]

However, these two lines are required individually for every language in the project. Also, once more complexity is added, properties like sys_root are set.

sys_root is documented to set the PKG_CONFIG_SYSROOT_DIR environment variable, however it is not entirely clear that this is the case at first glance.

This issue was raised in #7722, however there has been no activity on this in over three years. It seems that #3803 is also related to this same problem.

Considerations:

  1. In #3803, a compiler support issue is raised, however (and I am by no means knowledgeable on this) I would be surprised if any compilers actually had this problem. Either way, it should be trivial to add a check and if --sysroot isn't supported on the compiler to either do nothing/raise a warning or error, include/link the relevant $sysroot/usr/include and $sysroot/usr/lib directories or do something compiler specific. If compiler support is really a problem, it would still make sense to update the docs and close #3803 to avoid confusion.

  2. In #7722 a possible issue with pkgconfig was also raised, the way I see it, this can either be ignored or solved by passing a sensible default which can be overwritten #7722 (comment).

  3. The only problem I can foresee would be in a scenario where --sysroot should explicitly be NOT passed to the compiler/linker but the pkgconfig env var is still required for some reason. In that incredibly unlikely event, I believe it should be possible to manually set the PKG_CONFIG_SYSROOT_DIR environment variable when calling meson if you absolutely have to (I imagine there is also another way of doing this, but I cannot for the life of me find it in the docs1).

I would be willing to work on a PR for this if anyone wants it. If anyone wants to make a PR for this issue, please do so, I just want it solved.

tldr; It would be lovely if we can just pass the sys_root variable to the compiler (this would fix #7722 and #3803). Then cross compilation files can look like this: (and it would save 2 lines per language in a very large quantity of cross compilation files)

[binaries]
...

[host_machine]
...

[properties]
sys_root = '/path/to/sysroot'

It looks like #9993 might also have something to do with this issue, although I haven't encountered the problem it claims to solve myself.

Footnotes

  1. If it doesn't already exist, a way to set env vars from the cross compilation files would probably be nice. If it does exist, some findable documentation on it would definitely be nice