Skip to content
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

rust: C/C++ targets collect all rlib dependencies of a staticlib as linker flags #11721

Open
sdroege opened this issue Apr 24, 2023 · 2 comments · May be fixed by #11723
Open

rust: C/C++ targets collect all rlib dependencies of a staticlib as linker flags #11721

sdroege opened this issue Apr 24, 2023 · 2 comments · May be fixed by #11723

Comments

@sdroege
Copy link
Contributor

sdroege commented Apr 24, 2023

Project in question: https://github.com/HLTAS/hltas/tree/meson

When building this project with latest meson (plus #11719), the following commands are executed

[1/13] ccache c++ -Icpp/libhltas_cpp.a.p -Icpp -I../cpp -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++14 -O0 -g -fPIC -MD -MQ cpp/libhltas_cpp.a.p/src_hltas.cpp.o -MF cpp/libhltas_cpp.a.p/src_hltas.cpp.o.d -o cpp/libhltas_cpp.a.p/src_hltas.cpp.o -c ../cpp/src/hltas.cpp
[2/13] rm -f cpp/libhltas_cpp.a && gcc-ar csrDT cpp/libhltas_cpp.a cpp/libhltas_cpp.a.p/src_hltas.cpp.o
[3/13] ccache c++ -Icpp/hltas-cpp-tests.p -Icpp -I../cpp -I../cpp/src -I../cpp/catch2 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c++14 -O0 -g -MD -MQ cpp/hltas-cpp-tests.p/src_tests.cpp.o -MF cpp/hltas-cpp-tests.p/src_tests.cpp.o.d -o cpp/hltas-cpp-tests.p/src_tests.cpp.o -c ../cpp/src/tests.cpp
[4/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type rlib --edition=2018 -g -C relocation-model=pic --crate-name cfg_if --emit dep-info=subprojects/cfg-if-1.0.0/cfg_if.d --emit link -o subprojects/cfg-if-1.0.0/libcfg_if.rlib ../subprojects/cfg-if-1.0.0/src/lib.rs
[5/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type rlib --edition=2018 -g -C relocation-model=pic --crate-name minimal_lexical --emit dep-info=subprojects/minimal-lexical-0.2.1/minimal_lexical.d --emit link --cfg 'feature="default"' --cfg 'feature="std"' -o subprojects/minimal-lexical-0.2.1/libminimal_lexical.rlib ../subprojects/minimal-lexical-0.2.1/src/lib.rs
[6/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type rlib --edition=2018 -g -C relocation-model=pic --crate-name cookie_factory --emit dep-info=subprojects/cookie-factory-0.3.2/cookie_factory.d --emit link --cfg 'feature="default"' --cfg 'feature="std"' -o subprojects/cookie-factory-0.3.2/libcookie_factory.rlib ../subprojects/cookie-factory-0.3.2/src/lib.rs
[7/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type rlib --edition=2018 -g -C relocation-model=pic --crate-name memchr --emit dep-info=subprojects/memchr-2.5.0/memchr.d --emit link --cfg 'feature="default"' --cfg 'feature="std"' --cfg memchr_runtime_simd --cfg memchr_runtime_sse2 --cfg memchr_runtime_sse42 --cfg memchr_runtime_avx -o subprojects/memchr-2.5.0/libmemchr.rlib ../subprojects/memchr-2.5.0/src/lib.rs
[8/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type rlib --edition=2018 -g -C relocation-model=pic --crate-name nom --emit dep-info=subprojects/nom-7.1.3/nom.d --emit link --cfg 'feature="default"' --cfg 'feature="std"' --cfg 'feature="alloc"' -o subprojects/nom-7.1.3/libnom.rlib --extern memchr=subprojects/memchr-2.5.0/libmemchr.rlib --extern minimal_lexical=subprojects/minimal-lexical-0.2.1/libminimal_lexical.rlib -L subprojects/memchr-2.5.0 -L subprojects/minimal-lexical-0.2.1 ../subprojects/nom-7.1.3/src/lib.rs
[9/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type rlib --edition=2021 -g -C relocation-model=pic --crate-name hltas --emit dep-info=hltas.d --emit link -o libhltas.rlib --extern nom=subprojects/nom-7.1.3/libnom.rlib --extern cookie_factory=subprojects/cookie-factory-0.3.2/libcookie_factory.rlib -L subprojects/nom-7.1.3 -L subprojects/minimal-lexical-0.2.1 -L subprojects/memchr-2.5.0 -L subprojects/cookie-factory-0.3.2 ../src/lib.rs
[10/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type staticlib --edition=2021 -g -C relocation-model=pic --crate-name hltas_cpp_bridge --emit dep-info=hltas-cpp-bridge/hltas_cpp_bridge.d --emit link -o hltas-cpp-bridge/libhltas_cpp_bridge.a --extern hltas=libhltas.rlib --extern nom=subprojects/nom-7.1.3/libnom.rlib --extern cfg_if=subprojects/cfg-if-1.0.0/libcfg_if.rlib -L . -L subprojects/cookie-factory-0.3.2 -L subprojects/nom-7.1.3 -L subprojects/minimal-lexical-0.2.1 -L subprojects/memchr-2.5.0 -L subprojects/cfg-if-1.0.0 ../hltas-cpp-bridge/src/lib.rs
[11/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type bin --edition=2021 -g --crate-name hltas_tests --emit dep-info=hltas-tests.d --emit link --test -o hltas-tests --extern nom=subprojects/nom-7.1.3/libnom.rlib --extern cookie_factory=subprojects/cookie-factory-0.3.2/libcookie_factory.rlib -L subprojects/nom-7.1.3 -L subprojects/minimal-lexical-0.2.1 -L subprojects/memchr-2.5.0 -L subprojects/cookie-factory-0.3.2 ../src/lib.rs
[12/13] rustc -C linker=cc --color=always -C debug-assertions=yes --crate-type bin --edition=2021 -g --crate-name hltas_cpp_bridge_tests --emit dep-info=hltas-cpp-bridge/hltas-cpp-bridge-tests.d --emit link --test -o hltas-cpp-bridge/hltas-cpp-bridge-tests --extern hltas=libhltas.rlib --extern nom=subprojects/nom-7.1.3/libnom.rlib --extern cfg_if=subprojects/cfg-if-1.0.0/libcfg_if.rlib -L . -L subprojects/cookie-factory-0.3.2 -L subprojects/nom-7.1.3 -L subprojects/minimal-lexical-0.2.1 -L subprojects/memchr-2.5.0 -L subprojects/cfg-if-1.0.0 ../hltas-cpp-bridge/src/lib.rs
[13/13] c++  -o cpp/hltas-cpp-tests cpp/hltas-cpp-tests.p/src_tests.cpp.o -Wl,--as-needed -Wl,--no-undefined -Wl,--start-group cpp/libhltas_cpp.a hltas-cpp-bridge/libhltas_cpp_bridge.a -Wl,--end-group libhltas.rlib subprojects/nom-7.1.3/libnom.rlib subprojects/memchr-2.5.0/libmemchr.rlib subprojects/minimal-lexical-0.2.1/libminimal_lexical.rlib subprojects/cookie-factory-0.3.2/libcookie_factory.rlib subprojects/cfg-if-1.0.0/libcfg_if.rlib

Step 10 is building a staticlib, step 13 is then linking this into a C++ executable. All rlibs of step 10 (recursively) are added here.

meson should probably treat staticlib rlib dependencies as if they were link_whole instead of link_with.

CC @nirbheek @dcbaker @YaLTeR

@sdroege
Copy link
Contributor Author

sdroege commented Apr 24, 2023

Note that this does not happen if the staticlib in step 10 is changed to a cdylib.

@sdroege
Copy link
Contributor Author

sdroege commented Apr 24, 2023

See #11723 for a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants