2023-03-30 08:46:31 -05:00
|
|
|
# ignore-cross-compile
|
2016-12-01 14:06:33 -06:00
|
|
|
include ../tools.mk
|
|
|
|
|
2020-07-03 13:55:13 -05:00
|
|
|
# ignore-windows-msvc
|
2016-12-02 17:02:46 -06:00
|
|
|
|
|
|
|
NM=nm -D
|
|
|
|
CDYLIB_NAME=liba_cdylib.so
|
|
|
|
RDYLIB_NAME=liba_rust_dylib.so
|
2022-07-30 07:16:33 -05:00
|
|
|
PROC_MACRO_NAME=liba_proc_macro.so
|
2016-12-02 17:02:46 -06:00
|
|
|
EXE_NAME=an_executable
|
2017-10-31 08:00:28 -05:00
|
|
|
COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.so
|
2016-12-02 17:02:46 -06:00
|
|
|
|
|
|
|
ifeq ($(UNAME),Darwin)
|
|
|
|
NM=nm -gU
|
|
|
|
CDYLIB_NAME=liba_cdylib.dylib
|
|
|
|
RDYLIB_NAME=liba_rust_dylib.dylib
|
2022-07-30 07:16:33 -05:00
|
|
|
PROC_MACRO_NAME=liba_proc_macro.dylib
|
2016-12-02 17:02:46 -06:00
|
|
|
EXE_NAME=an_executable
|
2017-10-31 08:00:28 -05:00
|
|
|
COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dylib
|
2016-12-02 17:02:46 -06:00
|
|
|
endif
|
|
|
|
|
2020-07-03 13:55:13 -05:00
|
|
|
ifdef IS_WINDOWS
|
|
|
|
NM=nm -g
|
|
|
|
CDYLIB_NAME=liba_cdylib.dll.a
|
|
|
|
RDYLIB_NAME=liba_rust_dylib.dll.a
|
2022-07-30 07:16:33 -05:00
|
|
|
PROC_MACRO_NAME=liba_proc_macro.dll
|
2020-07-03 13:55:13 -05:00
|
|
|
EXE_NAME=an_executable.exe
|
|
|
|
COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dll.a
|
|
|
|
endif
|
|
|
|
|
2019-04-13 11:03:02 -05:00
|
|
|
# `grep` regex for symbols produced by either `legacy` or `v0` mangling
|
|
|
|
RE_ANY_RUST_SYMBOL="_ZN.*h.*E\|_R[a-zA-Z0-9_]+"
|
|
|
|
|
2016-12-01 14:06:33 -06:00
|
|
|
all:
|
2018-03-13 08:21:50 -05:00
|
|
|
$(RUSTC) -Zshare-generics=no an_rlib.rs
|
|
|
|
$(RUSTC) -Zshare-generics=no a_cdylib.rs
|
|
|
|
$(RUSTC) -Zshare-generics=no a_rust_dylib.rs
|
2022-07-30 07:16:33 -05:00
|
|
|
$(RUSTC) -Zshare-generics=no a_proc_macro.rs
|
2018-03-13 08:21:50 -05:00
|
|
|
$(RUSTC) -Zshare-generics=no an_executable.rs
|
|
|
|
$(RUSTC) -Zshare-generics=no a_cdylib.rs --crate-name combined_rlib_dylib --crate-type=rlib,cdylib
|
2016-12-01 14:06:33 -06:00
|
|
|
|
|
|
|
# Check that a cdylib exports its public #[no_mangle] functions
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ]
|
2016-12-01 14:06:33 -06:00
|
|
|
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ]
|
2016-12-01 14:06:33 -06:00
|
|
|
# Check that a cdylib DOES NOT export any public Rust functions
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
|
2016-12-01 14:06:33 -06:00
|
|
|
|
|
|
|
# Check that a Rust dylib exports its monomorphic functions
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rust_dylib)" -eq "1" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
# Check that a Rust dylib does not export generics if -Zshare-generics=no
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rust_dylib)" -eq "0" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
|
2016-12-01 14:06:33 -06:00
|
|
|
|
|
|
|
# Check that a Rust dylib exports the monomorphic functions from its dependencies
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rlib)" -eq "1" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
# Check that a Rust dylib does not export generics if -Zshare-generics=no
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rlib)" -eq "0" ]
|
2016-12-01 14:06:33 -06:00
|
|
|
|
2022-07-30 07:16:33 -05:00
|
|
|
# Check that a proc macro exports its public #[no_mangle] functions
|
2022-07-31 05:10:58 -05:00
|
|
|
# FIXME(#99978) avoid exporting #[no_mangle] symbols for proc macros
|
2022-07-30 07:16:33 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ]
|
|
|
|
# Check that a proc macro exports the public #[no_mangle] functions of dependencies
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ]
|
|
|
|
# Check that a proc macro DOES NOT export any public Rust functions
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
|
|
|
|
|
2022-04-18 14:49:59 -05:00
|
|
|
# FIXME(nbdd0121): This is broken in MinGW, see https://github.com/rust-lang/rust/pull/95604#issuecomment-1101564032
|
|
|
|
ifndef IS_WINDOWS
|
2016-12-01 14:06:33 -06:00
|
|
|
# Check that an executable does not export any dynamic symbols
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "0" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_rust_function_from_exe)" -eq "0" ]
|
2022-04-18 14:49:59 -05:00
|
|
|
endif
|
2016-12-02 17:02:46 -06:00
|
|
|
|
2017-10-31 08:00:28 -05:00
|
|
|
|
|
|
|
# Check the combined case, where we generate a cdylib and an rlib in the same
|
|
|
|
# compilation session:
|
|
|
|
# Check that a cdylib exports its public #[no_mangle] functions
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ]
|
2017-10-31 08:00:28 -05:00
|
|
|
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ]
|
2017-10-31 08:00:28 -05:00
|
|
|
# Check that a cdylib DOES NOT export any public Rust functions
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
$(RUSTC) -Zshare-generics=yes an_rlib.rs
|
|
|
|
$(RUSTC) -Zshare-generics=yes a_cdylib.rs
|
|
|
|
$(RUSTC) -Zshare-generics=yes a_rust_dylib.rs
|
2022-07-30 07:16:33 -05:00
|
|
|
$(RUSTC) -Zshare-generics=yes a_proc_macro.rs
|
2018-03-13 08:21:50 -05:00
|
|
|
$(RUSTC) -Zshare-generics=yes an_executable.rs
|
|
|
|
|
|
|
|
# Check that a cdylib exports its public #[no_mangle] functions
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
# Check that a cdylib DOES NOT export any public Rust functions
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
|
|
|
|
# Check that a Rust dylib exports its monomorphic functions, including generics this time
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rust_dylib)" -eq "1" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rust_dylib)" -eq "1" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
|
|
|
|
# Check that a Rust dylib exports the monomorphic functions from its dependencies
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rlib)" -eq "1" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rlib)" -eq "1" ]
|
2018-03-13 08:21:50 -05:00
|
|
|
|
2022-07-30 07:16:33 -05:00
|
|
|
# Check that a proc macro exports its public #[no_mangle] functions
|
2022-07-31 05:10:58 -05:00
|
|
|
# FIXME(#99978) avoid exporting #[no_mangle] symbols for proc macros
|
2022-07-30 07:16:33 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ]
|
|
|
|
# Check that a proc macro exports the public #[no_mangle] functions of dependencies
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ]
|
|
|
|
# Check that a proc macro DOES NOT export any public Rust functions
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
|
|
|
|
|
2022-04-18 14:49:59 -05:00
|
|
|
ifndef IS_WINDOWS
|
2018-03-13 08:21:50 -05:00
|
|
|
# Check that an executable does not export any dynamic symbols
|
2020-07-03 13:55:13 -05:00
|
|
|
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "0" ]
|
|
|
|
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_rust_function_from_exe)" -eq "0" ]
|
2022-04-18 14:49:59 -05:00
|
|
|
endif
|