diff options
author | Ayke van Laethem <[email protected]> | 2020-01-14 13:46:54 +0100 |
---|---|---|
committer | Ron Evans <[email protected]> | 2020-01-20 20:30:42 +0100 |
commit | 8f8232aada70f3f939f1d18cedad0d6cc3b4db31 (patch) | |
tree | 6e2d1a0eeea3b995d4d6dcb08b1b0cd3b74e3235 | |
parent | d5e11fa19b6b4ef53f2c5106c1c1c6d8e50358b3 (diff) | |
download | tinygo-8f8232aada70f3f939f1d18cedad0d6cc3b4db31.tar.gz tinygo-8f8232aada70f3f939f1d18cedad0d6cc3b4db31.zip |
compileopts: fix CGo when cross compiling
Use the cross compiling toolchains for compiling/linking. This fixes CGo
support, and therefore allows CGo to be used when cross compiling to
Linux on a different architecture.
This commit also removes some redundant testing code.
-rw-r--r-- | .circleci/config.yml | 2 | ||||
-rw-r--r-- | compileopts/target.go | 14 | ||||
-rw-r--r-- | main_test.go | 9 |
3 files changed, 14 insertions, 11 deletions
diff --git a/.circleci/config.yml b/.circleci/config.yml index dcd33dd5c..8b3915d07 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -23,9 +23,7 @@ commands: libclang<<parameters.llvm>>-dev \ lld<<parameters.llvm>> \ gcc-arm-linux-gnueabihf \ - libc6-dev-armel-cross \ gcc-aarch64-linux-gnu \ - libc6-dev-arm64-cross \ qemu-system-arm \ qemu-user \ gcc-avr \ diff --git a/compileopts/target.go b/compileopts/target.go index 949f00e47..637712c83 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -229,6 +229,14 @@ func LoadTarget(target string) (*TargetSpec, error) { if len(tripleSplit) < 3 { return nil, errors.New("expected a full LLVM target or a custom target in -target flag") } + if tripleSplit[0] == "arm" { + // LLVM and Clang have a different idea of what "arm" means, so + // upgrade to a slightly more modern ARM. In fact, when you pass + // --target=arm--linux-gnueabihf to Clang, it will convert that + // internally to armv7-unknown-linux-gnueabihf. Changing the + // architecture to armv7 will keep things consistent. + tripleSplit[0] = "armv7" + } goos := tripleSplit[2] if strings.HasPrefix(goos, "darwin") { goos = "darwin" @@ -237,11 +245,12 @@ func LoadTarget(target string) (*TargetSpec, error) { "i386": "386", "x86_64": "amd64", "aarch64": "arm64", + "armv7": "arm", }[tripleSplit[0]] if goarch == "" { goarch = tripleSplit[0] } - return defaultTarget(goos, goarch, target) + return defaultTarget(goos, goarch, strings.Join(tripleSplit, "-")) } } @@ -255,6 +264,7 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { BuildTags: []string{goos, goarch}, Compiler: "clang", Linker: "cc", + CFlags: []string{"--target=" + triple}, GDB: "gdb", PortReset: "false", FlashMethod: "native", @@ -267,11 +277,13 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { if goarch != runtime.GOARCH { // Some educated guesses as to how to invoke helper programs. if goarch == "arm" && goos == "linux" { + spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") spec.Linker = "arm-linux-gnueabihf-gcc" spec.GDB = "arm-linux-gnueabihf-gdb" spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"} } if goarch == "arm64" && goos == "linux" { + spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu") spec.Linker = "aarch64-linux-gnu-gcc" spec.GDB = "aarch64-linux-gnu-gdb" spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"} diff --git a/main_test.go b/main_test.go index 188f318e8..3287025fc 100644 --- a/main_test.go +++ b/main_test.go @@ -80,15 +80,8 @@ func runPlatTests(target string, matches []string, t *testing.T) { if path == filepath.Join("testdata", "gc.go") { continue } - case target == "": - // run all tests on host - case target == "cortex-m-qemu": - // all tests are supported default: - // cross-compilation of cgo is not yet supported - if path == filepath.Join("testdata", "cgo")+string(filepath.Separator) { - continue - } + // all tests are supported } t.Run(filepath.Base(path), func(t *testing.T) { |