Skip to content

Commit 06e3e7f

Browse files
committed
Consider existing archives during the build
1 parent 7af3197 commit 06e3e7f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

internal/arduino/builder/linker.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ func (b *Builder) link() error {
5353
// it may happen that a subdir/spi.o inside the archive may be overwritten by a anotherdir/spi.o
5454
// because thery are both named spi.o.
5555

56-
archives := paths.NewPathList()
56+
// Put all the existing archives apart from the other object files
57+
existingArchives := objectFiles.Clone()
58+
existingArchives.FilterSuffix(".a")
59+
objectFiles.FilterOutSuffix(".a")
60+
61+
// Generate an archive for each directory from the remaining object files
62+
newArchives := paths.NewPathList()
5763
for _, object := range objectFiles {
5864
archive := object.Parent().Join("objs.a")
59-
archives.AddIfMissing(archive)
65+
newArchives.AddIfMissing(archive)
6066
}
61-
62-
// Generate archive for each directory
63-
for _, archive := range archives {
67+
for _, archive := range newArchives {
6468
archiveDir := archive.Parent()
6569
relatedObjectFiles := objectFiles.Clone()
6670
relatedObjectFiles.Filter(func(object *paths.Path) bool {
@@ -70,7 +74,10 @@ func (b *Builder) link() error {
7074
b.archiveCompiledFiles(archive.Parent(), paths.New(archive.Base()), relatedObjectFiles)
7175
}
7276

73-
objectFileList = strings.Join(f.Map(archives.AsStrings(), wrapWithDoubleQuotes), " ")
77+
// Put everything together
78+
allArchives := existingArchives.Clone()
79+
allArchives.AddAll(newArchives)
80+
objectFileList = strings.Join(f.Map(allArchives.AsStrings(), wrapWithDoubleQuotes), " ")
7481
objectFileList = "-Wl,--whole-archive " + objectFileList + " -Wl,--no-whole-archive"
7582
}
7683

0 commit comments

Comments
 (0)