Subprojects can only be built for the host machine
Discussed in https://github.com/mesonbuild/meson/discussions/11120
Originally posted by LunarLambda November 30, 2022
Project A can be cross-compiled (it's a library for command-line parsing), so does not specify native: true.
Project B must be cross-compiled (single-platform embedded project), but wants to use Project A as a subproject dependency for native: true executables.
Is there any way for Project B to tell meson it should build Project A using the native compiler?
Or would Project A need to expose a custom build option (i.e. -Dnative=true), or would it need to expose two dependencies (one cross, one native)
Something like subproject(..., native: true) would be nice, however I can see this clashing with the rule of "every subproject is executed only once", as well as fallback subprojects used with wraps.
It would be nice to maybe use this time to come up with something much easier to understand than native: true | false (deprecation). For instance, subproject(..., native: true) would look a whole lot better as subproject(..., machines: [host_machine, build_machine]).
Every time I deal with native: true | false I have to go consult the docs.
But maybe now is not the time since I know @dcbaker has had some qualms about the way machines are currently done given what systemd has to deal with.
It is definitely not going to yield an array of subprojects.
Good point.
Maybe subproject(..., machine: build_machine)
I had thought about having machines : ['build', 'host'] as an option, but in that case I thought the better solution is to return a special type that can act as either a host or a build as appropriate, kinda like both_libraries, as that would make it 100% backwards compatible
or possibly machine: Literal['host', 'build', 'both'] = 'host'
Are you using 'build' and 'host' so someone doesn't supply target_machine?
among other things, yes. but also 'both' is more ergonomic than [host_machine, build_machine]
Your proposal seems reasonable.