Repository: conan-io/conan-center-index

Issue:
[package] wayland/1.22.0: conanfile uses wrong test for cross building.
### Description

the conanfile is using `cross_building()` when it really means `not can_run()` resulting in the build environment not being used to pull in wayland-scanner when cross compiling between incompatible ABIs on the same os/arch tuple.  This then results in meson using the system installed wayland-scanner (if present) rather than the one that should be build_required.

(note: there is a related bug in conan's meson toolchain generator which I'll be submitting a PR for shortly).

### Package and Environment Details

* Package Name/Version: **wayland/1.22.0**
* Operating System+version: **Linux Ubuntu 22.04** / **Yocto**
* Compiler+version: **GCC 11**
* Conan version: **conan 2.x** (develop2 branch head + bugfixes for meson cross compile bug conan-io/conan#15392 )
* Python version: **Python 3.10**


### Conan profile

please see description as this involves behavior in forced cross compile scenarios.

### Steps to reproduce

1. set up a profile with 
```
[conf]
tools.build.cross_building:can_run=false
```
2. attempt to build the package.

### Logs

```
-------- Installing package wayland/1.22.0 (31 of 35) --------
wayland/1.22.0: Building from source
wayland/1.22.0: Package wayland/1.22.0:db57ab7809fab3515e28598fd861124ccd5fedb2
wayland/1.22.0: Copying sources to build folder
wayland/1.22.0: Building your package in /home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b
wayland/1.22.0: Calling generate()
wayland/1.22.0: Generators folder: /home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo/conan
WARN: deprecated: Please, do not use a Conan option value directly. Convert 'options.enable_libraries' into a valid Pythondata type, e.g, bool(self.options.shared)
WARN: deprecated: Please, do not use a Conan option value directly. Convert 'options.enable_dtd_validation' into a valid Pythondata type, e.g, bool(self.options.shared)
wayland/1.22.0: Generating aggregated env files
wayland/1.22.0: Generated aggregated env files: ['conanbuild.sh']
wayland/1.22.0: Calling build()
wayland/1.22.0: Meson configure cmd: meson setup --cross-file "/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo/conan/conan_meson_cross.ini" "/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo" "/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/src" -Dprefix="/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/p"
wayland/1.22.0: RUN: meson setup --cross-file "/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo/conan/conan_meson_cross.ini" "/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo" "/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/src" -Dprefix="/home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/p"
The Meson build system
Version: 1.3.0
Source dir: /home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/src
Build dir: /home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo
Build type: cross build
Project name: wayland
Project version: 1.22.0
C compiler for the host machine: /usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/x86_64-oe-linux/x86_64-oe-linux-gcc (gcc 11.4.0 "x86_64-oe-linux-gcc (GCC) 11.4.0")
C linker for the host machine: /usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/x86_64-oe-linux/x86_64-oe-linux-gcc ld.bfd 2.38.20220708
C compiler for the build machine: cc (gcc 11.4.0 "cc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0")
C linker for the build machine: cc ld.bfd 2.38
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: x86_64
Host machine cpu: x86_64
Target machine cpu family: x86_64
Target machine cpu: x86_64
Compiler for C supports arguments -Wno-unused-parameter: YES 
Compiler for C supports arguments -Wstrict-prototypes: YES 
Compiler for C supports arguments -Wmissing-prototypes: YES 
Compiler for C supports arguments -fvisibility=hidden: YES 
Has header "sys/prctl.h" : YES 
Has header "sys/procctl.h" : NO 
Has header "sys/ucred.h" : NO 
Checking for function "accept4" : YES 
Checking for function "mkostemp" : YES 
Checking for function "posix_fallocate" : YES 
Checking for function "prctl" : YES 
Checking for function "memfd_create" : YES 
Checking for function "mremap" : YES 
Checking for function "strndup" : YES 
Checking whether type "struct xucred" has member "cr_pid" : NO 
Found pkg-config: YES (/home/kuroneko/.conan2/p/b/pkgcoa37456fc6f63c/p/bin/pkgconf) 2.1.0
Run-time dependency libffi found: YES 3.4.4
Header "sys/signalfd.h" has symbol "SFD_CLOEXEC" : YES 
Header "sys/timerfd.h" has symbol "TFD_CLOEXEC" : YES 
Header "time.h" has symbol "CLOCK_MONOTONIC" : YES 
Checking for function "clock_gettime" : NO 
Library rt found: YES
Checking for function "clock_gettime" with dependency -lrt: YES 
Configuring config.h using configuration
Configuring wayland-version.h using configuration
Run-time dependency expat found: YES 2.5.0
Run-time dependency libxml-2.0 found: YES 2.12.3
Program embed.py found: YES (/usr/bin/python3 /home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/src/src/embed.py)
Found pkg-config: YES (/usr/bin/pkg-config) 0.29.2
Dependency wayland-scanner found: NO found 1.20.0 but need: '1.22.0'
Found CMake: /home/kuroneko/local/bin/cmake (3.28.0)
Build-time dependency wayland-scanner found: NO (tried cmake)

../src/src/meson.build:81:15: ERROR: Dependency lookup for wayland-scanner with method 'pkgconfig' failed: Invalid version, need 'wayland-scanner' ['1.22.0'] found '1.20.0'.

A full log can be found at /home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo/meson-logs/meson-log.txt

wayland/1.22.0: ERROR: 
Package 'db57ab7809fab3515e28598fd861124ccd5fedb2' build failed
wayland/1.22.0: WARN: Build folder /home/kuroneko/.conan2/p/b/wayla49dd4c78a669d/b/build-relwithdebinfo
ERROR: wayland/1.22.0: Error in build() method, line 103
	meson.configure()
	ConanException: Error 1 while executing
```


Discussion:

Resolving patch:
diff --git a/recipes/wayland/all/conanfile.py b/recipes/wayland/all/conanfile.py
--- a/recipes/wayland/all/conanfile.py
+++ b/recipes/wayland/all/conanfile.py
@@ -1,6 +1,6 @@
 from conan import ConanFile
 from conan.errors import ConanInvalidConfiguration
-from conan.tools.build import cross_building
+from conan.tools.build import can_run
 from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
 from conan.tools.files import copy, get, replace_in_file, rmdir
 from conan.tools.gnu import PkgConfigDeps
@@ -61,7 +61,7 @@ def build_requirements(self):
         self.tool_requires("meson/1.3.0")
         if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
             self.tool_requires("pkgconf/2.1.0")
-        if cross_building(self):
+        if not can_run(self):
             self.tool_requires(str(self.ref))
 
     def source(self):
@@ -70,12 +70,12 @@ def source(self):
     def generate(self):
         env = VirtualBuildEnv(self)
         env.generate()
-        if not cross_building(self):
+        if can_run(self):
             env = VirtualRunEnv(self)
             env.generate(scope="build")
 
         pkg_config_deps = PkgConfigDeps(self)
-        if cross_building(self):
+        if not can_run(self):
             pkg_config_deps.build_context_activated = ["wayland"]
         elif self.dependencies["expat"].is_build_context:  # wayland is being built as build_require
             # If wayland is the build_require, all its dependencies are treated as build_requires
@@ -87,7 +87,7 @@ def generate(self):
         tc.project_options["libraries"] = self.options.enable_libraries
         tc.project_options["dtd_validation"] = self.options.enable_dtd_validation
         tc.project_options["documentation"] = False
-        if cross_building(self):
+        if not can_run(self):
             tc.project_options["build.pkg_config_path"] = self.generators_folder
         if Version(self.version) >= "1.18.91":
             tc.project_options["scanner"] = True


Test patch: