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.
Этот коммит содержится в:
		
							родитель
							
								
									d5e11fa19b
								
							
						
					
					
						коммит
						8f8232aada
					
				
					 3 изменённых файлов: 14 добавлений и 11 удалений
				
			
		|  | @ -23,9 +23,7 @@ commands: | ||||||
|                 libclang<<parameters.llvm>>-dev \ |                 libclang<<parameters.llvm>>-dev \ | ||||||
|                 lld<<parameters.llvm>> \ |                 lld<<parameters.llvm>> \ | ||||||
|                 gcc-arm-linux-gnueabihf \ |                 gcc-arm-linux-gnueabihf \ | ||||||
|                 libc6-dev-armel-cross \ |  | ||||||
|                 gcc-aarch64-linux-gnu \ |                 gcc-aarch64-linux-gnu \ | ||||||
|                 libc6-dev-arm64-cross \ |  | ||||||
|                 qemu-system-arm \ |                 qemu-system-arm \ | ||||||
|                 qemu-user \ |                 qemu-user \ | ||||||
|                 gcc-avr \ |                 gcc-avr \ | ||||||
|  |  | ||||||
|  | @ -229,6 +229,14 @@ func LoadTarget(target string) (*TargetSpec, error) { | ||||||
| 		if len(tripleSplit) < 3 { | 		if len(tripleSplit) < 3 { | ||||||
| 			return nil, errors.New("expected a full LLVM target or a custom target in -target flag") | 			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] | 		goos := tripleSplit[2] | ||||||
| 		if strings.HasPrefix(goos, "darwin") { | 		if strings.HasPrefix(goos, "darwin") { | ||||||
| 			goos = "darwin" | 			goos = "darwin" | ||||||
|  | @ -237,11 +245,12 @@ func LoadTarget(target string) (*TargetSpec, error) { | ||||||
| 			"i386":    "386", | 			"i386":    "386", | ||||||
| 			"x86_64":  "amd64", | 			"x86_64":  "amd64", | ||||||
| 			"aarch64": "arm64", | 			"aarch64": "arm64", | ||||||
|  | 			"armv7":   "arm", | ||||||
| 		}[tripleSplit[0]] | 		}[tripleSplit[0]] | ||||||
| 		if goarch == "" { | 		if goarch == "" { | ||||||
| 			goarch = tripleSplit[0] | 			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}, | 		BuildTags:   []string{goos, goarch}, | ||||||
| 		Compiler:    "clang", | 		Compiler:    "clang", | ||||||
| 		Linker:      "cc", | 		Linker:      "cc", | ||||||
|  | 		CFlags:      []string{"--target=" + triple}, | ||||||
| 		GDB:         "gdb", | 		GDB:         "gdb", | ||||||
| 		PortReset:   "false", | 		PortReset:   "false", | ||||||
| 		FlashMethod: "native", | 		FlashMethod: "native", | ||||||
|  | @ -267,11 +277,13 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { | ||||||
| 	if goarch != runtime.GOARCH { | 	if goarch != runtime.GOARCH { | ||||||
| 		// Some educated guesses as to how to invoke helper programs. | 		// Some educated guesses as to how to invoke helper programs. | ||||||
| 		if goarch == "arm" && goos == "linux" { | 		if goarch == "arm" && goos == "linux" { | ||||||
|  | 			spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-gnueabihf") | ||||||
| 			spec.Linker = "arm-linux-gnueabihf-gcc" | 			spec.Linker = "arm-linux-gnueabihf-gcc" | ||||||
| 			spec.GDB = "arm-linux-gnueabihf-gdb" | 			spec.GDB = "arm-linux-gnueabihf-gdb" | ||||||
| 			spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"} | 			spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-gnueabihf"} | ||||||
| 		} | 		} | ||||||
| 		if goarch == "arm64" && goos == "linux" { | 		if goarch == "arm64" && goos == "linux" { | ||||||
|  | 			spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu") | ||||||
| 			spec.Linker = "aarch64-linux-gnu-gcc" | 			spec.Linker = "aarch64-linux-gnu-gcc" | ||||||
| 			spec.GDB = "aarch64-linux-gnu-gdb" | 			spec.GDB = "aarch64-linux-gnu-gdb" | ||||||
| 			spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"} | 			spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"} | ||||||
|  |  | ||||||
|  | @ -80,15 +80,8 @@ func runPlatTests(target string, matches []string, t *testing.T) { | ||||||
| 			if path == filepath.Join("testdata", "gc.go") { | 			if path == filepath.Join("testdata", "gc.go") { | ||||||
| 				continue | 				continue | ||||||
| 			} | 			} | ||||||
| 		case target == "": |  | ||||||
| 			// run all tests on host |  | ||||||
| 		case target == "cortex-m-qemu": |  | ||||||
| 			// all tests are supported |  | ||||||
| 		default: | 		default: | ||||||
| 			// cross-compilation of cgo is not yet supported | 			// all tests are supported | ||||||
| 			if path == filepath.Join("testdata", "cgo")+string(filepath.Separator) { |  | ||||||
| 				continue |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		t.Run(filepath.Base(path), func(t *testing.T) { | 		t.Run(filepath.Base(path), func(t *testing.T) { | ||||||
|  |  | ||||||
		Загрузка…
	
	Создание таблицы
		
		Сослаться в новой задаче
	
	 Ayke van Laethem
						Ayke van Laethem