|
| 1 | +# This test case makes sure that native libraries are linked with --whole-archive semantics |
| 2 | +# when the `-bundle,+whole-archive` modifiers are applied to them. |
| 3 | +# |
| 4 | +# The test works by checking that the resulting executables produce the expected output, |
| 5 | +# part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work |
| 6 | +# that code would never make it into the final executable and we'd thus be missing some |
| 7 | +# of the output. |
| 8 | + |
| 9 | +-include ../../run-make-fulldeps/tools.mk |
| 10 | + |
| 11 | +all: $(TMPDIR)/$(call BIN,directly_linked) $(TMPDIR)/$(call BIN,indirectly_linked) $(TMPDIR)/$(call BIN,indirectly_linked_via_attr) |
| 12 | + $(call RUN,directly_linked) | $(CGREP) 'static-initializer.directly_linked.' |
| 13 | + $(call RUN,indirectly_linked) | $(CGREP) 'static-initializer.indirectly_linked.' |
| 14 | + $(call RUN,indirectly_linked_via_attr) | $(CGREP) 'static-initializer.native_lib_in_src.' |
| 15 | + |
| 16 | +# Native lib linked directly into executable |
| 17 | +$(TMPDIR)/$(call BIN,directly_linked): $(call NATIVE_STATICLIB,c_static_lib_with_constructor) |
| 18 | + $(RUSTC) directly_linked.rs -Z unstable-options -l static:+whole-archive=c_static_lib_with_constructor |
| 19 | + |
| 20 | +# Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable |
| 21 | +$(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib |
| 22 | + $(RUSTC) indirectly_linked.rs |
| 23 | + |
| 24 | +# Native lib linked into RLIB via #[link] attribute, RLIB linked into executable |
| 25 | +$(TMPDIR)/$(call BIN,indirectly_linked_via_attr): $(TMPDIR)/libnative_lib_in_src.rlib |
| 26 | + $(RUSTC) indirectly_linked_via_attr.rs |
| 27 | + |
| 28 | +# Native lib linked into rlib with via commandline |
| 29 | +$(TMPDIR)/librlib_with_cmdline_native_lib.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor) |
| 30 | + $(RUSTC) rlib_with_cmdline_native_lib.rs -Z unstable-options --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor |
| 31 | + |
| 32 | +# Native lib linked into rlib via `#[link()]` attribute on extern block. |
| 33 | +$(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor) |
| 34 | + $(RUSTC) native_lib_in_src.rs --crate-type=rlib |
| 35 | + |
| 36 | +$(TMPDIR)/libc_static_lib_with_constructor.o: c_static_lib_with_constructor.cpp |
| 37 | + $(call COMPILE_OBJ_CXX,$@,$<) |
0 commit comments