Skip to content

Commit d2ff99c

Browse files
committed
Allow precompiled objects to be included in the build
Combined with Library.precompiled flag, allows a developer to ship a precompiled library. The linker (ld in our case) needs static libraries to be explicitely included in the build (it doesn't try any heuristic). Luckily, "including" a dynamic library in this way works as well, so we can avoid the "-L" and "-l" dance
1 parent 998741d commit d2ff99c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/arduino.cc/builder/phases/libraries_builder.go

+21
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package phases
3131

3232
import (
3333
"path/filepath"
34+
"strings"
3435

3536
"arduino.cc/builder/builder_utils"
3637
"arduino.cc/builder/constants"
@@ -40,6 +41,8 @@ import (
4041
"arduino.cc/properties"
4142
)
4243

44+
var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS = map[string]bool{".a": true, ".so": true}
45+
4346
type LibrariesBuilder struct{}
4447

4548
func (s *LibrariesBuilder) Run(ctx *types.Context) error {
@@ -93,6 +96,24 @@ func compileLibrary(library *types.Library, buildPath string, buildProperties pr
9396
}
9497

9598
objectFiles := []string{}
99+
100+
if library.Precompiled {
101+
// search for files with PRECOMPILED_LIBRARIES_VALID_EXTENSIONS
102+
extensions := func(ext string) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS[ext] }
103+
104+
filePaths := []string{}
105+
mcu := buildProperties[constants.BUILD_PROPERTIES_BUILD_MCU]
106+
err := utils.FindFilesInFolder(&filePaths, filepath.Join(library.SrcFolder, mcu), extensions, true)
107+
if err != nil {
108+
return nil, i18n.WrapError(err)
109+
}
110+
for _, path := range filePaths {
111+
if strings.Contains(filepath.Base(path), library.RealName) {
112+
objectFiles = append(objectFiles, path)
113+
}
114+
}
115+
}
116+
96117
if library.Layout == types.LIBRARY_RECURSIVE {
97118
objectFiles, err = builder_utils.CompileFilesRecursive(objectFiles, library.SrcFolder, libraryBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
98119
if err != nil {

0 commit comments

Comments
 (0)