meson
meson copied to clipboard
Meson subproject native fallbacks
Describe the bug
Meson supports specifying native: true in a dependency() w/ subproject fallback, however that subproject is configured in the cross environment with no way to detect that a native build was requested. This means that fallbacks cannot be correctly used for subproject dependencies in the native part of a cross-build.
Additionally the meson object provides no way to ask if the parent project requested a native build so there's no way to work around this within the subproject (though I consider this a symptom of the problem and not itself a problem).
To Reproduce
meson.build:
project('proj', 'cpp')
if not meson.is_cross_build()
error('Must be built using a cross-file')
endif
subproj = dependency('subproj', native: true, fallback: ['subproj', 'subproj_dep'])
executable('proj', 'test.cxx', dependencies: [subproj], native: true)
test.cxx:
int main(int, char **) { return 0; }
subprojects/subproj/meson.build:
project('subproj', 'cpp')
lib = library('subproj', 'test.cxx')
subproj_dep = declare_dependency(link_with: lib)
touch subprojects/subproj/test.cxx
cross-file:
[binaries]
cpp = 'g++'
This results in the nonsensical error
meson.build:6:0: ERROR: Tried to mix libraries for machines 0 and 1 in target 'proj' This is not possible in a cross build.
Expected behavior
Only the native environment gets passed to the subproject so the resulting binaries are for the native platform, and this just works. Additionally I would expect meson.is_cross_build() to return false in the subproject as the dependency calls for a native build, not a cross-build.
system parameters
- Cross build
- Any OS (test case is written for Linux)
- Python 3.9.5
- Meson 0.58.1
- Ninja 1.10.2
I need to fix this for my own use, and I have some work in progress on it.
I did have a look at how this might be done prior to posting the report, but realised it was a lot of work to make subprojects aware of native: and then have the subproject interpreter use only the build machine's toolchain and fix all resulting targets up to have the correct for_machine propety
I'm not adverse to helping with this though
I think that's actually the easy part, we can just initiate the project with host == build. I think the two hardest things are going to be enforcing the subproject type, and dealing with projects that are cross built with build machine targets, ie, a code generator that gets built by both the host and build project