aboutsummaryrefslogtreecommitdiffhomepage
path: root/goenv
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-11-14 01:39:34 +0100
committerRon Evans <[email protected]>2021-11-15 11:53:44 +0100
commit7cb44fb37324d9d369d04a66bb3a6f43e7c11d0e (patch)
tree99aa7928814b1581a82766bb161a0fd1a484579c /goenv
parent73ad825b67c4ab74f28e42a75782c1c49ba33a88 (diff)
downloadtinygo-7cb44fb37324d9d369d04a66bb3a6f43e7c11d0e.tar.gz
tinygo-7cb44fb37324d9d369d04a66bb3a6f43e7c11d0e.zip
all: add support for GOARM
This environment variable can be set to 5, 6, or 7 and controls which ARM version (ARMv5, ARMv6, ARMv7) is used when compiling for GOARCH=arm. I have picked the default value ARMv6, which I believe is supported on most common single board computers including all Raspberry Pis. The difference in code size is pretty big. We could even go further and support ARMv4 if anybody is interested. It should be pretty simple to add this if needed.
Diffstat (limited to 'goenv')
-rw-r--r--goenv/goenv.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/goenv/goenv.go b/goenv/goenv.go
index 0ef18ba50..6fcd913f4 100644
--- a/goenv/goenv.go
+++ b/goenv/goenv.go
@@ -25,6 +25,12 @@ var Keys = []string{
"TINYGOROOT",
}
+func init() {
+ if Get("GOARCH") == "arm" {
+ Keys = append(Keys, "GOARM")
+ }
+}
+
// TINYGOROOT is the path to the final location for checking tinygo files. If
// unset (by a -X ldflag), then sourceDir() will fallback to the original build
// directory.
@@ -44,6 +50,20 @@ func Get(name string) string {
return dir
}
return runtime.GOARCH
+ case "GOARM":
+ if goarm := os.Getenv("GOARM"); goarm != "" {
+ return goarm
+ }
+ if goos := Get("GOOS"); goos == "windows" || goos == "android" {
+ // Assume Windows and Android are running on modern CPU cores.
+ // This matches upstream Go.
+ return "7"
+ }
+ // Default to ARMv6 on other devices.
+ // The difference between ARMv5 and ARMv6 is big, much bigger than the
+ // difference between ARMv6 and ARMv7. ARMv6 binaries are much smaller,
+ // especially when floating point instructions are involved.
+ return "6"
case "GOROOT":
return getGoroot()
case "GOPATH":