-
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
Fix niche cases when linking static libs #11742
Conversation
Case1 is a pure-C equivalent to this Rust issue: #11723. |
Does this also solve the the Rust issue if putting the dependencies explicitly into |
@sdroege I'm undecided what to do with Rust yet. As usual, the more I dig the more I realize the problem is bigger than I thought. For example s1 -> s2 -> r1 -> prog where s1 and s2 are C static lib and r1 is Rust staticlib, the final link of prog fails because it miss symbol from s1. What happens is rustc bundles s2 in r1 but not s1, because ninja backend in generate_rust_target() does not pass all deps to rustc. using link_whole was a bad idea, which should forbid link_whole of rust targets completely because Meson implement that by passing object files which we don't have access to with rustc. I leaning toward fixing this in ninja backend, generate_rust_target() does not use target.get_dependencies() correctly maybe... More thinking is needed :P |
Failing CI here is another problematic edge case, the unit test does:
That cannot be supported currently, clib is installed so to be usable it needs to bundle stuff. Meson does that by adding all object files from stuff into clib archive but we can't do that with rustc because we don't have access to individual .o files, only the final .a archive. Before this PR prog was incorrectly linking to stuff which should not be needed because clib is supposed to bundle it. This PR fix that, but since clib does not actually bundle stuff it now fail to link prog. But the thing is, that situation has always been broken because the installed clib does not bundle stuff which is not installed, that means installed clib was not usable which we never tested. |
That failing case should use |
One trick we might do is consider rust staticlib just like an external static library (which we cannot link_whole atm) and add code in Meson to extract archives like I did a while ago: #9218 |
In theory it should get promoted to link_whole implicitely, but Meson is not doing that because it knows it's broken: https://github.com/mesonbuild/meson/blob/master/mesonbuild/build.py#L1391. I think that should be turned into an hard error for now, it is not supported use-case. |
Installed static library: i If The auto-promotion is not the problem here, we can and should auto-promote rust libraries too. The problem is the unpacking. EDIT:
Right, I remember that. |
a2cb4d6
to
c7b12c2
Compare
I added a PR that does the promotion, but abort later when it tries to extract object files. That has those advantages:
|
c457a5f
to
2cb836f
Compare
2cb836f
to
f63cad5
Compare
It would be nice to reapply the original commits if we can get it to work... Is there part of this PR that doesn't depend on that and which we can merge independently? |
I think I have a proper fix, extract_all_objects() should include the object file for MSVC PCH. Unfortunately I lost access to my Windows machine (VPN seems down) so let's see if CI likes it. |
1f12503
to
e712910
Compare
Case 1: - Prog links to static lib A - A link_whole to static lib B - B link to static lib C - Prog dependencies should be A and C but not B which is already included in A. Case 2: - Same as case 1, but with A being installed. - To be useful, A must also include all objects from C that is not installed. - Prog only need to link on A.
It seems to only be used by the Rust module now, and it already does a copy.
To take good decisions we'll need to know if we are a Rust library which is only know after processing source files and compilers. Note that is it not the final list of compilers, some can be added in process_compilers_late(), but those are compilers for which we don't have source files any way.
Rustc can do it without needing Meson to extract all objects.
This changes the object file name with ninja backend to match the name used by vs backend and add it in outputs of the ninja rule.
Got CI to pass now. |
@eli-schwartz any objection? |
Anyone still have issues? |
This is a regression test for: mesonbuild#11165. The test was initially merged as part of: mesonbuild#10628, but had to be reverted. A second attempt at fixing the root cause also had to be reverted: mesonbuild#10699. A 3rd attempt got merged but missed this unit test: mesonbuild#11742. Co-authored-by: Dylan Baker <[email protected]>
Case 1:
Case 2: