rust/tests/run-make/no-cdylib-as-rdylib/Makefile
bjorn3 008be2d7b6 Verify that all crate sources are in sync
This ensures that rustc will not attempt to link against a cdylib as if
it is a rust dylib when an rlib for the same crate is available.
Previously rustc didn't actually check if any further formats of a
crate which has been loaded are of the same version and if they are
actually valid. This caused a cdylib to be interpreted as rust dylib as
soon as the corresponding rlib was loaded. As cdylibs don't export any
rust symbols, linking would fail if rustc decides to link against the
cdylib rather than the rlib.

Two crates depended on the previous behavior by separately compiling a
test crate as both rlib and dylib. These have been changed to capture
their original spirit to the best of my ability while still working
when rustc verifies that all crates are in sync. It is unlikely that
build systems depend on the current behavior and in any case we are
taking a lot of measures to ensure that any change to either the source
or the compilation options (including crate type) results in rustc
rejecting it as incompatible. We merely didn't do this check here for
now obsolete perf reasons.
2023-07-19 14:47:05 +00:00

17 lines
679 B
Makefile

# ignore-cross-compile
include ../tools.mk
# Test that rustc will not attempt to link against a cdylib as if
# it is a rust dylib when an rlib for the same crate is available.
# Previously rustc didn't actually check if any further formats of
# a crate which has been loaded are of the same version and if
# they are actually valid. This caused a cdylib to be interpreted
# as rust dylib as soon as the corresponding rlib was loaded. As
# cdylibs don't export any rust symbols, linking would fail if
# rustc decides to link against the cdylib rather than the rlib.
all:
$(RUSTC) bar.rs --crate-type=rlib --crate-type=cdylib
$(RUSTC) foo.rs -C prefer-dynamic
$(call RUN,foo)