@@ -8,12 +8,23 @@ import (
8
8
"os"
9
9
"path/filepath"
10
10
"regexp"
11
+ "strconv"
11
12
"strings"
12
13
13
14
"github.com/google/shlex"
14
15
"github.com/tinygo-org/tinygo/goenv"
15
16
)
16
17
18
+ // Library versions. Whenever an existing library is changed, this number should
19
+ // be added/increased so that existing caches are invalidated.
20
+ //
21
+ // (This is a bit of a layering violation, this should really be part of the
22
+ // builder.Library struct but that's hard to do since we want to know the
23
+ // library path in advance in several places).
24
+ var libVersions = map [string ]int {
25
+ "musl" : 2 ,
26
+ }
27
+
17
28
// Config keeps all configuration affecting the build in a single struct.
18
29
type Config struct {
19
30
Options * Options
@@ -247,9 +258,9 @@ func MuslArchitecture(triple string) string {
247
258
return CanonicalArchName (triple )
248
259
}
249
260
250
- // LibcPath returns the path to the libc directory. The libc path will be a libc
251
- // path in the cache directory (which might not yet be built).
252
- func (c * Config ) LibcPath (name string ) string {
261
+ // LibraryPath returns the path to the library build directory. The path will be
262
+ // a library path in the cache directory (which might not yet be built).
263
+ func (c * Config ) LibraryPath (name string ) string {
253
264
archname := c .Triple ()
254
265
if c .CPU () != "" {
255
266
archname += "-" + c .CPU ()
@@ -265,6 +276,11 @@ func (c *Config) LibcPath(name string) string {
265
276
archname += "-" + c .Target .Libc
266
277
}
267
278
279
+ // Append a version string, if this library has a version.
280
+ if v , ok := libVersions [name ]; ok {
281
+ archname += "-v" + strconv .Itoa (v )
282
+ }
283
+
268
284
// No precompiled library found. Determine the path name that will be used
269
285
// in the build cache.
270
286
return filepath .Join (goenv .Get ("GOCACHE" ), name + "-" + archname )
@@ -351,7 +367,7 @@ func (c *Config) LibcCFlags() []string {
351
367
case "picolibc" :
352
368
root := goenv .Get ("TINYGOROOT" )
353
369
picolibcDir := filepath .Join (root , "lib" , "picolibc" , "newlib" , "libc" )
354
- path := c .LibcPath ("picolibc" )
370
+ path := c .LibraryPath ("picolibc" )
355
371
return []string {
356
372
"-nostdlibinc" ,
357
373
"-isystem" , filepath .Join (path , "include" ),
@@ -361,7 +377,7 @@ func (c *Config) LibcCFlags() []string {
361
377
}
362
378
case "musl" :
363
379
root := goenv .Get ("TINYGOROOT" )
364
- path := c .LibcPath ("musl" )
380
+ path := c .LibraryPath ("musl" )
365
381
arch := MuslArchitecture (c .Triple ())
366
382
return []string {
367
383
"-nostdlibinc" ,
@@ -371,7 +387,7 @@ func (c *Config) LibcCFlags() []string {
371
387
"-isystem" , filepath .Join (root , "lib" , "musl" , "include" ),
372
388
}
373
389
case "wasi-libc" :
374
- path := c .LibcPath ("wasi-libc" )
390
+ path := c .LibraryPath ("wasi-libc" )
375
391
return []string {
376
392
"-nostdlibinc" ,
377
393
"-isystem" , filepath .Join (path , "include" ),
@@ -381,7 +397,7 @@ func (c *Config) LibcCFlags() []string {
381
397
return nil
382
398
case "mingw-w64" :
383
399
root := goenv .Get ("TINYGOROOT" )
384
- path := c .LibcPath ("mingw-w64" )
400
+ path := c .LibraryPath ("mingw-w64" )
385
401
return []string {
386
402
"-nostdlibinc" ,
387
403
"-isystem" , filepath .Join (path , "include" ),
0 commit comments