@@ -8,12 +8,23 @@ import (
88 "os"
99 "path/filepath"
1010 "regexp"
11+ "strconv"
1112 "strings"
1213
1314 "github.com/google/shlex"
1415 "github.com/tinygo-org/tinygo/goenv"
1516)
1617
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+
1728// Config keeps all configuration affecting the build in a single struct.
1829type Config struct {
1930 Options * Options
@@ -247,9 +258,9 @@ func MuslArchitecture(triple string) string {
247258 return CanonicalArchName (triple )
248259}
249260
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 {
253264 archname := c .Triple ()
254265 if c .CPU () != "" {
255266 archname += "-" + c .CPU ()
@@ -265,6 +276,11 @@ func (c *Config) LibcPath(name string) string {
265276 archname += "-" + c .Target .Libc
266277 }
267278
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+
268284 // No precompiled library found. Determine the path name that will be used
269285 // in the build cache.
270286 return filepath .Join (goenv .Get ("GOCACHE" ), name + "-" + archname )
@@ -351,7 +367,7 @@ func (c *Config) LibcCFlags() []string {
351367 case "picolibc" :
352368 root := goenv .Get ("TINYGOROOT" )
353369 picolibcDir := filepath .Join (root , "lib" , "picolibc" , "newlib" , "libc" )
354- path := c .LibcPath ("picolibc" )
370+ path := c .LibraryPath ("picolibc" )
355371 return []string {
356372 "-nostdlibinc" ,
357373 "-isystem" , filepath .Join (path , "include" ),
@@ -361,7 +377,7 @@ func (c *Config) LibcCFlags() []string {
361377 }
362378 case "musl" :
363379 root := goenv .Get ("TINYGOROOT" )
364- path := c .LibcPath ("musl" )
380+ path := c .LibraryPath ("musl" )
365381 arch := MuslArchitecture (c .Triple ())
366382 return []string {
367383 "-nostdlibinc" ,
@@ -371,7 +387,7 @@ func (c *Config) LibcCFlags() []string {
371387 "-isystem" , filepath .Join (root , "lib" , "musl" , "include" ),
372388 }
373389 case "wasi-libc" :
374- path := c .LibcPath ("wasi-libc" )
390+ path := c .LibraryPath ("wasi-libc" )
375391 return []string {
376392 "-nostdlibinc" ,
377393 "-isystem" , filepath .Join (path , "include" ),
@@ -381,7 +397,7 @@ func (c *Config) LibcCFlags() []string {
381397 return nil
382398 case "mingw-w64" :
383399 root := goenv .Get ("TINYGOROOT" )
384- path := c .LibcPath ("mingw-w64" )
400+ path := c .LibraryPath ("mingw-w64" )
385401 return []string {
386402 "-nostdlibinc" ,
387403 "-isystem" , filepath .Join (path , "include" ),
0 commit comments