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