Skip to content

Commit 8f06f7f

Browse files
facchinmcmaglie
authored andcommitted
Fix mixed code precompiled libraries
This patch restores some functionalities broken by arduino#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 * arduino#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)
1 parent 83d7f6e commit 8f06f7f

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

legacy/builder/phases/libraries_builder.go

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (s *LibrariesBuilder) Run(ctx *types.Context) error {
5555
ctx.LibrariesObjectFiles = objectFiles
5656

5757
// Search for precompiled libraries
58-
fixLDFLAGforPrecompiledLibraries(ctx, libs)
58+
fixLDFLAG(ctx, libs)
5959

6060
return nil
6161
}
@@ -109,35 +109,33 @@ func findExpectedPrecompiledLibFolder(ctx *types.Context, library *libraries.Lib
109109
return nil
110110
}
111111

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

114114
for _, library := range libs {
115-
if library.Precompiled {
116-
// add library src path to compiler.c.elf.extra_flags
117-
// use library.Name as lib name and srcPath/{mcpu} as location
118-
path := findExpectedPrecompiledLibFolder(ctx, library)
119-
if path == nil {
120-
break
121-
}
122-
// find all library names in the folder and prepend -l
123-
filePaths := []string{}
124-
libs_cmd := library.LDflags + " "
125-
extensions := func(ext string) bool {
126-
return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC[ext] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext]
127-
}
128-
utils.FindFilesInFolder(&filePaths, path.String(), extensions, false)
129-
for _, lib := range filePaths {
130-
name := strings.TrimSuffix(filepath.Base(lib), filepath.Ext(lib))
131-
// strip "lib" first occurrence
132-
if strings.HasPrefix(name, "lib") {
133-
name = strings.Replace(name, "lib", "", 1)
134-
libs_cmd += "-l" + name + " "
135-
}
115+
// add library src path to compiler.c.elf.extra_flags
116+
// use library.Name as lib name and srcPath/{mcpu} as location
117+
path := findExpectedPrecompiledLibFolder(ctx, library)
118+
if path == nil {
119+
break
120+
}
121+
// find all library names in the folder and prepend -l
122+
filePaths := []string{}
123+
libs_cmd := library.LDflags + " "
124+
extensions := func(ext string) bool {
125+
return PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_DYNAMIC[ext] || PRECOMPILED_LIBRARIES_VALID_EXTENSIONS_STATIC[ext]
126+
}
127+
utils.FindFilesInFolder(&filePaths, path.String(), extensions, false)
128+
for _, lib := range filePaths {
129+
name := strings.TrimSuffix(filepath.Base(lib), filepath.Ext(lib))
130+
// strip "lib" first occurrence
131+
if strings.HasPrefix(name, "lib") {
132+
name = strings.Replace(name, "lib", "", 1)
133+
libs_cmd += "-l" + name + " "
136134
}
137-
138-
currLDFlags := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS)
139-
ctx.BuildProperties.Set(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS, currLDFlags+"\"-L"+path.String()+"\" "+libs_cmd+" ")
140135
}
136+
137+
currLDFlags := ctx.BuildProperties.Get(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS)
138+
ctx.BuildProperties.Set(constants.BUILD_PROPERTIES_COMPILER_LIBRARIES_LDFLAGS, currLDFlags+"\"-L"+path.String()+"\" "+libs_cmd+" ")
141139
}
142140
return nil
143141
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy