Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate big-go version tags functionality [ fix #4391 ] #4389

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions compileopts/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions goenv/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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" {
Expand Down Expand Up @@ -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)
Expand Down
Loading