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

Open
wants to merge 5 commits into
base: develop2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions conan/tools/meson/toolchain.py
Expand Up @@ -396,6 +396,14 @@ def _sanitize_format(v):
# These link_args have already the LDFLAGS env value so let's add only the new possible ones
self.objc_link_args.extend(apple_flags + extra_flags["ldflags"])
self.objcpp_link_args.extend(apple_flags + extra_flags["ldflags"])
# Meson properties
sys_root = self._conanfile.conf.get("tools.build:sysroot", check_type=str)
if sys_root:
self.properties["sys_root"] = sys_root
self.c_args.append("--sysroot=" + sys_root)
self.cpp_args.append("--sysroot=" + sys_root)
self.c_link_args.append("--sysroot=" + sys_root)
self.cpp_link_args.append("--sysroot=" + sys_root)
Comment on lines +448 to +452
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If sys_root is a property, does it still need to be added as a flag? Wouldn't Meson take care of that automatically?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks weird. I'm going to figure out how Meson manages this attribute because I think that it should automatically inject that one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed: https://mesonbuild.com/Cross-compilation.html#properties

Since 0.52.0 The sys_root property may point to the root of the host system path (the system that will run the compiled binaries). This is used internally by Meson to set the PKG_CONFIG_SYSROOT_DIR environment variable for pkg-config. If this is unset the host system is assumed to share a root with the build system.

The sys_root property only configures the PKG_CONFIG_SYSROOT_DIR, nothing more.

But how Meson users manage --sysroot then?

They pass to c_flags and cxx_flags:


On the other hand, Conan users could have it defined in tools.build:cflags and so on.


if self.libcxx:
self.cpp_args.append(self.libcxx)
Expand Down
61 changes: 61 additions & 0 deletions conans/test/functional/toolchains/meson/test_meson.py
Expand Up @@ -309,3 +309,64 @@ def build(self):
client.run("build .")
assert "unrecognized character escape sequence" not in str(client.out) # if Visual
assert "unknown escape sequence" not in str(client.out) # if mingw


@pytest.mark.tool("meson")
@pytest.mark.skipif(sys.version_info.minor < 8, reason="Latest Meson versions needs Python >= 3.8")
@pytest.mark.skipif(platform.system() != "Darwin", reason="Requires apple-clang")
def test_meson_sysroot_flag():
"""
Testing when users pass tools.build:sysroot on the profile
"""
profile = textwrap.dedent("""
[settings]
os = Macos
os.version=10.11
arch = armv7
compiler = apple-clang
compiler.version = 12.0
compiler.libcxx = libc++

[conf]
tools.build:sysroot = /my/new/sysroot/path
""")
myfilename = textwrap.dedent("""
[project options]
my_option = 'fake-option'
""")
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.meson import Meson
class Pkg(ConanFile):
name = "test_name"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
generators = "MesonToolchain"
exports_sources = "meson.build", "src/*"
def build(self):
meson = Meson(self)
meson.configure()
meson.build()
def layout(self):
self.folders.build = "./test-build"
""")
client = TestClient()
client.save({"conanfile.py": conanfile,
"build/myfilename.ini": myfilename,
"meson.build": "project('tutorial', 'cpp')", # dummy one
"profile": profile})

client.run("install . -pr=profile")
client.run("build . -pr=profile", assert_error=False)

# Check the meson configuration file
conan_meson = client.load("conan_meson_cross.ini")
assert re.search(r"sys_root = '/my/new/sysroot/path'", conan_meson)
assert re.search(r"c_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"c_link_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"cpp_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"cpp_link_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is adding this to the file then?


# Check the meson-log.txt
conan_log = client.load("./test-build/meson-logs/meson-log.txt")
assert r"--sysroot=/my/new/sysroot/path" in conan_log