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