Skip to content

Commit 2da53e9

Browse files
xclaessejpakkane
authored andcommitted
rust: Add transitive dependencies to ninja rules
In the case r1 -> s1 -> s2 where s1 and s2 are uninstalled C static libraries, the libs1.a rule does not depend on libs2.a. That means that r1 rule must depend on both s1 and s2.
1 parent 0bc01e8 commit 2da53e9

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

mesonbuild/backend/ninjabackend.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,10 +1877,7 @@ def generate_rust_target(self, target: build.BuildTarget) -> None:
18771877
self.generate_generator_list_rules(target)
18781878

18791879
# dependencies need to cause a relink, they're not just for ordering
1880-
deps = [
1881-
os.path.join(t.subdir, t.get_filename())
1882-
for t in itertools.chain(target.link_targets, target.link_whole_targets)
1883-
]
1880+
deps: T.List[str] = []
18841881

18851882
# Dependencies for rust-project.json
18861883
project_deps: T.List[RustDep] = []
@@ -1983,6 +1980,7 @@ def _link_library(libname: str, static: bool, bundle: bool = False):
19831980
target_deps = target.get_dependencies()
19841981
for d in target_deps:
19851982
linkdirs.add(d.subdir)
1983+
deps.append(self.get_dependency_filename(d))
19861984
if d.uses_rust_abi():
19871985
if d not in itertools.chain(target.link_targets, target.link_whole_targets):
19881986
# Indirect Rust ABI dependency, we only need its path in linkdirs.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extern "C" {
2+
fn static2() -> i32;
3+
}
4+
5+
fn main() {
6+
unsafe {
7+
static2();
8+
}
9+
}

test cases/rust/21 transitive dependencies/meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ exe = executable('footest', 'foo.c',
2727
test('footest', exe)
2828

2929
subdir('diamond')
30+
31+
# The ninja rule for libstatic2.a does not depend on libstatic1.a because it
32+
# only need static2.c.o to create the archive. That means that the ninja rule
33+
# for app must depend on both, otherwise libstatic1.a won't be built and linking
34+
# will fail.
35+
static1 = static_library('static1', 'static1.c', build_by_default: false)
36+
static2 = static_library('static2', 'static2.c', link_with: static1)
37+
exe = executable('app', 'app.rs', link_with: static2)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int static1(void);
2+
3+
int static1(void){
4+
return 1;
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
int static1(void);
2+
int static2(void);
3+
4+
int static2(void)
5+
{
6+
return 1 + static1();
7+
}

0 commit comments

Comments
 (0)