Skip to content

Commit 4410dc1

Browse files
committed
Consider existing archives during the build
1 parent 9e5276e commit 4410dc1

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: internal/arduino/builder/linker.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,32 @@ 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 archive for each directory from the remianing 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()
70+
relatedObjectFiles.FilterOutSuffix(".a")
6671
relatedObjectFiles.Filter(func(object *paths.Path) bool {
6772
// extract all the object files that are in the same directory of the archive
6873
return object.Parent().EquivalentTo(archiveDir)
6974
})
7075
b.archiveCompiledFiles(archive.Parent(), paths.New(archive.Base()), relatedObjectFiles)
7176
}
7277

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

0 commit comments

Comments
 (0)