Skip to content

Commit

Permalink
Allow precompiled objects to be included in the build
Browse files Browse the repository at this point in the history
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
  • Loading branch information
facchinm committed Mar 16, 2017
1 parent 998741d commit d2ff99c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/arduino.cc/builder/phases/libraries_builder.go
Expand Up @@ -31,6 +31,7 @@ package phases

import (
"path/filepath"
"strings"

"arduino.cc/builder/builder_utils"
"arduino.cc/builder/constants"
Expand All @@ -40,6 +41,8 @@ import (
"arduino.cc/properties"
)

var PRECOMPILED_LIBRARIES_VALID_EXTENSIONS = map[string]bool{".a": true, ".so": true}

type LibrariesBuilder struct{}

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

objectFiles := []string{}

if library.Precompiled {
// search for files with PRECOMPILED_LIBRARIES_VALID_EXTENSIONS
extensions := func(ext string) bool { return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS[ext] }

filePaths := []string{}
mcu := buildProperties[constants.BUILD_PROPERTIES_BUILD_MCU]
err := utils.FindFilesInFolder(&filePaths, filepath.Join(library.SrcFolder, mcu), extensions, true)
if err != nil {
return nil, i18n.WrapError(err)
}
for _, path := range filePaths {
if strings.Contains(filepath.Base(path), library.RealName) {
objectFiles = append(objectFiles, path)
}
}
}

if library.Layout == types.LIBRARY_RECURSIVE {
objectFiles, err = builder_utils.CompileFilesRecursive(objectFiles, library.SrcFolder, libraryBuildPath, buildProperties, includes, verbose, warningsLevel, logger)
if err != nil {
Expand Down

0 comments on commit d2ff99c

Please sign in to comment.