Skip to content

Allow precompiled libs #219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 14, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
  • Loading branch information
facchinm committed Mar 16, 2017
commit d2ff99cdf9c798ca3b1acffaf88d47f23eca4199
21 changes: 21 additions & 0 deletions src/arduino.cc/builder/phases/libraries_builder.go
Original file line number Diff line number Diff line change
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