Open calixteman opened 4 years ago
I'm not sure what the issue is... You're 100% right about the issue, but the build script is passing rustc-link-lib=static=tcmalloc
and rustc-link-search=native=$dir
correctly.
My build log:
Running `CARGO_PKG_DESCRIPTION='Drop-in global allocator using tcmalloc' OUT_DIR=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/build/tcmalloc-sys-bd2bceea39d44987/out CARGO_MANIFEST_DIR=/home/jmcomets/Bundle/tcmalloc-rs/tcmalloc-sys CARGO_PKG_VERSION_PRE= CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_MAJOR=0 LD_LIBRARY_PATH='/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps:/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib:/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION=0.3.0 CARGO_PKG_HOMEPAGE= CARGO_PKG_REPOSITORY='https://github.com/jmcomets/tcmalloc-rs' CARGO=/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_PKG_AUTHORS='Jean-Marie Comets <jean.marie.comets@gmail.com>' CARGO_PKG_NAME=tcmalloc-sys /home/jmcomets/.cargo/bin/sccache rustc --crate-name tcmalloc_sys --edition=2018 /home/jmcomets/Bundle/tcmalloc-rs/tcmalloc-sys/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 -C metadata=1b9b4356add8d905 -C extra-filename=-1b9b4356add8d905 --out-dir /home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps -C incremental=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/incremental -L dependency=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps -L native=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/build/tcmalloc-sys-bd2bceea39d44987/out/build/.libs -l static=tcmalloc`
Compiling tcmalloc v0.3.0 (/home/jmcomets/Bundle/tcmalloc-rs)
Running `CARGO_PKG_DESCRIPTION='Drop-in global allocator using tcmalloc' CARGO_MANIFEST_DIR=/home/jmcomets/Bundle/tcmalloc-rs CARGO_PKG_VERSION_PRE= CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_MAJOR=0 LD_LIBRARY_PATH='/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps:/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib:/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' CARGO_PKG_VERSION_MINOR=3 CARGO_PKG_VERSION=0.3.0 CARGO_PKG_HOMEPAGE= CARGO_PKG_REPOSITORY='https://github.com/jmcomets/tcmalloc-rs' CARGO=/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_PKG_AUTHORS='Jean-Marie Comets <jean.marie.comets@gmail.com>' CARGO_PKG_NAME=tcmalloc /home/jmcomets/.cargo/bin/sccache rustc --crate-name tcmalloc --edition=2018 /home/jmcomets/Bundle/tcmalloc-rs/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C debuginfo=2 --cfg 'feature="bundled"' --cfg 'feature="default"' --cfg 'feature="tcmalloc-sys"' -C metadata=08cebbd5eeaed400 -C extra-filename=-08cebbd5eeaed400 --out-dir /home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps -C incremental=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/incremental -L dependency=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps --extern tcmalloc_sys=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps/libtcmalloc_sys-1b9b4356add8d905.rmeta -L native=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/build/tcmalloc-sys-bd2bceea39d44987/out/build/.libs`
Compiling tcmalloc-example v0.1.0 (/home/jmcomets/Bundle/tcmalloc-rs/examples)
Running `CARGO_PKG_DESCRIPTION= CARGO_MANIFEST_DIR=/home/jmcomets/Bundle/tcmalloc-rs/examples CARGO_PKG_VERSION_PRE= CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_MAJOR=0 LD_LIBRARY_PATH='/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps:/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib:/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib' CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION=0.1.0 CARGO_PKG_HOMEPAGE= CARGO_PKG_REPOSITORY= CARGO=/home/jmcomets/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo CARGO_PKG_AUTHORS='Jean-Marie Comets <jean.marie.comets@gmail.com>' CARGO_PKG_NAME=tcmalloc-example /home/jmcomets/.cargo/bin/sccache rustc --crate-name tcmalloc_example src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg 'feature="bundled"' --cfg 'feature="default"' -C metadata=0896e3eafc81bdd2 -C extra-filename=-0896e3eafc81bdd2 --out-dir /home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps -C incremental=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/incremental -L dependency=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps --extern tcmalloc=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/deps/libtcmalloc-08cebbd5eeaed400.rlib -L native=/home/jmcomets/Bundle/tcmalloc-rs/examples/target/debug/build/tcmalloc-sys-bd2bceea39d44987/out/build/.libs`
Finished dev [unoptimized + debuginfo] target(s) in 46.32s
TL;DR the options -l static=tcmalloc
and -L native=$dir
are passed in correctly. Maybe this is a Cargo issue? :thinking:
It seems to me this line would result in a DSO requirement appears in the final binary even in bundled feature. (https://github.com/jmcomets/tcmalloc-rs/blob/master/src/lib.rs#L5)
#[link(name = "tcmalloc")]
Only adding kind="static"
doesn't work, maybe its because it requires the cargo:rustc-link*
stuffs present in parent crate's build.rs?
I tried to move the extern C
part to tcmalloc-sys
(and delete the link directive), then import tcmalloc_sys
in parent crate's src/lib.rs
and it kinda works, however I need to also add link-arg related to libstdc++ and libunwind to make it compiles.
A way to reproduce:
and then
ldd target/debug/tcmalloc-example
:and then
readelf -s target/debug/tcmalloc-example | rg 'UND' | rg 'tc_'
: