Skip to content

Commit 1c0a735

Browse files
committed
Use static library dependencies not when the library is built but when it is used.
1 parent 8d45972 commit 1c0a735

File tree

8 files changed

+35
-2
lines changed

8 files changed

+35
-2
lines changed

build.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class BuildTarget():
131131
'cs_args' : True,
132132
'link_args' : True,
133133
'link_depends': True,
134+
'link_with' : True,
134135
'include_directories': True,
135136
'dependencies' : True,
136137
'install_dir' : True,
@@ -362,7 +363,12 @@ def get_extra_args(self, language):
362363
return self.extra_args.get(language, [])
363364

364365
def get_dependencies(self):
365-
return self.link_targets
366+
transitive_deps = []
367+
for t in self.link_targets:
368+
transitive_deps.append(t)
369+
if isinstance(t, StaticLibrary):
370+
transitive_deps += t.get_dependencies()
371+
return transitive_deps
366372

367373
def get_basename(self):
368374
return self.name

environment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ class ArLinker():
13021302

13031303
def __init__(self, exelist):
13041304
self.exelist = exelist
1305+
self.id = 'ar'
13051306

13061307
def build_rpath_args(self, build_dir, rpath_paths, install_rpath):
13071308
return []

ninjabackend.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,13 @@ def generate_link(self, target, outfile, outname, obj_list, linker, extra_args=[
12391239
commands += linker.get_std_link_args()
12401240
else:
12411241
raise RuntimeError('Unknown build target type.')
1242-
dependencies = target.get_dependencies()
1242+
# Link arguments of static libraries are not put in the command line of
1243+
# the library. They are instead appended to the command line where
1244+
# the static library is used.
1245+
if linker_base == 'STATIC':
1246+
dependencies = []
1247+
else:
1248+
dependencies = target.get_dependencies()
12431249
commands += self.build_target_link_arguments(linker, dependencies)
12441250
commands += target.link_args
12451251
# External deps must be last because target link libraries may depend on them.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
project('statchain', 'c')
2+
3+
subdir('subdir')
4+
statlib = static_library('stat', 'stat.c', link_with : shlib)
5+
exe = executable('prog', 'prog.c', link_with : statlib)
6+
test('runtest', exe)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int statlibfunc();
2+
3+
int main(int argc, char **argv) {
4+
return statlibfunc() == 42 ? 0 : 1;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int shlibfunc();
2+
3+
int statlibfunc() {
4+
return shlibfunc();
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
shlib = shared_library('shar', 'shlib.c')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int shlibfunc() {
2+
return 42;
3+
}

0 commit comments

Comments
 (0)