From 05d2f2c412c351d1262094bf5f75d55eb9b2fbde Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Wed, 23 Sep 2020 17:26:43 +0200 Subject: [PATCH] main: improve support for x86-32 and add tests To avoid breaking this, make sure we actually test x86-32 (aka i386 aka GOARCH=386) support in CI. Also remove the now-unnecessary binutils-arm-none-eabi package to speed up CI a bit. --- .circleci/config.yml | 5 +++-- compileopts/target.go | 7 ++++--- main_test.go | 10 +++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 15ca09e0..aa475a46 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -28,6 +28,7 @@ commands: qemu-user \ gcc-avr \ avr-libc + sudo apt-get install --no-install-recommends libc6-dev-i386 lib32gcc-8-dev install-node: steps: - run: @@ -133,7 +134,6 @@ commands: command: | sudo apt-get install \ gcc-arm-linux-gnueabihf \ - binutils-arm-none-eabi \ libc6-dev-armel-cross \ gcc-aarch64-linux-gnu \ libc6-dev-arm64-cross \ @@ -141,6 +141,7 @@ commands: qemu-user \ gcc-avr \ avr-libc + sudo apt-get install --no-install-recommends libc6-dev-i386 lib32gcc-6-dev - install-node - install-wasmtime - install-xtensa-toolchain: @@ -194,7 +195,6 @@ commands: command: | sudo apt-get install \ gcc-arm-linux-gnueabihf \ - binutils-arm-none-eabi \ libc6-dev-armel-cross \ gcc-aarch64-linux-gnu \ libc6-dev-arm64-cross \ @@ -202,6 +202,7 @@ commands: qemu-user \ gcc-avr \ avr-libc + sudo apt-get install --no-install-recommends libc6-dev-i386 lib32gcc-6-dev - install-node - install-wasmtime - install-xtensa-toolchain: diff --git a/compileopts/target.go b/compileopts/target.go index f95ecfd8..89e40252 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -215,6 +215,7 @@ func LoadTarget(target string) (*TargetSpec, error) { } goarch := map[string]string{ // map from LLVM arch to Go arch "i386": "386", + "i686": "386", "x86_64": "amd64", "aarch64": "arm64", "armv7": "arm", @@ -260,9 +261,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { spec.GDB = "aarch64-linux-gnu-gdb" spec.Emulator = []string{"qemu-aarch64", "-L", "/usr/aarch64-linux-gnu"} } - if goarch == "386" { - spec.CFlags = []string{"-m32"} - spec.LDFlags = []string{"-m32"} + if goarch == "386" && runtime.GOARCH == "amd64" { + spec.CFlags = append(spec.CFlags, "-m32") + spec.LDFlags = append(spec.LDFlags, "-m32") } } return &spec, nil diff --git a/main_test.go b/main_test.go index ac01baaf..09c3919e 100644 --- a/main_test.go +++ b/main_test.go @@ -78,6 +78,9 @@ func TestCompiler(t *testing.T) { } if runtime.GOOS == "linux" { + t.Run("X86Linux", func(t *testing.T) { + runPlatTests("i386--linux-gnu", matches, t) + }) t.Run("ARMLinux", func(t *testing.T) { runPlatTests("arm--linux-gnueabihf", matches, t) }) @@ -189,10 +192,11 @@ func runTest(path, target string, t *testing.T) { t.Fatal("failed to load target spec:", err) } if len(spec.Emulator) == 0 { - t.Fatal("no emulator available for target:", target) + cmd = exec.Command(binary) + } else { + args := append(spec.Emulator[1:], binary) + cmd = exec.Command(spec.Emulator[0], args...) } - args := append(spec.Emulator[1:], binary) - cmd = exec.Command(spec.Emulator[0], args...) } stdout := &bytes.Buffer{} cmd.Stdout = stdout