diff options
author | Ayke van Laethem <[email protected]> | 2024-02-19 16:32:04 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2024-02-19 17:53:36 +0100 |
commit | d04b07fa8b22f2ce9b88c861159e92054b38125b (patch) | |
tree | 684ef4ed75898575d10f1ff021ac3f468df00f0c | |
parent | 7486277012185e98d3896bfd81271b417ddbb029 (diff) | |
download | tinygo-d04b07fa8b22f2ce9b88c861159e92054b38125b.tar.gz tinygo-d04b07fa8b22f2ce9b88c861159e92054b38125b.zip |
compileopts: always enable CGo
CGo is needed for the rp2040 and for macOS (GOOS=darwin), without it
these targets just won't work. And there really isn't a benefit from
disabling CGo: we don't need any external linkers for example.
This avoids a somewhat common issue of people having CGO_ENABLED=0
somewhere in their environment and not understanding why things don't
work. See for example: https://github.com/tinygo-org/tinygo/issues/3450
-rw-r--r-- | compileopts/config.go | 6 | ||||
-rw-r--r-- | goenv/goenv.go | 7 | ||||
-rw-r--r-- | loader/list.go | 6 |
3 files changed, 3 insertions, 16 deletions
diff --git a/compileopts/config.go b/compileopts/config.go index d5e037042..14d16223c 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -87,12 +87,6 @@ func (c *Config) BuildTags() []string { return tags } -// CgoEnabled returns true if (and only if) CGo is enabled. It is true by -// default and false if CGO_ENABLED is set to "0". -func (c *Config) CgoEnabled() bool { - return goenv.Get("CGO_ENABLED") == "1" -} - // GC returns the garbage collection strategy in use on this platform. Valid // values are "none", "leaking", "conservative" and "precise". func (c *Config) GC() string { diff --git a/goenv/goenv.go b/goenv/goenv.go index 439d4bf1e..be1c631ca 100644 --- a/goenv/goenv.go +++ b/goenv/goenv.go @@ -142,11 +142,8 @@ func Get(name string) string { } return filepath.Join(dir, "tinygo") case "CGO_ENABLED": - val := os.Getenv("CGO_ENABLED") - if val == "1" || val == "0" { - return val - } - // Default to enabling CGo. + // Always enable CGo. It is required by a number of targets, including + // macOS and the rp2040. return "1" case "TINYGOROOT": return sourceDir() diff --git a/loader/list.go b/loader/list.go index 16b674c74..4ab887ab7 100644 --- a/loader/list.go +++ b/loader/list.go @@ -22,12 +22,8 @@ func List(config *compileopts.Config, extraArgs, pkgs []string) (*exec.Cmd, erro args = append(args, "-tags", strings.Join(config.BuildTags(), " ")) } args = append(args, pkgs...) - cgoEnabled := "0" - if config.CgoEnabled() { - cgoEnabled = "1" - } cmd := exec.Command(filepath.Join(goenv.Get("GOROOT"), "bin", "go"), args...) - cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED="+cgoEnabled) + cmd.Env = append(os.Environ(), "GOROOT="+goroot, "GOOS="+config.GOOS(), "GOARCH="+config.GOARCH(), "CGO_ENABLED=1") if config.Options.Directory != "" { cmd.Dir = config.Options.Directory } |