Skip to content

Commit fa9deba

Browse files
committed
Added support for "precompiled=full" in library.properties
This flag allow the deployment of a pure precompiled library that ships also the source code of the precompiled part. This allows to possibly compile-from-source as a fallback if the library does not provide a precompiled build for the current architecture. The "precompiled=true" instead has been ported back to the old behaviour (for libraries that ships a precompiled binary and support source code that wraps/uses the precompiled part).
1 parent 7329bc7 commit fa9deba

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

Diff for: arduino/libraries/libraries.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,21 @@ type Library struct {
5555

5656
Types []string `json:"types,omitempty"`
5757

58-
InstallDir *paths.Path
59-
SourceDir *paths.Path
60-
UtilityDir *paths.Path
61-
Location LibraryLocation
62-
ContainerPlatform *cores.PlatformRelease `json:""`
63-
Layout LibraryLayout
64-
RealName string
65-
DotALinkage bool
66-
Precompiled bool
67-
LDflags string
68-
IsLegacy bool
69-
Version *semver.Version
70-
License string
71-
Properties *properties.Map
58+
InstallDir *paths.Path
59+
SourceDir *paths.Path
60+
UtilityDir *paths.Path
61+
Location LibraryLocation
62+
ContainerPlatform *cores.PlatformRelease `json:""`
63+
Layout LibraryLayout
64+
RealName string
65+
DotALinkage bool
66+
Precompiled bool
67+
PrecompiledWithSources bool
68+
LDflags string
69+
IsLegacy bool
70+
Version *semver.Version
71+
License string
72+
Properties *properties.Map
7273
}
7374

7475
func (library *Library) String() string {

Diff for: arduino/libraries/loader.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ func makeNewLibrary(libraryDir *paths.Path, location LibraryLocation) (*Library,
103103
library.Website = strings.TrimSpace(libProperties.Get("url"))
104104
library.IsLegacy = false
105105
library.DotALinkage = libProperties.GetBoolean("dot_a_linkage")
106-
library.Precompiled = libProperties.GetBoolean("precompiled")
106+
library.PrecompiledWithSources = libProperties.Get("precompiled") == "full"
107+
library.Precompiled = libProperties.Get("precompiled") == "true" || library.PrecompiledWithSources
107108
library.LDflags = strings.TrimSpace(libProperties.Get("ldflags"))
108109
library.Properties = libProperties
109110

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

+14-10
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,14 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
135135
objectFiles := paths.NewPathList()
136136

137137
if library.Precompiled {
138-
if precompiledPath := findExpectedPrecompiledLibFolder(ctx, library); precompiledPath != nil {
138+
coreSupportPrecompiled := ctx.BuildProperties.ContainsKey("compiler.libraries.ldflags")
139+
precompiledPath := findExpectedPrecompiledLibFolder(ctx, library)
140+
141+
if !coreSupportPrecompiled {
142+
logger := ctx.GetLogger()
143+
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "The plaform does not support 'compiler.libraries.ldflags' for precompiled libraries.")
144+
145+
} else if precompiledPath != nil {
139146
// Find all libraries in precompiledPath
140147
libs, err := precompiledPath.ReadDir()
141148
if err != nil {
@@ -153,14 +160,8 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
153160
}
154161
}
155162

156-
key := "compiler.libraries.ldflags"
157-
if !ctx.BuildProperties.ContainsKey(key) {
158-
logger := ctx.GetLogger()
159-
logger.Fprintln(os.Stdout, constants.LOG_LEVEL_INFO, "The plaform doesn't support 'compiler.libraries.ldflags' for precompiled libraries... trying with 'compiler.ldflags'.")
160-
key = "compiler.ldflags"
161-
}
162-
currLDFlags := ctx.BuildProperties.Get(key)
163-
ctx.BuildProperties.Set(key, currLDFlags+" \"-L"+precompiledPath.String()+"\" "+libsCmd+" ")
163+
currLDFlags := ctx.BuildProperties.Get("compiler.libraries.ldflags")
164+
ctx.BuildProperties.Set("compiler.libraries.ldflags", currLDFlags+" \"-L"+precompiledPath.String()+"\" "+libsCmd+" ")
164165

165166
// TODO: This codepath is just taken for .a with unusual names that would
166167
// be ignored by -L / -l methods.
@@ -172,7 +173,10 @@ func compileLibrary(ctx *types.Context, library *libraries.Library, buildPath *p
172173
objectFiles.Add(lib)
173174
}
174175
}
175-
return objectFiles, nil
176+
177+
if library.PrecompiledWithSources {
178+
return objectFiles, nil
179+
}
176180
}
177181
}
178182

0 commit comments

Comments
 (0)