forked from mesonbuild/meson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust: Do not bundle static libraries into internal libraries
When a Rust rlib/staticlib links to a C static library, it should not bundle its object files, unless it gets installed. This solves cases of multiple symbol definition when there is a diamond dependency graph. The only case we want to bundle is when a Rust staticlib link-whole another static library. In non-Rust case we achieve that by extracting objects, but rustc can do it for us. As extra bonus, rustc can bundle static libraries built with a CustomTarget.
- Loading branch information
Showing
10 changed files
with
91 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
int c_func(void); | ||
int c_func(void) { | ||
return 123; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int r3(void); | ||
|
||
int main_func(void) { | ||
return r3() == 246 ? 0 : 1; | ||
} |
25 changes: 25 additions & 0 deletions
25
test cases/rust/20 transitive dependencies/diamond/meson.build
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Regression test for a diamond dependency graph: | ||
# ┌►R1┐ | ||
# main-►R3─┤ ├─►C1 | ||
# └►R2┘ | ||
# Both libr1.rlib and libr2.rlib used to contain func.c.o. That was causing | ||
# libr3.rlib to have duplicated func.c.o and then libmain.so failed to link: | ||
# multiple definition of `c_func'. | ||
|
||
libc1 = static_library('c1', 'func.c') | ||
libr1 = static_library('r1', 'r1.rs', link_with: libc1) | ||
libr2 = static_library('r2', 'r2.rs', link_with: libc1) | ||
libr3 = static_library('r3', 'r3.rs', | ||
link_with: [libr1, libr2], | ||
rust_abi: 'c', | ||
) | ||
shared_library('main', 'main.c', link_whole: [libr3]) | ||
|
||
# Same dependency graph, but r3 is now installed. Since c1, r1 and r2 are | ||
# not installed, r3 must contain them. | ||
libr3 = static_library('r3-installed', 'r3.rs', | ||
link_with: [libr1, libr2], | ||
rust_abi: 'c', | ||
install: true, | ||
) | ||
shared_library('main-installed', 'main.c', link_with: [libr3]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extern "C" { | ||
fn c_func() -> i32; | ||
} | ||
|
||
pub fn r1() -> i32 { | ||
unsafe { | ||
c_func() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
extern "C" { | ||
fn c_func() -> i32; | ||
} | ||
|
||
pub fn r2() -> i32 { | ||
unsafe { | ||
c_func() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#[no_mangle] | ||
pub fn r3() -> i32 { | ||
r1::r1() + r2::r2() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,5 @@ exe = executable('footest', 'foo.c', | |
link_with: foo, | ||
) | ||
test('footest', exe) | ||
|
||
subdir('diamond') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"installed": [ | ||
{"type": "file", "file": "usr/lib/libr3-installed.a"} | ||
] | ||
} |