When trying to cross-compile mesa on an aarch64 system, I noticed some strange behavior. Meson would only ever find the wayland-scanner binary in my host machine's sysroot (/mnt/amethyst): Native dependency wayland-scanner found: YES 1.16.0 Program /mnt/amethyst/usr/bin/wayland-scanner found: YES (/mnt/amethyst/usr/bin/wayland-scanner) It should be finding /usr/bin/wayland-scanner instead, since the wayland-scanner dependency is created as native. On closer inspection, it turned out that meson was ignoring the native argument passed to dependency(), and wuld always use the pkgconfig binary specified in my toolchain instead of the native one (/usr/bin/pkg-config): Native dependency wayland-scanner found: YES 1.16.0 Called `/home/lyudess/Projects/panfrost/scripts/amethyst-pkg-config --variable=wayland_scanner wayland-scanner` -> 0 Turns out that if we create a dependency() object with native:false, we end up caching the pkg-config path for the host machine in PkgConfigDependency.class_pkgbin, instead of the build machine's pkg-config path. This results causing in all pkg-config invocations for dependency() objects to use the host machine's pkg-config binary, regardless of whether or not 'native: true' was specified when the dependency() object was instantiated. So, fix this by never setting PkgConfigDependency.class_pkgbin for cross dependency() objects. Also, add some test cases for this. Since triggering this bug can be avoided by creating a dependency() objects with native:true before creating any with native:false, we make sure that our test has two modes: one where it starts with a native dependency first, and another where it starts with a cross dependency first. As a final note here: We currently skip this test on windows, because windows doesn't support directly executing python scripts as executables: something that we need in order to point pkgconfig to a wrapper script that sets the PKG_CONFIG_LIBDIR env appropriately before calling pkg-config. Signed-off-by: Lyude Paul <thatslyude@gmail.com>pull/4482/head
parent
d178fd0ab3
commit
11e3011a6b
7 changed files with 69 additions and 1 deletions
@ -0,0 +1,12 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import os |
||||
import sys |
||||
import subprocess |
||||
|
||||
environ = os.environ.copy() |
||||
environ['PKG_CONFIG_LIBDIR'] = os.path.join( |
||||
os.path.dirname(os.path.realpath(__file__)), 'cross_pkgconfig') |
||||
|
||||
sys.exit( |
||||
subprocess.run(['pkg-config'] + sys.argv[1:], env=environ).returncode) |
@ -0,0 +1,5 @@ |
||||
dep_type=cross |
||||
|
||||
Name: dependency() test |
||||
Description: dependency() test |
||||
Version: 0 |
@ -0,0 +1,15 @@ |
||||
project('native dep pkgconfig test') |
||||
|
||||
if get_option('start_native') |
||||
dep_native = dependency('dep_tester', native: true, method: 'pkg-config') |
||||
dep_cross = dependency('dep_tester', native: false, method: 'pkg-config') |
||||
else |
||||
dep_cross = dependency('dep_tester', native: false, method: 'pkg-config') |
||||
dep_native = dependency('dep_tester', native: true, method: 'pkg-config') |
||||
endif |
||||
|
||||
dep_type = dep_native.get_pkgconfig_variable('dep_type') |
||||
assert(dep_type == 'native', 'Expected native') |
||||
|
||||
dep_type = dep_cross.get_pkgconfig_variable('dep_type') |
||||
assert(dep_type == 'cross', 'Expected cross') |
@ -0,0 +1,6 @@ |
||||
option( |
||||
'start_native', |
||||
type : 'boolean', |
||||
value : 'false', |
||||
description : 'Start by creating a dependency() with native : true', |
||||
) |
@ -0,0 +1,5 @@ |
||||
dep_type=native |
||||
|
||||
Name: dependency() test |
||||
Description: dependency() test |
||||
Version: 0 |
Loading…
Reference in new issue