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

fix: sysroot property #16011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ def __init__(self, conanfile, backend=None, native=False):
default_comp = "cl"
default_comp_cpp = "cl"

# Read configuration for sys_root property (honoring existing conf)
self._sys_root = self._conanfile_conf.get("tools.build:sysroot", check_type=str)
if self._sys_root:
self.properties["sys_root"] = self._sys_root

# Read configuration for compilers
compilers_by_conf = self._conanfile_conf.get("tools.build:compiler_executables", default={},
check_type=dict)
Expand Down Expand Up @@ -404,10 +409,11 @@ def _get_extra_flags(self):
linker_scripts = self._conanfile_conf.get("tools.build:linker_scripts", default=[], check_type=list)
linker_script_flags = ['-T"' + linker_script + '"' for linker_script in linker_scripts]
defines = [f"-D{d}" for d in self._conanfile.conf.get("tools.build:defines", default=[], check_type=list)]
sys_root = [f"--sysroot={self._sys_root}"] if self._sys_root else [""]
return {
"cxxflags": cxxflags,
"cflags": cflags,
"ldflags": sharedlinkflags + exelinkflags + linker_script_flags,
"cxxflags": cxxflags + sys_root,
"cflags": cflags + sys_root,
"ldflags": sharedlinkflags + exelinkflags + linker_script_flags + sys_root,
"defines": defines
}

Expand Down
4 changes: 2 additions & 2 deletions test/functional/toolchains/meson/test_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import pytest

from conans.model.recipe_ref import RecipeReference
from conan.test.assets.sources import gen_function_cpp, gen_function_h
from test.functional.toolchains.meson._base import TestMesonBase
from conan.test.utils.tools import TestClient
from conans.model.recipe_ref import RecipeReference
from test.functional.toolchains.meson._base import TestMesonBase


class MesonToolchainTest(TestMesonBase):
Expand Down
51 changes: 50 additions & 1 deletion test/integration/toolchains/meson/test_mesontoolchain.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import platform
import re
import textwrap

import pytest

from conan.test.assets.genconanfile import GenConanfile
from conan.test.utils.tools import TestClient
from conan.tools.files import load
from conan.tools.meson import MesonToolchain
from conan.test.utils.tools import TestClient


def test_apple_meson_keep_user_custom_flags():
Expand Down Expand Up @@ -534,3 +535,51 @@ def test_compiler_path_with_spaces():
conan_meson_native = client.load("conan_meson_native.ini")
assert "c = 'c compiler path with spaces'" in conan_meson_native
assert "cpp = 'cpp compiler path with spaces'" in conan_meson_native


def test_meson_sysroot_app():
"""Testing when users pass tools.build:sysroot on the profile with Meson

The generated conan_meson_cross.ini needs to contain both sys_root property to fill the
PKG_CONFIG_PATH and the compiler flags with --sysroot.

When cross-building, Meson needs both compiler_executables in the config, otherwise it will fail
when running setup.
"""
sysroot = "/my/new/sysroot/path"
client = TestClient()
profile = textwrap.dedent(f"""
[settings]
os = Macos
arch = armv8
compiler = apple-clang
compiler.version = 13.0
compiler.libcxx = libc++

[conf]
tools.build:sysroot={sysroot}
tools.build:verbosity=verbose
tools.compilation:verbosity=verbose
tools.apple:sdk_path=/my/sdk/path
""")
profile_build = textwrap.dedent(f"""
[settings]
os = Macos
arch = x86_64
compiler = apple-clang
compiler.version = 13.0
compiler.libcxx = libc++
""")
client.save({"conanfile.py": GenConanfile(name="hello", version="0.1")
.with_settings("os", "arch", "compiler", "build_type")
.with_generator("MesonToolchain"),
"build": profile_build,
"host": profile})
client.run("install . -pr:h host -pr:b build")
# Check the meson configuration file
conan_meson = client.load(os.path.join(client.current_folder, "conan_meson_cross.ini"))
assert f"sys_root = '{sysroot}'\n" in conan_meson
assert re.search(r"c_args =.+--sysroot={}.+".format(sysroot), conan_meson)
assert re.search(r"c_link_args =.+--sysroot={}.+".format(sysroot), conan_meson)
assert re.search(r"cpp_args =.+--sysroot={}.+".format(sysroot), conan_meson)
assert re.search(r"cpp_link_args =.+--sysroot={}.+".format(sysroot), conan_meson)