-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Allow subprojects to be built for both the build and host machine #12258
base: master
Are you sure you want to change the base?
Conversation
d94a857
to
74de6bf
Compare
dc5f2ce
to
2b14ab1
Compare
EDIT: my bad, I was on the wrong branch : ) the example actually works I tried setting up a simple cross compilation project that builds a native executable, and builds a dependency for the executable from a subproject. It didn't work: Top-level meson.build: project('myexecutable', 'c')
subproject('mylib')
mylib_dep = dependency('mylib', native: true)
myexecutable = executable('myexecutable', 'main.c', native: true, dependencies: mylib_dep)
test('myexecutable-test', myexecutable) subprojects/mylib/meson.build: project('mylib', 'c')
mylib = static_library('mylib', 'main.c')
mylib_dep = declare_dependency(link_with: mylib)
meson.override_dependency('mylib', mylib_dep) meson log:
Does this mean that 'mylib' should have two targets for the same lib, one with native: true and one with native: false, and therefore two declare_dependency() and meson.override_dependency() calls? |
docs/markdown/snippets/subproject_and_override_program_native.md
Outdated
Show resolved
Hide resolved
@Nomura-RH did I understand correctly that you did get it working? |
Yep. |
Ok, this time I'm pretty sure I've found an error : ) Nothing build-breaking though. Sub-subprojects are reported in the logs as being built for the host machine, even when they are actually being built for the build machine. Here is a slightly more involved version of my previous example to show what I mean: Top-level meson.build: project('myexecutable', 'c')
mylib_dep = dependency('mylib', native: true)
myexecutable = executable('myexecutable', 'main.c', native: true, dependencies: mylib_dep)
test('myexecutable-test', myexecutable) subprojects/mylib/meson.build: project('mylib', 'c')
mysublib_dep = dependency('mysublib')
mylib = static_library('mylib', 'main.c', dependencies: mysublib_dep)
mylib_dep = declare_dependency(link_with: mylib)
meson.override_dependency('mylib', mylib_dep) subprojects/mysublib/meson.build: project('mysublib', 'c')
mysublib = static_library('mysublib', 'main.c')
mysublib_dep = declare_dependency(link_with: mysublib)
meson.override_dependency('mysublib', mysublib_dep) meson log:
The log errors are:
|
2b14ab1
to
95c8865
Compare
@Nomura-RH oh, good catch. Yeah, because the for-build-only subprojects think that host == build they report that they're building for the host machine. Should be fixed in the latest version (with a test!) |
39e6c87
to
f162b3b
Compare
The first error is indeed solved, but the second one is still there (the summary at the end still reports the subsubproject in the list of subprojects for the host machine) |
f162b3b
to
00e90f0
Compare
Yup, I didn't pass the change down a level... Fixed now in both cases |
Almost there :) Now all subprojects get listed for both machines:
EDIT: maybe this is actually my doing, because I added a
|
In the "10 native subproject" I see only the "both" subproject in both, and then "buildtool", "hostp", and "test installs" in the build list. but that calling a subproject from a subproject that was called in the main project is probably worth testing... let me see |
00e90f0
to
a285c82
Compare
I've added more tests for correct machine reporting, and discovered that output rpaths weren't being set correctly in the process, so there's another bug down |
eb7eafb
to
dc7e517
Compare
f121b6a
to
48dbe2a
Compare
Which is required to make test for installed files work correctly
Which de-duplicates a lot of printing material and makes it easier to change things.
forcing the executor to the build machine doesn't actually work correctly once we allow build subprojects.
Which maps subproject name to version
Currently, the assumption is that a subproject will only be built for the host machine. Instead back the storage with PerMachine objects, which fixes this. This goal of this patch is to extend the storage, not enable per-machine subprojects yet. This uncovers some cases where we should be using the SubProject type, but instead are using a string.
The builddir will not mirror the subdir in this case, and we need to track that.
We need this information later to build both a build and a host subproject separately. It's a lot of boilerplate and has been split out to try to simplify review of the difficult pieces
When a subproject is built for both machines, we need to ensure that the outputs don't clash. To do this we'll put the outputs of build only subprojects in a separate root folder (build.subprojects/). We need special methods for this. Currently, this patch changes nothing in the output, but as more boilerplate kind of code it's been split out.
…ild == host config In order to run a build machine only subproject, we create a new Build, Environment, and CoreData object that have look like a host == build configuration, but that are properly merged back into the originals.
The current situation in Meson is that subprojects are always built for the host machine. This means that while cross compiling, a tool that must be run on the build machine must have all of its dependencies met by the system (pkg-config, cmake, config-tool, etc); but dependencies for the host machine can be built. With this patch subprojects may also be built for the build machine. Nothing should ever be installed from a subproject for the build machine, while cross compiling. However, we we are not cross compiling they are installed, since Meson can't really tell the difference between a host and build dependency.
For the most part, what we had before would work correctly for cross building. There is, however a case where this might not work correctly, which is a project for the host machine that builds a build machine target and uses that as an override (think some kind of transpiler), to make this work correctly we need to add a native keyword argument to the `override_find_program` method.
48dbe2a
to
409b0ce
Compare
Currently, subprojects can only be built for the host machine. This is obviously not a great situation, as you may need to build dependencies for the build machine. This series fixes that (hopefully for both cmake and native subprojects), but allowing a subproject to be configured twice.
This is accomplished by creating copies of the core datastructures (Build, Environment, and CoreData), with the per-machine attributes set so that both the host and the build point to the overall build configuration. All install targets from build machine subprojects have been dropped, to avoid such unsupported installation. In addition, I've ensured that in a host == build setup only one subproject will be configured, so that in the case of
that
d_build
is just a reference tod
This also requires tracking a number of things on a per-machine basis that weren't before. Namely program overrides. In general we want to override for the host machine, but in some cases it makes sense to override for the build machine (such as for build only subprojects), so a native keyword has been added. This may be useful in cases where different output is needed for the host and build machine anyway.
I've made an effort to split out boilerplate changes (and there are several of them), to make this easier to review.
I won't be surprised if there's still some bugs in this, I've run it through some cross compilation on my system, but it's a large complicated set of changes.