2021-08-30 09:54:12 +00:00
|
|
|
# ignore-cross-compile -- compiling C++ code does not work well when cross-compiling
|
|
|
|
|
2022-08-01 18:47:32 +00:00
|
|
|
# This test case makes sure that native libraries are linked with appropriate semantics
|
|
|
|
# when the `[+-]bundle,[+-]whole-archive` modifiers are applied to them.
|
2021-08-30 09:54:12 +00:00
|
|
|
#
|
|
|
|
# The test works by checking that the resulting executables produce the expected output,
|
|
|
|
# part of which is emitted by otherwise unreferenced C code. If +whole-archive didn't work
|
|
|
|
# that code would never make it into the final executable and we'd thus be missing some
|
|
|
|
# of the output.
|
|
|
|
|
2023-03-30 12:58:50 +00:00
|
|
|
include ../tools.mk
|
2021-08-30 09:54:12 +00:00
|
|
|
|
2022-08-01 18:47:32 +00:00
|
|
|
all: $(TMPDIR)/$(call BIN,directly_linked) \
|
|
|
|
$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive) \
|
|
|
|
$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive) \
|
|
|
|
$(TMPDIR)/$(call BIN,indirectly_linked) \
|
|
|
|
$(TMPDIR)/$(call BIN,indirectly_linked_via_attr)
|
2021-08-30 09:54:12 +00:00
|
|
|
$(call RUN,directly_linked) | $(CGREP) 'static-initializer.directly_linked.'
|
2022-08-01 18:47:32 +00:00
|
|
|
$(call RUN,directly_linked_test_plus_whole_archive) --nocapture | $(CGREP) 'static-initializer.'
|
|
|
|
$(call RUN,directly_linked_test_minus_whole_archive) --nocapture | $(CGREP) -v 'static-initializer.'
|
2021-08-30 09:54:12 +00:00
|
|
|
$(call RUN,indirectly_linked) | $(CGREP) 'static-initializer.indirectly_linked.'
|
|
|
|
$(call RUN,indirectly_linked_via_attr) | $(CGREP) 'static-initializer.native_lib_in_src.'
|
|
|
|
|
|
|
|
# Native lib linked directly into executable
|
|
|
|
$(TMPDIR)/$(call BIN,directly_linked): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
|
2022-04-08 15:20:57 +00:00
|
|
|
$(RUSTC) directly_linked.rs -l static:+whole-archive=c_static_lib_with_constructor
|
2021-08-30 09:54:12 +00:00
|
|
|
|
2022-08-01 18:47:32 +00:00
|
|
|
# Native lib linked into test executable, +whole-archive
|
|
|
|
$(TMPDIR)/$(call BIN,directly_linked_test_plus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
|
|
|
|
$(RUSTC) directly_linked_test_plus_whole_archive.rs --test -l static:+whole-archive=c_static_lib_with_constructor
|
|
|
|
# Native lib linked into test executable, -whole-archive
|
|
|
|
$(TMPDIR)/$(call BIN,directly_linked_test_minus_whole_archive): $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
|
|
|
|
$(RUSTC) directly_linked_test_minus_whole_archive.rs --test -l static:-whole-archive=c_static_lib_with_constructor
|
|
|
|
|
2021-08-30 09:54:12 +00:00
|
|
|
# Native lib linked into RLIB via `-l static:-bundle,+whole-archive`, RLIB linked into executable
|
|
|
|
$(TMPDIR)/$(call BIN,indirectly_linked): $(TMPDIR)/librlib_with_cmdline_native_lib.rlib
|
|
|
|
$(RUSTC) indirectly_linked.rs
|
|
|
|
|
|
|
|
# Native lib linked into RLIB via #[link] attribute, RLIB linked into executable
|
|
|
|
$(TMPDIR)/$(call BIN,indirectly_linked_via_attr): $(TMPDIR)/libnative_lib_in_src.rlib
|
|
|
|
$(RUSTC) indirectly_linked_via_attr.rs
|
|
|
|
|
|
|
|
# Native lib linked into rlib with via commandline
|
|
|
|
$(TMPDIR)/librlib_with_cmdline_native_lib.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
|
2022-04-08 15:20:57 +00:00
|
|
|
$(RUSTC) rlib_with_cmdline_native_lib.rs --crate-type=rlib -l static:-bundle,+whole-archive=c_static_lib_with_constructor
|
2021-08-30 09:54:12 +00:00
|
|
|
|
|
|
|
# Native lib linked into rlib via `#[link()]` attribute on extern block.
|
|
|
|
$(TMPDIR)/libnative_lib_in_src.rlib: $(call NATIVE_STATICLIB,c_static_lib_with_constructor)
|
|
|
|
$(RUSTC) native_lib_in_src.rs --crate-type=rlib
|
|
|
|
|
|
|
|
$(TMPDIR)/libc_static_lib_with_constructor.o: c_static_lib_with_constructor.cpp
|
|
|
|
$(call COMPILE_OBJ_CXX,$@,$<)
|