diff --git a/builder/config.go b/builder/config.go index a82450a638..5cb0bad86f 100644 --- a/builder/config.go +++ b/builder/config.go @@ -33,10 +33,15 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) { return nil, fmt.Errorf("requires go version 1.19 through 1.22, got go%d.%d", major, minor) } + // tinygo major / minor version + tgMajor, tgMinor := goenv.GetVersion() + return &compileopts.Config{ Options: options, Target: spec, GoMinorVersion: minor, TestConfig: options.TestConfig, + VersionMajor: tgMajor, + VersionMinor: tgMinor, }, nil } diff --git a/compileopts/config.go b/compileopts/config.go index a5ab7cd8f9..504b7d1ac0 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -20,6 +20,10 @@ type Config struct { Target *TargetSpec GoMinorVersion int TestConfig TestConfig + + // tinygo versions + VersionMajor int + VersionMinor int } // Triple returns the LLVM target triple, like armv6m-unknown-unknown-eabi. @@ -81,9 +85,19 @@ func (c *Config) BuildTags() []string { "math_big_pure_go", // to get math/big to work "gc." + c.GC(), "scheduler." + c.Scheduler(), // used inside the runtime package "serial." + c.Serial()}...) // used inside the machine package + + // Go Version tags for i := 1; i <= c.GoMinorVersion; i++ { tags = append(tags, fmt.Sprintf("go1.%d", i)) } + + // tinygo Version tags + for i := 0; i <= c.VersionMajor; i++ { + for j := 1; j <= c.VersionMinor; j++ { + tags = append(tags, fmt.Sprintf("tinygo%d.%d", i, j)) + } + } + tags = append(tags, c.Options.Tags...) return tags } diff --git a/goenv/version.go b/goenv/version.go index bed4e26f34..b54c146256 100644 --- a/goenv/version.go +++ b/goenv/version.go @@ -27,6 +27,13 @@ func Version() string { return v } +// Return version as major / minor +func GetVersion() (major, minor int) { + // version must be + fmt.Sscanf(version, "%d.%d", &major, &minor) + return +} + // GetGorootVersion returns the major and minor version for a given GOROOT path. // If the goroot cannot be determined, (0, 0) is returned. func GetGorootVersion() (major, minor int, err error) { diff --git a/main.go b/main.go index c90bf7e69a..95b40a3cef 100644 --- a/main.go +++ b/main.go @@ -1428,7 +1428,7 @@ func main() { // development it can be useful to not emit debug information at all. skipDwarf := flag.Bool("internal-nodwarf", false, "internal flag, use -no-debug instead") - var flagJSON, flagDeps, flagTest bool + var flagJSON, flagDeps, flagTest, flagFull bool if command == "help" || command == "list" || command == "info" || command == "build" { flag.BoolVar(&flagJSON, "json", false, "print data in JSON format") } @@ -1440,6 +1440,9 @@ func main() { if command == "help" || command == "build" || command == "test" { flag.StringVar(&outpath, "o", "", "output filename") } + if command == "info" { + flag.BoolVar(&flagFull, "full", false, "output all tinygo version build-tags") + } var witPackage, witWorld string if command == "help" || command == "build" || command == "test" || command == "run" { @@ -1720,6 +1723,12 @@ func main() { os.Exit(1) } config.GoMinorVersion = 0 // this avoids creating the list of Go1.x build tags. + if !flagFull { + // avoid creating tinygoX.X build tags + config.VersionMinor = 0 + config.VersionMajor = 0 + } + if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1)