Skip to content

Commit a96fc7e

Browse files
committed
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)
1 parent 8483cb2 commit a96fc7e

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

Diff for: legacy/builder/phases/libraries_builder.go

+24-26
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)