Skip to content

Fix mixed code precompiled libraries #611

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 13 commits into from
May 8, 2020
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
Next Next commit
Fix mixed code precompiled libraries
This patch restores some functionalities broken by #512 .
It introduces a BREAKING CHANGE to "precompiled" field

If merged, "precompiled" means that the library ONLY contains a precompiled library and its headers.
No file containing implementation will be compiled if the library is specified as such.

Fixes arduino/arduino-builder#353

Tested with
* #512 (comment) (Nano33BLE and generic MKR board)
* https://github.com/BoschSensortec/BSEC-Arduino-library (works after removing precompiled=true directive in library.properties)
* https://github.com/vidor-libraries/USBBlaster (MKRVidor, fully precompiled)
  • Loading branch information
facchinm authored and cmaglie committed May 4, 2020
commit 341cf723644592ea722c813be9e31080de31b4e2
50 changes: 24 additions & 26 deletions legacy/builder/phases/libraries_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
ctx.LibrariesObjectFiles = objectFiles

// Search for precompiled libraries
fixLDFLAGforPrecompiledLibraries(ctx, libs)
fixLDFLAG(ctx, libs)

return nil
}
Expand Down Expand Up @@ -109,35 +109,33 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
return nil
}

func fixLDFLAGforPrecompiledLibraries(ctx *types.Context, libs libraries.List) error {
func fixLDFLAG(ctx *types.Context, libs libraries.List) error {

for _, library := range libs {
if library.Precompiled {
// add library src path to compiler.c.elf.extra_flags
// use library.Name as lib name and srcPath/{mcpu} as location
path := findExpectedPrecompiledLibFolder(ctx, library)
if path == nil {
break
}
// find all library names in the folder and prepend -l
filePaths := []string{}
libs_cmd := library.LDflags + " "
extensions := func(ext string) bool {
return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC[ext] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext]
}
utils.FindFilesInFolder(&filePaths, path.String(), extensions, false)
for _, lib := range filePaths {
name := strings.TrimSuffix(filepath.Base(lib), filepath.Ext(lib))
// strip "lib" first occurrence
if strings.HasPrefix(name, "lib") {
name = strings.Replace(name, "lib", "", 1)
libs_cmd += "-l" + name + " "
}
// add library src path to compiler.c.elf.extra_flags
// use library.Name as lib name and srcPath/{mcpu} as location
path := findExpectedPrecompiledLibFolder(ctx, library)
if path == nil {
break
}
// find all library names in the folder and prepend -l
filePaths := []string{}
libs_cmd := library.LDflags + " "
extensions := func(ext string) bool {
return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC[ext] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext]
}
utils.FindFilesInFolder(&filePaths, path.String(), extensions, false)
for _, lib := range filePaths {
name := strings.TrimSuffix(filepath.Base(lib), filepath.Ext(lib))
// strip "lib" first occurrence
if strings.HasPrefix(name, "lib") {
name = strings.Replace(name, "lib", "", 1)
libs_cmd += "-l" + name + " "
}

currLDFlags := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS)
ctx.BuildProperties.Set(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS, currLDFlags+"\"-L"+path.String()+"\" "+libs_cmd+" ")
}

currLDFlags := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS)
ctx.BuildProperties.Set(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS, currLDFlags+"\"-L"+path.String()+"\" "+libs_cmd+" ")
}
return nil
}
Expand Down