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

static-link feature doesn't seem to do anything without also specifying bundled (Linux) #1196

Open
valderman opened this issue Jan 10, 2022 · 3 comments
Labels
bug build-process Everything related to build.rs, or the build process in general

Comments

@valderman
Copy link

When #1195 prevented me from building my small image-using project with the bundled feature, I tried to link statically against the system libraries instead. Unfortunately, everything gets dynamically linked, as if static-link was never specified.

Using the following config:

[dependencies.sdl2]
version = "~0.35"
default-features = false
features = ["static-link", "use-pkgconfig", "image"]

The expected result is a binary with ~5 dependencies, which is what I get if I replace use-pkgconfig with bundled and commend out any use of the image feature.

However, running ldd on the binary built with the config shown above results in the following monstrosity:

	linux-vdso.so.1 (0x00007ffffa9ee000)
	libSDL2_image-2.0.so.0 => /lib/x86_64-linux-gnu/libSDL2_image-2.0.so.0 (0x00007f7fb3e03000)
	libSDL2-2.0.so.0 => /lib/x86_64-linux-gnu/libSDL2-2.0.so.0 (0x00007f7fb3c64000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7fb3c5d000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7fb3c3c000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7fb3c22000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7fb3a57000)
	libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f7fb3a1d000)
	libjpeg.so.62 => /lib/x86_64-linux-gnu/libjpeg.so.62 (0x00007f7fb3999000)
	libtiff.so.5 => /lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f7fb3912000)
	libwebp.so.6 => /lib/x86_64-linux-gnu/libwebp.so.6 (0x00007f7fb38a9000)
	libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2 (0x00007f7fb37a2000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7fb365d000)
	libpulse.so.0 => /lib/x86_64-linux-gnu/libpulse.so.0 (0x00007f7fb3608000)
	libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f7fb34c5000)
	libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f7fb34b0000)
	libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f7fb34a3000)
	libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f7fb349e000)
	libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f7fb3488000)
	libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f7fb3480000)
	libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f7fb3473000)
	libXss.so.1 => /lib/x86_64-linux-gnu/libXss.so.1 (0x00007f7fb346e000)
	libXxf86vm.so.1 => /lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f7fb3268000)
	libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f7fb3253000)
	libgbm.so.1 => /lib/x86_64-linux-gnu/libgbm.so.1 (0x00007f7fb3241000)
	libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007f7fb323c000)
	libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007f7fb322b000)
	libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007f7fb3222000)
	libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f7fb31dc000)
	libdecor-0.so.0 => /lib/x86_64-linux-gnu/libdecor-0.so.0 (0x00007f7fb31d1000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f7fb3e8a000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7fb31b2000)
	libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f7fb30d7000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f7fb30af000)
	libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f7fb2ea1000)
	libdeflate.so.0 => /lib/x86_64-linux-gnu/libdeflate.so.0 (0x00007f7fb2e85000)
	libpulsecommon-15.0.so => /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-15.0.so (0x00007f7fb2dfa000)
	libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f7fb2da6000)
	libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f7fb2d7b000)
	libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f7fb2b71000)
	libwayland-server.so.0 => /lib/x86_64-linux-gnu/libwayland-server.so.0 (0x00007f7fb2b5a000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f7fb2b28000)
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7fb291c000)
	libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007f7fb290f000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7fb2904000)
	libsndfile.so.1 => /lib/x86_64-linux-gnu/libsndfile.so.1 (0x00007f7fb2881000)
	libX11-xcb.so.1 => /lib/x86_64-linux-gnu/libX11-xcb.so.1 (0x00007f7fb287a000)
	libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f7fb279b000)
	libasyncns.so.0 => /lib/x86_64-linux-gnu/libasyncns.so.0 (0x00007f7fb2793000)
	libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007f7fb2787000)
	libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f7fb2782000)
	libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f7fb257c000)
	libFLAC.so.8 => /lib/x86_64-linux-gnu/libFLAC.so.8 (0x00007f7fb253b000)
	libvorbis.so.0 => /lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f7fb250e000)
	libvorbisenc.so.2 => /lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f7fb2463000)
	libopus.so.0 => /lib/x86_64-linux-gnu/libopus.so.0 (0x00007f7fb2408000)
	libogg.so.0 => /lib/x86_64-linux-gnu/libogg.so.0 (0x00007f7fb23fb000)
	liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f7fb23d6000)
	libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x00007f7fb23cb000)
	libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f7fb2290000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f7fb2276000)
	libnsl.so.2 => /lib/x86_64-linux-gnu/libnsl.so.2 (0x00007f7fb225b000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f7fb2244000)
	libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f7fb221b000)
	libtirpc.so.3 => /lib/x86_64-linux-gnu/libtirpc.so.3 (0x00007f7fb21ec000)
	libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007f7fb21df000)
	libgssapi_krb5.so.2 => /lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f7fb218c000)
	libkrb5.so.3 => /lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f7fb20b2000)
	libk5crypto.so.3 => /lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f7fb2080000)
	libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f7fb207a000)
	libkrb5support.so.0 => /lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f7fb206b000)
	libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f7fb2064000)
@Cobrand Cobrand added bug build-process Everything related to build.rs, or the build process in general labels Jan 10, 2022
@Cobrand
Copy link
Member

Cobrand commented Jan 10, 2022

This seems to be a regression, I have no idea from when though.

Even without image simply using cargo build --example demo --features use-pkgconfig,static-link links SDL2 dynamically, which is not the behavior expected:

ldd target/debug/examples/demo
	linux-vdso.so.1 (0x00007ffd653c4000)
	libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f132db63000)
	libSDL2-2.0.so.0 => /usr/lib/libSDL2-2.0.so.0 (0x00007f132d9bf000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f132d9a4000)
	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f132d983000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f132d7b7000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f132dc09000)
	libm.so.6 => /usr/lib/libm.so.6 (0x00007f132d673000)

@valderman valderman changed the title static-link feature seem to do anything without also specifying bundled (Linux) static-link feature doesn't seem to do anything without also specifying bundled (Linux) Jan 11, 2022
@Cobrand
Copy link
Member

Cobrand commented Jan 22, 2022

It seems to be an upstream issue from pkg-config: rust-lang/pkg-config-rs#102 (comment)

@nistvan86
Copy link

nistvan86 commented Oct 25, 2022

I wonder if we could use sdl2-config --cflags --static-libs instead of pkg-config to figure out library dependencies in such case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build-process Everything related to build.rs, or the build process in general
Projects
None yet
Development

No branches or pull requests

3 participants