Skip to content

Always add libdirs to rustc command #14799

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

Merged
merged 1 commit into from
Jul 19, 2025

Conversation

leftmostcat
Copy link
Contributor

This works around an issue in which meson provides absolute paths to rustc, but rustc may do its own dependency resolution and add -l flags for the same libs, causing a failure to link. See #14622.

@leftmostcat leftmostcat requested a review from jpakkane as a code owner July 13, 2025 16:58
@bonzini
Copy link
Collaborator

bonzini commented Jul 14, 2025

The idea seems acceptable, but I don't understand the if. Do you need to run the new code even if not a.endswith(('.dll', '.so', '.dylib', '.a', '.lib'))?

In other words, should this be

                if a in rustc.native_static_libs:
                    # Exclude link args that rustc already add by default
                    continue
                if a.startswith('-L'):
                    args.append(a)
                    continue
                if a.endswith(('.dll', '.so', '.dylib', '.a', '.lib')):
                    # Work around a disconnect in meson and rustc behavior in
                    # which rustc performs some dependency resolution of its own
                    # and adds `-l:our_lib` despite having an absolute path to
                    # `our_lib.a`. Always add the -L option.
                    dir_, lib = os.path.split(a)
                    linkdirs.add(dir_)
                    if isinstance(target, build.StaticLibrary):
                        if not verbatim:
                            lib, ext = os.path.splitext(lib)
                            if lib.startswith('lib'):
                                lib = lib[3:]
                        static = a.endswith(('.a', '.lib'))
                        _link_library(lib, static)
                        continue
                args.append(f'-Clink-arg={a}')

or something like that

@leftmostcat leftmostcat force-pushed the rustc-libdir branch 2 times, most recently from 3421a6d to 982988b Compare July 16, 2025 19:33
@leftmostcat
Copy link
Contributor Author

I've adjusted this based on the review. I've removed the comment for now as I don't really understand why these were separated previously and what's happening with static libs, so I don't want comments that make no sense for the existing context. I can add something back if there's a need.

@bonzini
Copy link
Collaborator

bonzini commented Jul 16, 2025

@leftmostcat
Copy link
Contributor Author

Forgot to stage. 🤦

@bonzini bonzini added this to the 1.9 milestone Jul 19, 2025
@bonzini
Copy link
Collaborator

bonzini commented Jul 19, 2025

LGTM. Please add "Fixes: #14622" to the description, so that issue and pull request are linked.

This works around an issue in which meson provides absolute paths to
rustc, but rustc pulls metadata from an external rlib and adds link args
without adding library paths.

Fixes: mesonbuild#14622
@dcbaker dcbaker merged commit bf86466 into mesonbuild:master Jul 19, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants