fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
3.1 KiB52 linesraw
1# ignore-cross-compile -- compiling C++ code does not work well when cross-compiling
2
3# This test case makes sure that native libraries are linked with appropriate semantics
4# when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
5#
6# The test works by checking that the resulting executables produce the expected output,
7# part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
8# that code would never make it into the final executable and we'd thus be missing some
9# of the output.
10
11include ../tools.mk
12
13all: $(TMPDIR)/$(call BIN,directly_linked) \
14     $(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive) \
15     $(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive) \
16     $(TMPDIR)/$(call BIN,indirectly_linked) \
17     $(TMPDIR)/$(call BIN,indirectly_linked_via_attr)
18	$(call RUN,directly_linked) | $(CGREP) 'static-initializer.directly_linked.'
19	$(call RUN,directly_linked_test_plus_whole_archive) --nocapture | $(CGREP) 'static-initializer.'
20	$(call RUN,directly_linked_test_minus_whole_archive) --nocapture | $(CGREP) -v 'static-initializer.'
21	$(call RUN,indirectly_linked) | $(CGREP) 'static-initializer.indirectly_linked.'
22	$(call RUN,indirectly_linked_via_attr) | $(CGREP) 'static-initializer.native_lib_in_src.'
23
24# Native lib linked directly into executable
25$(TMPDIR)/$(call BIN,directly_linked): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
26	$(RUSTC) directly_linked.rs -l static:+whole-archive=c_static_lib_with_constructor
27
28# Native lib linked into test executable, +whole-archive
29$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
30	$(RUSTC) directly_linked_test_plus_whole_archive.rs --test -l static:+whole-archive=c_static_lib_with_constructor
31# Native lib linked into test executable, -whole-archive
32$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
33	$(RUSTC) directly_linked_test_minus_whole_archive.rs --test -l static:-whole-archive=c_static_lib_with_constructor
34
35# Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
36$(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib
37	$(RUSTC) indirectly_linked.rs
38
39# Native lib linked into RLIB via #[link] attribute, RLIB linked into executable
40$(TMPDIR)/$(call BIN,indirectly_linked_via_attr): $(TMPDIR)/libnative_lib_in_src.rlib
41	$(RUSTC) indirectly_linked_via_attr.rs
42
43# Native lib linked into rlib with via commandline
44$(TMPDIR)/librlib_with_cmdline_native_lib.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
45	$(RUSTC) rlib_with_cmdline_native_lib.rs --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor
46
47# Native lib linked into rlib via `#[link()]` attribute on extern block.
48$(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
49	$(RUSTC) native_lib_in_src.rs --crate-type=rlib
50
51$(TMPDIR)/libc_static_lib_with_constructor.o: c_static_lib_with_constructor.cpp
52	$(call COMPILE_OBJ_CXX,$@,$<)