fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1# ignore-cross-compile 2include ../tools.mk 3 4# ignore-windows-msvc 5 6NM=nm -D 7CDYLIB_NAME=liba_cdylib.so 8RDYLIB_NAME=liba_rust_dylib.so 9PROC_MACRO_NAME=liba_proc_macro.so 10EXE_NAME=an_executable 11COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.so 12 13ifeq ($(UNAME),Darwin) 14NM=nm -gU 15CDYLIB_NAME=liba_cdylib.dylib 16RDYLIB_NAME=liba_rust_dylib.dylib 17PROC_MACRO_NAME=liba_proc_macro.dylib 18EXE_NAME=an_executable 19COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dylib 20endif 21 22ifdef IS_WINDOWS 23NM=nm -g 24CDYLIB_NAME=liba_cdylib.dll.a 25RDYLIB_NAME=liba_rust_dylib.dll.a 26PROC_MACRO_NAME=liba_proc_macro.dll 27EXE_NAME=an_executable.exe 28COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dll.a 29endif 30 31# `grep` regex for symbols produced by either `legacy` or `v0` mangling 32RE_ANY_RUST_SYMBOL="_ZN.*h.*E\|_R[a-zA-Z0-9_]+" 33 34all: 35 $(RUSTC) -Zshare-generics=no an_rlib.rs 36 $(RUSTC) -Zshare-generics=no a_cdylib.rs 37 $(RUSTC) -Zshare-generics=no a_rust_dylib.rs 38 $(RUSTC) -Zshare-generics=no a_proc_macro.rs 39 $(RUSTC) -Zshare-generics=no an_executable.rs 40 $(RUSTC) -Zshare-generics=no a_cdylib.rs --crate-name combined_rlib_dylib --crate-type=rlib,cdylib 41 42 # Check that a cdylib exports its public #[no_mangle] functions 43 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ] 44 # Check that a cdylib exports the public #[no_mangle] functions of dependencies 45 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ] 46 # Check that a cdylib DOES NOT export any public Rust functions 47 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ] 48 49 # Check that a Rust dylib exports its monomorphic functions 50 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rust_dylib)" -eq "1" ] 51 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rust_dylib)" -eq "1" ] 52 # Check that a Rust dylib does not export generics if -Zshare-generics=no 53 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rust_dylib)" -eq "0" ] 54 55 56 # Check that a Rust dylib exports the monomorphic functions from its dependencies 57 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ] 58 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rlib)" -eq "1" ] 59 # Check that a Rust dylib does not export generics if -Zshare-generics=no 60 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rlib)" -eq "0" ] 61 62 # Check that a proc macro exports its public #[no_mangle] functions 63 # FIXME(#99978) avoid exporting #[no_mangle] symbols for proc macros 64 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ] 65 # Check that a proc macro exports the public #[no_mangle] functions of dependencies 66 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ] 67 # Check that a proc macro DOES NOT export any public Rust functions 68 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ] 69 70# FIXME(nbdd0121): This is broken in MinGW, see https://github.com/rust-lang/rust/pull/95604#issuecomment-1101564032 71ifndef IS_WINDOWS 72 # Check that an executable does not export any dynamic symbols 73 [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "0" ] 74 [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_rust_function_from_exe)" -eq "0" ] 75endif 76 77 78 # Check the combined case, where we generate a cdylib and an rlib in the same 79 # compilation session: 80 # Check that a cdylib exports its public #[no_mangle] functions 81 [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ] 82 # Check that a cdylib exports the public #[no_mangle] functions of dependencies 83 [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ] 84 # Check that a cdylib DOES NOT export any public Rust functions 85 [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ] 86 87 88 $(RUSTC) -Zshare-generics=yes an_rlib.rs 89 $(RUSTC) -Zshare-generics=yes a_cdylib.rs 90 $(RUSTC) -Zshare-generics=yes a_rust_dylib.rs 91 $(RUSTC) -Zshare-generics=yes a_proc_macro.rs 92 $(RUSTC) -Zshare-generics=yes an_executable.rs 93 94 # Check that a cdylib exports its public #[no_mangle] functions 95 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ] 96 # Check that a cdylib exports the public #[no_mangle] functions of dependencies 97 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ] 98 # Check that a cdylib DOES NOT export any public Rust functions 99 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ] 100 101 # Check that a Rust dylib exports its monomorphic functions, including generics this time 102 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rust_dylib)" -eq "1" ] 103 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rust_dylib)" -eq "1" ] 104 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rust_dylib)" -eq "1" ] 105 106 # Check that a Rust dylib exports the monomorphic functions from its dependencies 107 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ] 108 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rlib)" -eq "1" ] 109 [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rlib)" -eq "1" ] 110 111 # Check that a proc macro exports its public #[no_mangle] functions 112 # FIXME(#99978) avoid exporting #[no_mangle] symbols for proc macros 113 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_cdylib)" -eq "1" ] 114 # Check that a proc macro exports the public #[no_mangle] functions of dependencies 115 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "1" ] 116 # Check that a proc macro DOES NOT export any public Rust functions 117 [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ] 118 119ifndef IS_WINDOWS 120 # Check that an executable does not export any dynamic symbols 121 [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "0" ] 122 [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_rust_function_from_exe)" -eq "0" ] 123endif