diff options
author | Ayke van Laethem <[email protected]> | 2024-08-06 12:44:01 +0200 |
---|---|---|
committer | Ayke <[email protected]> | 2024-08-07 14:41:21 +0200 |
commit | fb3d98ce6e6786f7133facbe131374102a6aa375 (patch) | |
tree | 2cf4791961d6b96e3ef2b0af7aca5909e9f3561a /compileopts | |
parent | 020664591ab3a995d6d0aab5097c6fab838a925c (diff) | |
download | tinygo-fb3d98ce6e6786f7133facbe131374102a6aa375.tar.gz tinygo-fb3d98ce6e6786f7133facbe131374102a6aa375.zip |
compileopts: add CanonicalArchName to centralize arch detection
It's possible to detect the architecture from the target triple, but
there are a number of exceptions that make it unpleasant to use for this
purpose. There are just too many weird exceptions (like mips vs mipsel,
and armv6m vs thumv6m vs arm64 vs aarch64) so it's better to centralize
these to canonical architecture names.
I picked the architecture names that happen to match the musl
architecture names, because those seem the most natural to me.
Diffstat (limited to 'compileopts')
-rw-r--r-- | compileopts/config.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/compileopts/config.go b/compileopts/config.go index 893fbf001..a5ab7cd8f 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -207,10 +207,13 @@ func (c *Config) RP2040BootPatch() bool { return false } -// MuslArchitecture returns the architecture name as used in musl libc. It is -// usually the same as the first part of the LLVM triple, but not always. -func MuslArchitecture(triple string) string { +// Return a canonicalized architecture name, so we don't have to deal with arm* +// vs thumb* vs arm64. +func CanonicalArchName(triple string) string { arch := strings.Split(triple, "-")[0] + if arch == "arm64" { + return "aarch64" + } if strings.HasPrefix(arch, "arm") || strings.HasPrefix(arch, "thumb") { return "arm" } @@ -220,6 +223,12 @@ func MuslArchitecture(triple string) string { return arch } +// MuslArchitecture returns the architecture name as used in musl libc. It is +// usually the same as the first part of the LLVM triple, but not always. +func MuslArchitecture(triple string) string { + return CanonicalArchName(triple) +} + // LibcPath returns the path to the libc directory. The libc path will be either // a precompiled libc shipped with a TinyGo build, or a libc path in the cache // directory (which might not yet be built). |