2023-03-30 08:46:31 -05:00
|
|
|
# ignore-cross-compile
|
2023-03-30 07:58:50 -05:00
|
|
|
include ../tools.mk
|
2021-10-28 12:00:43 -05:00
|
|
|
|
|
|
|
# Ensure that crates compiled with different rustc versions cannot
|
|
|
|
# be dynamically linked.
|
|
|
|
|
2023-11-02 01:34:05 -05:00
|
|
|
FLAGS := -Cprefer-dynamic -Csymbol-mangling-version=v0
|
2021-10-28 12:00:43 -05:00
|
|
|
UNAME := $(shell uname)
|
|
|
|
ifeq ($(UNAME),Linux)
|
|
|
|
EXT=".so"
|
|
|
|
NM_CMD := nm -D
|
|
|
|
endif
|
|
|
|
ifeq ($(UNAME),Darwin)
|
|
|
|
EXT=".dylib"
|
|
|
|
NM_CMD := nm
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef NM_CMD
|
|
|
|
all:
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
all:
|
|
|
|
# a.rs is a dylib
|
|
|
|
$(RUSTC) a.rs --crate-type=dylib $(FLAGS)
|
|
|
|
# Write symbols to disk.
|
|
|
|
$(NM_CMD) $(call DYLIB,a) > $(TMPDIR)/symbolsbefore
|
|
|
|
# b.rs is a binary
|
|
|
|
$(RUSTC) b.rs --extern a=$(TMPDIR)/liba$(EXT) --crate-type=bin -Crpath $(FLAGS)
|
|
|
|
$(call RUN,b)
|
|
|
|
# Now re-compile a.rs with another rustc version
|
2022-01-12 15:31:26 -06:00
|
|
|
RUSTC_FORCE_RUSTC_VERSION=deadfeed $(RUSTC) a.rs --crate-type=dylib $(FLAGS)
|
2021-10-28 12:00:43 -05:00
|
|
|
# After compiling with a different rustc version, write symbols to disk again.
|
|
|
|
$(NM_CMD) $(call DYLIB,a) > $(TMPDIR)/symbolsafter
|
|
|
|
# As a sanity check, test if the symbols changed:
|
|
|
|
# If the symbols are identical, there's been an error.
|
|
|
|
if diff $(TMPDIR)/symbolsbefore $(TMPDIR)/symbolsafter; then exit 1; fi
|
|
|
|
$(call FAIL,b)
|
|
|
|
endif
|