From a6246e60f3d9bd54095e1a28baca2d799cd1cb15 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 22 Sep 2021 02:44:28 +0200 Subject: [PATCH] main: remove -target flag for LLVM targets It is better to use environment variables (GOOS and GOARCH) for consistency instead of providing two slightly incompatible ways. This -target flag should only be used to specify a .json file (either directly or in the TinyGo targets directory). Previously it was possible to specify the LLVM target as well but that was never really fully supported. So: - To specify a different OS/arch like you would in regular Go, use GOOS and GOARCH. - To specify a microcontroller chip or board, use the -target flag. Also remove the old `os.Setenv` which might have had a purpose long ago but doesn't have a purpose now. --- compileopts/target.go | 41 ++++++++------------------------------ compileopts/target_test.go | 3 ++- main.go | 4 +--- 3 files changed, 11 insertions(+), 37 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go index 7a2bc15f..aaa5fada 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -189,41 +189,16 @@ func LoadTarget(options *Options) (*TargetSpec, error) { // Arduino). spec := &TargetSpec{} err := spec.loadFromGivenStr(options.Target) - if err == nil { - // Successfully loaded this target from a built-in .json file. Make sure - // it includes all parents as specified in the "inherits" key. - err = spec.resolveInherits() - if err != nil { - return nil, err - } - return spec, nil - } else if !os.IsNotExist(err) { - // Expected a 'file not found' error, got something else. Report it as - // an error. + if err != nil { return nil, err - } else { - // Load target from given triple, ignore GOOS/GOARCH environment - // variables. - tripleSplit := strings.Split(options.Target, "-") - if len(tripleSplit) < 3 { - return nil, errors.New("expected a full LLVM target or a custom target in -target flag") - } - goos := tripleSplit[2] - if strings.HasPrefix(goos, "darwin") { - goos = "darwin" - } - goarch := map[string]string{ // map from LLVM arch to Go arch - "i386": "386", - "i686": "386", - "x86_64": "amd64", - "aarch64": "arm64", - "armv7": "arm", - }[tripleSplit[0]] - if goarch == "" { - goarch = tripleSplit[0] - } - return defaultTarget(goos, goarch, strings.Join(tripleSplit, "-")) } + // Successfully loaded this target from a built-in .json file. Make sure + // it includes all parents as specified in the "inherits" key. + err = spec.resolveInherits() + if err != nil { + return nil, err + } + return spec, nil } // WindowsBuildNotSupportedErr is being thrown, when goos is windows and no target has been specified. diff --git a/compileopts/target_test.go b/compileopts/target_test.go index b065258b..11071663 100644 --- a/compileopts/target_test.go +++ b/compileopts/target_test.go @@ -1,6 +1,7 @@ package compileopts import ( + "os" "reflect" "testing" ) @@ -16,7 +17,7 @@ func TestLoadTarget(t *testing.T) { t.Error("LoadTarget should have failed with non existing target") } - if err.Error() != "expected a full LLVM target or a custom target in -target flag" { + if !os.IsNotExist(err) { t.Error("LoadTarget failed for wrong reason:", err) } } diff --git a/main.go b/main.go index 64311424..de148499 100644 --- a/main.go +++ b/main.go @@ -1081,7 +1081,7 @@ func main() { dumpSSA := flag.Bool("dumpssa", false, "dump internal Go SSA") verifyIR := flag.Bool("verifyir", false, "run extra verification steps on LLVM IR") tags := flag.String("tags", "", "a space-separated list of extra build tags") - target := flag.String("target", "", "LLVM target | .json file with TargetSpec") + target := flag.String("target", "", "chip/board name or JSON target specification file") printSize := flag.String("size", "", "print sizes (none, short, full)") printStacks := flag.Bool("print-stacks", false, "print stack sizes of goroutines") printAllocsString := flag.String("print-allocs", "", "regular expression of functions for which heap allocations should be printed") @@ -1173,8 +1173,6 @@ func main() { options.PrintCommands = printCommand } - os.Setenv("CC", "clang -target="+*target) - err = options.Verify() if err != nil { fmt.Fprintln(os.Stderr, err.Error())