aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-03-12 20:19:07 +0100
committerRon Evans <[email protected]>2022-03-13 01:08:20 +0100
commite49e93f22cf82f57ecf5e1d0d4d0f580ac17df03 (patch)
treeb76eb1877b0d55d839d4d00164d4f7b84b4d132f /compileopts
parent7d4bf09b1a9f7f268a0bfaed55bf98ebe827bde7 (diff)
downloadtinygo-e49e93f22cf82f57ecf5e1d0d4d0f580ac17df03.tar.gz
tinygo-e49e93f22cf82f57ecf5e1d0d4d0f580ac17df03.zip
main: calculate default output path if -o is not specified
This matches the Go command and is generally convenient to have.
Diffstat (limited to 'compileopts')
-rw-r--r--compileopts/config.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index fa790af61..a06aa8fd2 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -245,6 +245,29 @@ func (c *Config) LibcPath(name string) (path string, precompiled bool) {
return filepath.Join(goenv.Get("GOCACHE"), name+"-"+archname), false
}
+// DefaultBinaryExtension returns the default extension for binaries, such as
+// .exe, .wasm, or no extension (depending on the target).
+func (c *Config) DefaultBinaryExtension() string {
+ parts := strings.Split(c.Triple(), "-")
+ if parts[0] == "wasm32" {
+ // WebAssembly files always have the .wasm file extension.
+ return ".wasm"
+ }
+ if len(parts) >= 3 && parts[2] == "windows" {
+ // Windows uses .exe.
+ return ".exe"
+ }
+ if len(parts) >= 3 && parts[2] == "unknown" {
+ // There appears to be a convention to use the .elf file extension for
+ // ELF files intended for microcontrollers. I'm not aware of the origin
+ // of this, it's just something that is used by many projects.
+ // I think it's a good tradition, so let's keep it.
+ return ".elf"
+ }
+ // Linux, MacOS, etc, don't use a file extension. Use it as a fallback.
+ return ""
+}
+
// CFlags returns the flags to pass to the C compiler. This is necessary for CGo
// preprocessing.
func (c *Config) CFlags() []string {