Open lu-zero opened 7 years ago
rustc
has a -Z print-link-args
flag. Would that work for your use case?
$ cargo new --bin hello && cd $_
$ cargo rustc -- -Z print-link-args
Compiling hello v0.1.0 (file:///home/japaric/tmp/hello)
"cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/japaric/tmp/hello/target/debug/deps/hello-d4ae70c69d5b5ea8.0.o" "-o" "/home/japaric/tmp/hello/target/debug/deps/hello-d4ae70c69d5b5ea8" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/japaric/tmp/hello/target/debug/deps" "-L" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-b4054fae3db32020.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-1c6ed188684e7d33.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-63f7707126c5a809.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_unicode-a9711770523833d4.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-d2ecc8049920bea8.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-5837d7d3490e00c5.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-0720511b45a7223a.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc_jemalloc-477554c8f244cbba.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-ab203041f1ec5313.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-93f19628b61beb76.rlib" "/home/japaric/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-35d2bc471c7ce467.rlib" "-l" "dl" "-l" "rt" "-l" "pthread" "-l" "gcc_s" "-l" "pthread" "-l" "c" "-l" "m" "-l" "rt" "-l" "util"
Finished debug [unoptimized + debuginfo] target(s) in 0.42 secs
@japaric pointed me to here as well.
(did I? 😅)
Yes, you did :).
I just need to keep -L
and -l
so in theory I should be able to extract it from that but is sort of cumbersome (and I'm sure that there are cases in which you need something smarter than that)
@lu-zero did it work out for you in the end? if so, please close this :)
There are few spurious flags (e.g. -m64
) so it is far from ideal. (and interacts in strange ways with --lib
).
Another use-case for this is to get the link line to generate pkg-conf
files.
I'd like to integrate better some rust component in a larger project (namely VLC).
I have already an horrible kludge sort of working, but one of the quite annoying issues for this use case and other is the inability to pass to the larger build system the linker flags.
A smaller use-case:
I read that getting rustc to play along with other build systems is in the roadmap for 2017 and @japaric pointed me to here as well.