diff options
| author | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-05 09:13:28 +0100 |
|---|---|---|
| committer | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-11 09:32:08 +0000 |
| commit | cf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch) | |
| tree | 40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/run-make/native-link-modifier-bundle | |
| parent | ca855e6e42787ecd062d81d53336fe6788ef51a9 (diff) | |
| download | rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip | |
Move /src/test to /tests
Diffstat (limited to 'tests/run-make/native-link-modifier-bundle')
6 files changed, 58 insertions, 0 deletions
diff --git a/tests/run-make/native-link-modifier-bundle/Makefile b/tests/run-make/native-link-modifier-bundle/Makefile new file mode 100644 index 00000000000..7c78d7783e0 --- /dev/null +++ b/tests/run-make/native-link-modifier-bundle/Makefile @@ -0,0 +1,33 @@ +# ignore-cross-compile +# ignore-windows-msvc + +include ../../run-make-fulldeps/tools.mk + +# We're using the llvm-nm instead of the system nm to ensure it is compatible +# with the LLVM bitcode generated by rustc. +NM = "$(LLVM_BIN_DIR)"/llvm-nm + +all: $(call NATIVE_STATICLIB,native-staticlib) + # Build a staticlib and a rlib, the `native_func` symbol will be bundled into them + $(RUSTC) bundled.rs --crate-type=staticlib --crate-type=rlib + $(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "T _*native_func" + $(NM) $(TMPDIR)/libbundled.a | $(CGREP) -e "U _*native_func" + $(NM) $(TMPDIR)/libbundled.rlib | $(CGREP) -e "T _*native_func" + $(NM) $(TMPDIR)/libbundled.rlib | $(CGREP) -e "U _*native_func" + + # Build a staticlib and a rlib, the `native_func` symbol will not be bundled into it + $(RUSTC) non-bundled.rs --crate-type=staticlib --crate-type=rlib + $(NM) $(TMPDIR)/libnon_bundled.a | $(CGREP) -ve "T _*native_func" + $(NM) $(TMPDIR)/libnon_bundled.a | $(CGREP) -e "U _*native_func" + $(NM) $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -ve "T _*native_func" + $(NM) $(TMPDIR)/libnon_bundled.rlib | $(CGREP) -e "U _*native_func" + + # Build a cdylib, `native-staticlib` will not appear on the linker line because it was bundled previously + # The cdylib will contain the `native_func` symbol in the end + $(RUSTC) cdylib-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -ve '-l[" ]*native-staticlib' + $(NM) $(call DYLIB,cdylib_bundled) | $(CGREP) -e "[Tt] _*native_func" + + # Build a cdylib, `native-staticlib` will appear on the linker line because it was not bundled previously + # The cdylib will contain the `native_func` symbol in the end + $(RUSTC) cdylib-non-bundled.rs --crate-type=cdylib --print link-args | $(CGREP) -e '-l[" ]*native-staticlib' + $(NM) $(call DYLIB,cdylib_non_bundled) | $(CGREP) -e "[Tt] _*native_func" diff --git a/tests/run-make/native-link-modifier-bundle/bundled.rs b/tests/run-make/native-link-modifier-bundle/bundled.rs new file mode 100644 index 00000000000..0bbae8752d7 --- /dev/null +++ b/tests/run-make/native-link-modifier-bundle/bundled.rs @@ -0,0 +1,11 @@ +#[link(name = "native-staticlib", kind = "static", modifiers = "+bundle")] +extern "C" { + pub fn native_func(); +} + +#[no_mangle] +pub extern "C" fn wrapped_func() { + unsafe { + native_func(); + } +} diff --git a/tests/run-make/native-link-modifier-bundle/cdylib-bundled.rs b/tests/run-make/native-link-modifier-bundle/cdylib-bundled.rs new file mode 100644 index 00000000000..7291309168a --- /dev/null +++ b/tests/run-make/native-link-modifier-bundle/cdylib-bundled.rs @@ -0,0 +1 @@ +extern crate bundled; diff --git a/tests/run-make/native-link-modifier-bundle/cdylib-non-bundled.rs b/tests/run-make/native-link-modifier-bundle/cdylib-non-bundled.rs new file mode 100644 index 00000000000..1df81fd101f --- /dev/null +++ b/tests/run-make/native-link-modifier-bundle/cdylib-non-bundled.rs @@ -0,0 +1 @@ +extern crate non_bundled; diff --git a/tests/run-make/native-link-modifier-bundle/native-staticlib.c b/tests/run-make/native-link-modifier-bundle/native-staticlib.c new file mode 100644 index 00000000000..d300fdf1c17 --- /dev/null +++ b/tests/run-make/native-link-modifier-bundle/native-staticlib.c @@ -0,0 +1 @@ +void native_func() {} diff --git a/tests/run-make/native-link-modifier-bundle/non-bundled.rs b/tests/run-make/native-link-modifier-bundle/non-bundled.rs new file mode 100644 index 00000000000..8181e6387c5 --- /dev/null +++ b/tests/run-make/native-link-modifier-bundle/non-bundled.rs @@ -0,0 +1,11 @@ +#[link(name = "native-staticlib", kind = "static", modifiers = "-bundle")] +extern "C" { + pub fn native_func(); +} + +#[no_mangle] +pub extern "C" fn wrapped_func() { + unsafe { + native_func(); + } +} |
