11include ../tools.mk
22
3- # ignore-windows
4- #
5- # On MINGW the --version-script, --dynamic-list, and --retain-symbol args don't
6- # seem to work reliably.
3+ # ignore-windows-msvc
74
85NM =nm -D
96CDYLIB_NAME =liba_cdylib.so
@@ -19,6 +16,14 @@ EXE_NAME=an_executable
1916COMBINED_CDYLIB_NAME =libcombined_rlib_dylib.dylib
2017endif
2118
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+
2227# `grep` regex for symbols produced by either `legacy` or `v0` mangling
2328RE_ANY_RUST_SYMBOL ="_ZN.*h.*E\|_R[a-zA-Z0-9_]+"
2429
3035 $(RUSTC ) -Zshare-generics=no a_cdylib.rs --crate-name combined_rlib_dylib --crate-type=rlib,cdylib
3136
3237 # Check that a cdylib exports its public #[no_mangle] functions
33- [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
38+ [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep - c public_c_function_from_cdylib)" -eq "1" ]
3439 # 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" ]
40+ [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep - c public_c_function_from_rlib)" -eq "1" ]
3641 # Check that a cdylib DOES NOT export any public Rust functions
37- [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
42+ [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep - c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
3843
3944 # 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" ]
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" ]
4247 # 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" ]
48+ [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep - c public_generic_function_from_rust_dylib)" -eq "0" ]
4449
4550
4651 # 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" ]
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" ]
4954 # 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" ]
55+ [ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep - c public_generic_function_from_rlib)" -eq "0" ]
5156
5257 # 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" ]
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" ]
5560
5661
5762 # Check the combined case, where we generate a cdylib and an rlib in the same
5863 # compilation session:
5964 # 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" ]
65+ [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep - c public_c_function_from_cdylib)" -eq "1" ]
6166 # 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" ]
67+ [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep - c public_c_function_from_rlib)" -eq "1" ]
6368 # 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" ]
69+ [ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -v __imp_ | grep - c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
6570
6671
6772 $(RUSTC) -Zshare-generics=yes an_rlib.rs
7075 $(RUSTC) -Zshare-generics=yes an_executable.rs
7176
7277 # Check that a cdylib exports its public #[no_mangle] functions
73- [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_cdylib)" -eq "1" ]
78+ [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep - c public_c_function_from_cdylib)" -eq "1" ]
7479 # 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" ]
80+ [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep - c public_c_function_from_rlib)" -eq "1" ]
7681 # Check that a cdylib DOES NOT export any public Rust functions
77- [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
82+ [ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -v __imp_ | grep - c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
7883
7984 # 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 "1" ]
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" ]
8388
8489 # 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 "1" ]
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" ]
8893
8994 # 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" ]
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" ]
0 commit comments