-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add rustc --emit=link-info for staticlib link-line output #31471
Comments
This seems reasonable to me, although I might prefer to call it something like I think we could even suppress the "warning, you gotta link these libs" message when you're emitting these as well. We may even be able to get crazy and put other flags in there (e.g. things like |
Generate an unix-style ldflags line when building with --crate-type staticlib --emit link-flags-ld. If a filename is given, write the link line there for later use by an external build system in linking the static library. If none is given, just modify the normal informative message to print the flags line instead of the library list. Issue rust-lang#31471.
Generate an unix-style ldflags line when building with --crate-type staticlib --emit link-flags-ld. If a filename is given, write the link line there for later use by an external build system in linking the static library. If none is given, just modify the normal informative message to print the flags line instead of the library list. Issue rust-lang#31471.
While there might not be a standard for most compilers, msvc definitely does have a way for libraries to specify dependencies that are pulled in automatically. |
Oh! That would be great. Can you share some documentation about how this works? As far as I knew msvc |
I can't find any documentation on it at the moment, just some other documentation that alludes to it. https://msdn.microsoft.com/en-us/library/f1tbxcxh.aspx
https://msdn.microsoft.com/en-us/library/229a6ysd.aspx
So the capability is there in object files, I just have no idea how to add that information to the object file. |
Thanks for the links. I still don't see a way to make this work though. I think the |
Really it's just a matter of seeing whether LLVM can do it, since LLVM is what creates our object files, and is also what creates static libraries for us (Rust doesn't use |
As noted in #33173 just writing the libraries note to stdout instead of stderr would help a lot. Heck, create a .libs-needed file and write to that. Better yet, can someone finish @rillian's #31875, or can we just merge it and add the lack of tests and docs as a separate issue? I feel like waiting for better tests and docs would be nice, but this is kind of an obnoxious situation and it looks like @rillian has dropped out of trying to get a fix in. I'm currently working around this in my Makefile (because reasons) with
where the |
Yeah, I haven't been able to work more on this. Would be very happy to have someone finish it up! |
Ah, I figured out how to do the default lib stuff in LLVM, based on what clang does. This method lets you pass arbitrary arguments to the linker without having to explicitly pass them to the linker. !0 = !{i32 6, !"Linker Options", !1}
!1 = !{!2, !3, !4, !5, !6, !7, !8}
!2 = !{!"/DEFAULTLIB:libcmt.lib"}
!3 = !{!"/DEFAULTLIB:oldnames.lib"}
!4 = !{!"/FAILIFMISMATCH:\22_MSC_VER=1900\22"}
!5 = !{!"/FAILIFMISMATCH:\22_ITERATOR_DEBUG_LEVEL=0\22"}
!6 = !{!"/FAILIFMISMATCH:\22RuntimeLibrary=MT_StaticRelease\22"}
!7 = !{!"/DEFAULTLIB:libcpmt.lib"}
!8 = !{!"/FAILIFMISMATCH:\22_CRT_STDIO_ISO_WIDE_SPECIFIERS=0\22"} |
When linking rust into C++ projects, I use
rustc --crate-type=staticlib
to generate a static library which I can link into the overall project. Since there's no standard for transitive dependency declaration in the C ABI for static libraries, rustc prints out a list of libraries which need to be linked along with the staticlib. (#25820 (comment))This is very helpful in development, but not ideal for automation. I propose adding an
--emit=link-info
option (--emit=libs
?--emit=ldflags
?) to write the required link line out to a file for use later, similar to--emit=dep-info
for makefile dependency generation.Order of evaluation is a little trickier than with dep-info since it has to work the first time, but this should simplify funky stderr hacks like
into
The text was updated successfully, but these errors were encountered: