]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/symbol-visibility/Makefile
Rollup merge of #64746 - estebank:elide-impl-trait-obligations-on-err, r=cramertj
[rust.git] / src / test / run-make-fulldeps / symbol-visibility / Makefile
1 include ../tools.mk
2
3 # ignore-windows
4 #
5 # On MINGW the --version-script, --dynamic-list, and --retain-symbol args don't
6 # seem to work reliably.
7
8 NM=nm -D
9 CDYLIB_NAME=liba_cdylib.so
10 RDYLIB_NAME=liba_rust_dylib.so
11 EXE_NAME=an_executable
12 COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.so
13
14 ifeq ($(UNAME),Darwin)
15 NM=nm -gU
16 CDYLIB_NAME=liba_cdylib.dylib
17 RDYLIB_NAME=liba_rust_dylib.dylib
18 EXE_NAME=an_executable
19 COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dylib
20 endif
21
22 # `grep` regex for symbols produced by either `legacy` or `v0` mangling
23 RE_ANY_RUST_SYMBOL="_ZN.*h.*E\|_R[a-zA-Z0-9_]+"
24
25 all:
26         $(RUSTC) -Zshare-generics=no an_rlib.rs
27         $(RUSTC) -Zshare-generics=no a_cdylib.rs
28         $(RUSTC) -Zshare-generics=no a_rust_dylib.rs
29         $(RUSTC) -Zshare-generics=no an_executable.rs
30         $(RUSTC) -Zshare-generics=no a_cdylib.rs --crate-name combined_rlib_dylib --crate-type=rlib,cdylib
31
32         # Check that a cdylib exports its public #[no_mangle] functions
33         [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
34         # Check that a cdylib exports the public #[no_mangle] functions of dependencies
35         [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
36         # Check that a cdylib DOES NOT export any public Rust functions
37         [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
38
39         # Check that a Rust dylib exports its monomorphic functions
40         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
41         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rust_dylib)" -eq "1" ]
42         # Check that a Rust dylib does not export generics if -Zshare-generics=no
43         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rust_dylib)" -eq "0" ]
44
45
46         # Check that a Rust dylib exports the monomorphic functions from its dependencies
47         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
48         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rlib)" -eq "1" ]
49         # Check that a Rust dylib does not export generics if -Zshare-generics=no
50         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rlib)" -eq "0" ]
51
52         # Check that an executable does not export any dynamic symbols
53         [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]
54         [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_rust_function_from_exe)" -eq "0" ]
55
56
57         # Check the combined case, where we generate a cdylib and an rlib in the same
58         # compilation session:
59         # Check that a cdylib exports its public #[no_mangle] functions
60         [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
61         # Check that a cdylib exports the public #[no_mangle] functions of dependencies
62         [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
63         # Check that a cdylib DOES NOT export any public Rust functions
64         [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
65
66
67         $(RUSTC) -Zshare-generics=yes an_rlib.rs
68         $(RUSTC) -Zshare-generics=yes a_cdylib.rs
69         $(RUSTC) -Zshare-generics=yes a_rust_dylib.rs
70         $(RUSTC) -Zshare-generics=yes an_executable.rs
71
72         # Check that a cdylib exports its public #[no_mangle] functions
73         [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
74         # Check that a cdylib exports the public #[no_mangle] functions of dependencies
75         [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
76         # Check that a cdylib DOES NOT export any public Rust functions
77         [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
78
79         # Check that a Rust dylib exports its monomorphic functions, including generics this time
80         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
81         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rust_dylib)" -eq "1" ]
82         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rust_dylib)" -eq "0" ]
83
84         # Check that a Rust dylib exports the monomorphic functions from its dependencies
85         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
86         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rlib)" -eq "1" ]
87         [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rlib)" -eq "0" ]
88
89         # Check that an executable does not export any dynamic symbols
90         [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]
91         [ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_rust_function_from_exe)" -eq "0" ]