Skip to content

Commit 1830c7f

Browse files
committed
add go-compatibility feature
Signed-off-by: sivchari <shibuuuu5@gmail.com>
1 parent 9be956f commit 1830c7f

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

builder/config.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ func NewConfig(options *compileopts.Options) (*compileopts.Config, error) {
3333
if err != nil {
3434
return nil, err
3535
}
36-
if gorootMajor != 1 || gorootMinor < minorMin || gorootMinor > minorMax {
37-
// Note: when this gets updated, also update the Go compatibility matrix:
38-
// https://github.com/tinygo-org/tinygo-site/blob/dev/content/docs/reference/go-compat-matrix.md
39-
return nil, fmt.Errorf("requires go version 1.%d through 1.%d, got go%d.%d", minorMin, minorMax, gorootMajor, gorootMinor)
36+
37+
if options.GoCompatibility {
38+
if gorootMajor != 1 || gorootMinor < minorMin || gorootMinor > minorMax {
39+
// Note: when this gets updated, also update the Go compatibility matrix:
40+
// https://github.com/tinygo-org/tinygo-site/blob/dev/content/docs/reference/go-compat-matrix.md
41+
return nil, fmt.Errorf("requires go version 1.%d through 1.%d, got go%d.%d", minorMin, minorMax, gorootMajor, gorootMinor)
42+
}
4043
}
4144

4245
// Check that the Go toolchain version isn't too new, if we haven't been

compileopts/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type Options struct {
5959
WITPackage string // pass through to wasm-tools component embed invocation
6060
WITWorld string // pass through to wasm-tools component embed -w option
6161
ExtLDFlags []string
62+
GoCompatibility bool // enable to check for Go version compatibility
6263
}
6364

6465
// Verify performs a validation on the given options, raising an error if options are not valid.

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,7 @@ func main() {
16351635
cpuprofile := flag.String("cpuprofile", "", "cpuprofile output")
16361636
monitor := flag.Bool("monitor", false, "enable serial monitor")
16371637
baudrate := flag.Int("baudrate", 115200, "baudrate of serial monitor")
1638+
gocompatibility := flag.Bool("go-compatibility", true, "enable to check for Go versions compatibility, you can also configure this by setting the TINYGOGOCOMPATIBILITY environment variable")
16381639

16391640
// Internal flags, that are only intended for TinyGo development.
16401641
printIR := flag.Bool("internal-printir", false, "print LLVM IR")
@@ -1712,6 +1713,16 @@ func main() {
17121713
ocdCommands = strings.Split(*ocdCommandsString, ",")
17131714
}
17141715

1716+
val, ok := os.LookupEnv("TINYGOGOCOMPATIBILITY")
1717+
if ok {
1718+
b, err := strconv.ParseBool(val)
1719+
if err != nil {
1720+
fmt.Fprintf(os.Stderr, "could not parse TINYGOGOCOMPATIBILITY value %q: %v\n", val, err)
1721+
os.Exit(1)
1722+
}
1723+
*gocompatibility = b
1724+
}
1725+
17151726
options := &compileopts.Options{
17161727
GOOS: goenv.Get("GOOS"),
17171728
GOARCH: goenv.Get("GOARCH"),
@@ -1748,6 +1759,7 @@ func main() {
17481759
Timeout: *timeout,
17491760
WITPackage: witPackage,
17501761
WITWorld: witWorld,
1762+
GoCompatibility: *gocompatibility,
17511763
}
17521764
if *printCommands {
17531765
options.PrintCommands = printCommand

0 commit comments

Comments
 (0)