diff --git a/.gitignore b/.gitignore index 7b822bc..213c4e6 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ /tinygo-0.14.0.tar.gz /tinygo-0.14.1.tar.gz /tinygo-0.15.0.tar.gz +/tinygo-0.16.0.tar.gz diff --git a/0001-Use-Fedora-command-names.patch b/0001-Use-Fedora-command-names.patch index 350c952..ac2d474 100644 --- a/0001-Use-Fedora-command-names.patch +++ b/0001-Use-Fedora-command-names.patch @@ -1,19 +1,19 @@ -From 845a1e4c9d7456d2a914e540ad6c8a7f9d684aa6 Mon Sep 17 00:00:00 2001 +From d12f535f6e41d821d7ddb3f24677ce2b071ba590 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 7 Jun 2019 20:55:25 -0400 -Subject: [PATCH 1/6] Use Fedora command names. +Subject: [PATCH 1/4] Use Fedora command names. Signed-off-by: Elliott Sales de Andrade --- - compileopts/target.go | 10 +++++----- - main_test.go | 2 +- - 2 files changed, 6 insertions(+), 6 deletions(-) + compileopts/target.go | 8 ++++---- + main_test.go | 2 +- + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compileopts/target.go b/compileopts/target.go -index 6547320..d7f8390 100644 +index 8b3c68f..53b3b61 100644 --- a/compileopts/target.go +++ b/compileopts/target.go -@@ -226,7 +226,7 @@ func LoadTarget(target string) (*TargetSpec, error) { +@@ -174,7 +174,7 @@ func LoadTarget(target string) (*TargetSpec, error) { } target = llvmarch + "--" + llvmos if goarch == "arm" { @@ -22,28 +22,26 @@ index 6547320..d7f8390 100644 } return defaultTarget(goos, goarch, target) } -@@ -302,10 +302,10 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { - if goarch != runtime.GOARCH { +@@ -254,9 +254,9 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { // Some educated guesses as to how to invoke helper programs. + spec.GDB = "gdb-multiarch" 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"} + spec.CFlags = append(spec.CFlags, "--sysroot=/usr/arm-linux-none") + spec.Linker = "arm-linux-gnu-gcc" -+ spec.GDB = "arm-linux-gnu-gdb" + spec.Emulator = []string{"qemu-arm", "-L", "/usr/arm-linux-none"} } if goarch == "arm64" && goos == "linux" { spec.CFlags = append(spec.CFlags, "--sysroot=/usr/aarch64-linux-gnu") diff --git a/main_test.go b/main_test.go -index f66117b..3c31e21 100644 +index a7eca14..f8285a2 100644 --- a/main_test.go +++ b/main_test.go -@@ -79,7 +79,7 @@ func TestCompiler(t *testing.T) { - - if runtime.GOOS == "linux" { +@@ -82,7 +82,7 @@ func TestCompiler(t *testing.T) { + runPlatTests("i386--linux-gnu", matches, t) + }) t.Run("ARMLinux", func(t *testing.T) { - runPlatTests("arm--linux-gnueabihf", matches, t) + runPlatTests("arm--linux-none", matches, t) @@ -51,5 +49,5 @@ index f66117b..3c31e21 100644 t.Run("ARM64Linux", func(t *testing.T) { runPlatTests("aarch64--linux-gnu", matches, t) -- -2.26.2 +2.29.2 diff --git a/0002-Skip-ARM-Linux-tests.patch b/0002-Skip-ARM-Linux-tests.patch index a2c3dd3..347c576 100644 --- a/0002-Skip-ARM-Linux-tests.patch +++ b/0002-Skip-ARM-Linux-tests.patch @@ -1,7 +1,7 @@ -From 483c57eee834fb9cf19426d35f31cdb21a94044f Mon Sep 17 00:00:00 2001 +From af52d3bdf25e9f318003c4fc39845fc3e9257a43 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 12 Jun 2019 04:28:55 -0400 -Subject: [PATCH 2/6] Skip ARM Linux tests. +Subject: [PATCH 2/4] Skip ARM Linux tests. We don't have the C library to do this. @@ -11,13 +11,13 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 6 deletions(-) diff --git a/main_test.go b/main_test.go -index 3c31e21..47a0e6b 100644 +index f8285a2..efeb2db 100644 --- a/main_test.go +++ b/main_test.go -@@ -78,12 +78,6 @@ func TestCompiler(t *testing.T) { - } - - if runtime.GOOS == "linux" { +@@ -81,12 +81,6 @@ func TestCompiler(t *testing.T) { + t.Run("X86Linux", func(t *testing.T) { + runPlatTests("i386--linux-gnu", matches, t) + }) - t.Run("ARMLinux", func(t *testing.T) { - runPlatTests("arm--linux-none", matches, t) - }) @@ -28,5 +28,5 @@ index 3c31e21..47a0e6b 100644 if err != nil { t.Error("could not get Go version:", err) -- -2.26.2 +2.29.2 diff --git a/0003-Skip-STM32-tests.patch b/0003-Skip-STM32-tests.patch index 4449028..bdd50fe 100644 --- a/0003-Skip-STM32-tests.patch +++ b/0003-Skip-STM32-tests.patch @@ -1,7 +1,7 @@ -From b93a578d1ca1538ada696ccb6d75f4c8c7858b14 Mon Sep 17 00:00:00 2001 +From 307770eb5da848e0f62fc8d02ff51b5ea8767bb7 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 13 Jun 2019 02:50:40 -0400 -Subject: [PATCH 3/6] Skip STM32 tests. +Subject: [PATCH 3/4] Skip STM32 tests. We can't ship the STM32 .svd files due to their odd license. @@ -11,10 +11,10 @@ Signed-off-by: Elliott Sales de Andrade 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/Makefile b/Makefile -index e59799c..9e6b571 100644 +index 660975e..ae41b06 100644 --- a/Makefile +++ b/Makefile -@@ -118,7 +118,7 @@ fmt-check: +@@ -103,7 +103,7 @@ fmt-check: @unformatted=$$(gofmt -l $(FMT_PATHS)); [ -z "$$unformatted" ] && exit 0; echo "Unformatted:"; for fn in $$unformatted; do echo " $$fn"; done; exit 1 @@ -23,7 +23,7 @@ index e59799c..9e6b571 100644 gen-device-avr: @if [ ! -e lib/avr/README.md ]; then echo "Submodules have not been downloaded. Please download them using:\n git submodule update --init"; exit 1; fi -@@ -257,8 +257,6 @@ smoketest: +@@ -249,8 +249,6 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=pca10031 examples/blinky1 @$(MD5SUM) test.hex @@ -32,7 +32,7 @@ index e59799c..9e6b571 100644 $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky1 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=reelboard examples/blinky2 -@@ -275,14 +273,6 @@ smoketest: +@@ -267,14 +265,6 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/blinky1 @$(MD5SUM) test.hex @@ -47,7 +47,7 @@ index e59799c..9e6b571 100644 $(TINYGO) build -size short -o test.hex -target=circuitplay-bluefruit examples/blinky1 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=circuitplay-express examples/i2s -@@ -307,8 +297,6 @@ smoketest: +@@ -299,8 +289,6 @@ smoketest: @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=particle-xenon examples/blinky1 @$(MD5SUM) test.hex @@ -57,5 +57,5 @@ index e59799c..9e6b571 100644 @$(MD5SUM) test.hex $(TINYGO) build -size short -o test.hex -target=x9pro examples/blinky1 -- -2.26.2 +2.29.2 diff --git a/0004-Also-check-lib64-for-clang-include-path.patch b/0004-Also-check-lib64-for-clang-include-path.patch deleted file mode 100644 index 3e1972f..0000000 --- a/0004-Also-check-lib64-for-clang-include-path.patch +++ /dev/null @@ -1,45 +0,0 @@ -From 22bbf4dc4f002d1a9178d45f92e5f81bac8593a4 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sat, 19 Sep 2020 23:11:08 -0400 -Subject: [PATCH 4/6] Also check lib64 for clang include path. - -On 64-bit Fedora, `lib64` is where the clang headers are, not `lib`. For -multiarch systems, both will exist, but it's likely you want 64-bit, so -check that first. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/env.go | 14 ++++++++++---- - 1 file changed, 10 insertions(+), 4 deletions(-) - -diff --git a/builder/env.go b/builder/env.go -index c59f5df..91bc263 100644 ---- a/builder/env.go -+++ b/builder/env.go -@@ -40,13 +40,19 @@ func getClangHeaderPath(TINYGOROOT string) string { - // Example executable: - // /usr/lib/llvm-9/bin/clang - // Example include path: -- // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -+ // /usr/lib/llvm-9/lib64/clang/9.0.1/include/ - llvmRoot := filepath.Dir(filepath.Dir(binpath)) -- clangVersionRoot := filepath.Join(llvmRoot, "lib", "clang") -+ clangVersionRoot := filepath.Join(llvmRoot, "lib64", "clang") - dirs, err := ioutil.ReadDir(clangVersionRoot) - if err != nil { -- // Unexpected. -- continue -+ // Example include path: -+ // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -+ clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") -+ dirs, err = ioutil.ReadDir(clangVersionRoot) -+ if err != nil { -+ // Unexpected. -+ continue -+ } - } - dirnames := make([]string, len(dirs)) - for i, d := range dirs { --- -2.26.2 - diff --git a/0004-Skip-WASI-tests.patch b/0004-Skip-WASI-tests.patch new file mode 100644 index 0000000..feaaf83 --- /dev/null +++ b/0004-Skip-WASI-tests.patch @@ -0,0 +1,30 @@ +From 82d01abd2fe82e0e19678721388d4068fe0de7d0 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Tue, 15 Dec 2020 05:06:04 -0500 +Subject: [PATCH 4/4] Skip WASI tests. + +We do not have wasmtime available. + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 4 ---- + 1 file changed, 4 deletions(-) + +diff --git a/main_test.go b/main_test.go +index efeb2db..d2cbba3 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -95,10 +95,6 @@ func TestCompiler(t *testing.T) { + runPlatTests("wasm", matches, t) + }) + } +- +- t.Run("WASI", func(t *testing.T) { +- runPlatTests("wasi", matches, t) +- }) + } + } + +-- +2.29.2 + diff --git a/0005-main-add-initial-support-for-in-development-LLVM-11.patch b/0005-main-add-initial-support-for-in-development-LLVM-11.patch deleted file mode 100644 index 495b8b0..0000000 --- a/0005-main-add-initial-support-for-in-development-LLVM-11.patch +++ /dev/null @@ -1,270 +0,0 @@ -From 91f8baf2d104ab29ff11e62bde456899083db319 Mon Sep 17 00:00:00 2001 -From: Ayke van Laethem -Date: Tue, 14 Apr 2020 22:43:32 +0200 -Subject: [PATCH 5/6] main: add initial support for (in-development) LLVM 11 - -This can be useful to test improvements in LLVM master and to make it -possible to support LLVM 11 for the most part already before the next -release. That also allows catching LLVM bugs early to fix them upstream. - -Note that tests do not yet pass for this LLVM version, but the TinyGo -compiler can be built with the binaries from apt.llvm.org (at the time -of making this commit). - -Signed-off-by: Elliott Sales de Andrade ---- - builder/build.go | 11 +++++++++++ - builder/objcopy.go | 8 +++++++- - cgo/libclang_config.go | 2 +- - cgo/libclang_config_llvm11.go | 14 ++++++++++++++ - go.mod | 2 +- - go.sum | 4 ++-- - interp/interp_test.go | 17 +++++++++++++++-- - targets/gameboy-advance.ld | 7 ++++--- - transform/globals.go | 14 ++++++++++++++ - transform/transform_test.go | 16 ++++++++++++++-- - 10 files changed, 83 insertions(+), 12 deletions(-) - create mode 100644 cgo/libclang_config_llvm11.go - -diff --git a/builder/build.go b/builder/build.go -index 67c09df..e59fec4 100644 ---- a/builder/build.go -+++ b/builder/build.go -@@ -129,6 +129,17 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil - } - } - -+ // LLVM 11 by default tries to emit tail calls (even with the target feature -+ // disabled) unless it is explicitly disabled with a function attribute. -+ // This is a problem, as it tries to emit them and prints an error when it -+ // can't with this feature disabled. -+ // Because as of september 2020 tail calls are not yet widely supported, -+ // they need to be disabled until they are widely supported (at which point -+ // the +tail-call target feautre can be set). -+ if strings.HasPrefix(config.Triple(), "wasm") { -+ transform.DisableTailCalls(mod) -+ } -+ - // Make sure stack sizes are loaded from a separate section so they can be - // modified after linking. - var stackSizeLoads []string -diff --git a/builder/objcopy.go b/builder/objcopy.go -index a8a76af..991bceb 100644 ---- a/builder/objcopy.go -+++ b/builder/objcopy.go -@@ -61,7 +61,7 @@ func extractROM(path string) (uint64, []byte, error) { - - progs := make(progSlice, 0, 2) - for _, prog := range f.Progs { -- if prog.Type != elf.PT_LOAD || prog.Filesz == 0 { -+ if prog.Type != elf.PT_LOAD || prog.Filesz == 0 || prog.Off == 0 { - continue - } - progs = append(progs, prog) -@@ -73,6 +73,12 @@ func extractROM(path string) (uint64, []byte, error) { - - var rom []byte - for _, prog := range progs { -+ romEnd := progs[0].Paddr + uint64(len(rom)) -+ if prog.Paddr > romEnd && prog.Paddr < romEnd+16 { -+ // Sometimes, the linker seems to insert a bit of padding between -+ // segments. Simply zero-fill these parts. -+ rom = append(rom, make([]byte, prog.Paddr-romEnd)...) -+ } - if prog.Paddr != progs[0].Paddr+uint64(len(rom)) { - diff := prog.Paddr - (progs[0].Paddr + uint64(len(rom))) - if diff > maxPadBytes { -diff --git a/cgo/libclang_config.go b/cgo/libclang_config.go -index ec65d8a..24b9501 100644 ---- a/cgo/libclang_config.go -+++ b/cgo/libclang_config.go -@@ -1,5 +1,5 @@ - // +build !byollvm --// +build !llvm9 -+// +build !llvm9,!llvm11 - - package cgo - -diff --git a/cgo/libclang_config_llvm11.go b/cgo/libclang_config_llvm11.go -new file mode 100644 -index 0000000..6fab82b ---- /dev/null -+++ b/cgo/libclang_config_llvm11.go -@@ -0,0 +1,14 @@ -+// +build !byollvm -+// +build llvm11 -+ -+package cgo -+ -+/* -+#cgo linux CFLAGS: -I/usr/lib/llvm-11/include -+#cgo darwin CFLAGS: -I/usr/local/opt/llvm@11/include -+#cgo freebsd CFLAGS: -I/usr/local/llvm11/include -+#cgo linux LDFLAGS: -L/usr/lib/llvm-11/lib -lclang -+#cgo darwin LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi -+#cgo freebsd LDFLAGS: -L/usr/local/llvm11/lib -lclang -+*/ -+import "C" -diff --git a/go.mod b/go.mod -index 6887936..98a2ab9 100644 ---- a/go.mod -+++ b/go.mod -@@ -10,5 +10,5 @@ require ( - github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 - go.bug.st/serial v1.0.0 - golang.org/x/tools v0.0.0-20200216192241-b320d3a0f5a2 -- tinygo.org/x/go-llvm v0.0.0-20200503225853-345b2947b59d -+ tinygo.org/x/go-llvm v0.0.0-20200503224449-70c558526021 - ) -diff --git a/go.sum b/go.sum -index c24491e..9ceebac 100644 ---- a/go.sum -+++ b/go.sum -@@ -46,5 +46,5 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbO - golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= - gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= - gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= --tinygo.org/x/go-llvm v0.0.0-20200503225853-345b2947b59d h1:hcX7vpB067GWM/EH4sGGOti0PMgIx+0bbZwUXctOIvE= --tinygo.org/x/go-llvm v0.0.0-20200503225853-345b2947b59d/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= -+tinygo.org/x/go-llvm v0.0.0-20200503224449-70c558526021 h1:d8T98WXGjrTgDmMXgxa6nb9EAYXGXwnzXygnJl6d+ac= -+tinygo.org/x/go-llvm v0.0.0-20200503224449-70c558526021/go.mod h1:fv1F0BSNpxMfCL0zF3M4OPFbgYHnhtB6ST0HvUtu/LE= -diff --git a/interp/interp_test.go b/interp/interp_test.go -index 6b0cc38..dba7387 100644 ---- a/interp/interp_test.go -+++ b/interp/interp_test.go -@@ -3,6 +3,7 @@ package interp - import ( - "io/ioutil" - "os" -+ "regexp" - "strings" - "testing" - -@@ -66,6 +67,8 @@ func runTest(t *testing.T, pathPrefix string) { - } - } - -+var alignRegexp = regexp.MustCompile(", align [0-9]+$") -+ - // fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly - // equal. That means, only relevant lines are compared (excluding comments - // etc.). -@@ -75,8 +78,18 @@ func fuzzyEqualIR(s1, s2 string) bool { - if len(lines1) != len(lines2) { - return false - } -- for i, line := range lines1 { -- if line != lines2[i] { -+ for i, line1 := range lines1 { -+ line2 := lines2[i] -+ match1 := alignRegexp.MatchString(line1) -+ match2 := alignRegexp.MatchString(line2) -+ if match1 != match2 { -+ // Only one of the lines has the align keyword. Remove it. -+ // This is a change to make the test work in both LLVM 10 and LLVM -+ // 11 (LLVM 11 appears to automatically add alignment everywhere). -+ line1 = alignRegexp.ReplaceAllString(line1, "") -+ line2 = alignRegexp.ReplaceAllString(line2, "") -+ } -+ if line1 != line2 { - return false - } - } -diff --git a/targets/gameboy-advance.ld b/targets/gameboy-advance.ld -index 8b35042..566f78e 100644 ---- a/targets/gameboy-advance.ld -+++ b/targets/gameboy-advance.ld -@@ -19,6 +19,7 @@ SECTIONS - { - KEEP (*(.init)) - *(.text) -+ *(.text.*) - . = ALIGN(4); - } >rom - -@@ -26,7 +27,7 @@ SECTIONS - { - . = ALIGN(4); - *(.rodata) -- *(.rodata*) -+ *(.rodata.*) - . = ALIGN(4); - } >rom - -@@ -51,7 +52,7 @@ SECTIONS - . = ALIGN(4); - _sdata = .; /* used by startup code */ - *(.data) -- *(.data*) -+ *(.data.*) - *(.iwram .iwram.*) - . = ALIGN(4); - _edata = .; /* used by startup code */ -@@ -63,7 +64,7 @@ SECTIONS - . = ALIGN(4); - _sbss = .; /* used by startup code */ - *(.bss) -- *(.bss*) -+ *(.bss.*) - *(COMMON) - . = ALIGN(4); - _ebss = .; /* used by startup code */ -diff --git a/transform/globals.go b/transform/globals.go -index 89386fd..7a29683 100644 ---- a/transform/globals.go -+++ b/transform/globals.go -@@ -31,3 +31,17 @@ func NonConstGlobals(mod llvm.Module) { - global = llvm.NextGlobal(global) - } - } -+ -+// DisableTailCalls adds the "disable-tail-calls"="true" function attribute to -+// all functions. This may be necessary, in particular to avoid an error with -+// WebAssembly in LLVM 11. -+func DisableTailCalls(mod llvm.Module) { -+ attribute := mod.Context().CreateStringAttribute("disable-tail-calls", "true") -+ llvmFn := mod.FirstFunction() -+ for !llvmFn.IsNil() { -+ if !llvmFn.IsDeclaration() { -+ llvmFn.AddFunctionAttr(attribute) -+ } -+ llvmFn = llvm.NextFunction(llvmFn) -+ } -+} -diff --git a/transform/transform_test.go b/transform/transform_test.go -index 7a607f1..28faf86 100644 ---- a/transform/transform_test.go -+++ b/transform/transform_test.go -@@ -61,6 +61,8 @@ func testTransform(t *testing.T, pathPrefix string, transform func(mod llvm.Modu - } - } - -+var alignRegexp = regexp.MustCompile(", align [0-9]+$") -+ - // fuzzyEqualIR returns true if the two LLVM IR strings passed in are roughly - // equal. That means, only relevant lines are compared (excluding comments - // etc.). -@@ -70,8 +72,18 @@ func fuzzyEqualIR(s1, s2 string) bool { - if len(lines1) != len(lines2) { - return false - } -- for i, line := range lines1 { -- if line != lines2[i] { -+ for i, line1 := range lines1 { -+ line2 := lines2[i] -+ match1 := alignRegexp.MatchString(line1) -+ match2 := alignRegexp.MatchString(line2) -+ if match1 != match2 { -+ // Only one of the lines has the align keyword. Remove it. -+ // This is a change to make the test work in both LLVM 10 and LLVM -+ // 11 (LLVM 11 appears to automatically add alignment everywhere). -+ line1 = alignRegexp.ReplaceAllString(line1, "") -+ line2 = alignRegexp.ReplaceAllString(line2, "") -+ } -+ if line1 != line2 { - return false - } - } --- -2.26.2 - diff --git a/0006-Make-lib64-clang-include-path-check-more-robust.patch b/0006-Make-lib64-clang-include-path-check-more-robust.patch deleted file mode 100644 index 1587772..0000000 --- a/0006-Make-lib64-clang-include-path-check-more-robust.patch +++ /dev/null @@ -1,89 +0,0 @@ -From ffd6037f1c765686ea6d02e9f9fb599ed284f5be Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 4 Oct 2020 02:51:46 -0400 -Subject: [PATCH 6/6] Make lib64 clang include path check more robust. - -On Fedora 33+, there is a buggy package that installs to -`/usr/lib64/clang/{version}/lib`, even on 32-bit systems. The original -code sees the `/usr/lib64/clang/{version}` directory, checks for an -`include` subdirectory, and then gives up because it doesn't exist. - -To be more robust, check both `/usr/lib64/clang/{version}/include` and -`/usr/lib/clang/{version}/include`, sorted by version subdirectory. - -Signed-off-by: Elliott Sales de Andrade ---- - builder/env.go | 46 +++++++++++++++++++++++++++++++--------------- - 1 file changed, 31 insertions(+), 15 deletions(-) - -diff --git a/builder/env.go b/builder/env.go -index 91bc263..c93e988 100644 ---- a/builder/env.go -+++ b/builder/env.go -@@ -6,6 +6,7 @@ import ( - "os/exec" - "path/filepath" - "sort" -+ "strings" - ) - - // getClangHeaderPath returns the path to the built-in Clang headers. It tries -@@ -43,25 +44,40 @@ func getClangHeaderPath(TINYGOROOT string) string { - // /usr/lib/llvm-9/lib64/clang/9.0.1/include/ - llvmRoot := filepath.Dir(filepath.Dir(binpath)) - clangVersionRoot := filepath.Join(llvmRoot, "lib64", "clang") -- dirs, err := ioutil.ReadDir(clangVersionRoot) -- if err != nil { -- // Example include path: -- // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -- clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") -- dirs, err = ioutil.ReadDir(clangVersionRoot) -- if err != nil { -- // Unexpected. -- continue -- } -+ dirs64, err64 := ioutil.ReadDir(clangVersionRoot) -+ // Example include path: -+ // /usr/lib/llvm-9/lib/clang/9.0.1/include/ -+ clangVersionRoot = filepath.Join(llvmRoot, "lib", "clang") -+ dirs32, err32 := ioutil.ReadDir(clangVersionRoot) -+ if err64 != nil && err32 != nil { -+ // Unexpected. -+ continue -+ } -+ dirnames := make([]string, len(dirs64)+len(dirs32)) -+ for i, d := range dirs32 { -+ dirnames[i] = filepath.Join(llvmRoot, "lib", "clang", d.Name()) - } -- dirnames := make([]string, len(dirs)) -- for i, d := range dirs { -- dirnames[i] = d.Name() -+ for i, d := range dirs64 { -+ dirnames[len(dirs32)+i] = filepath.Join(llvmRoot, "lib64", "clang", d.Name()) - } -- sort.Strings(dirnames) -+ sort.SliceStable(dirnames, func(i, j int) bool { -+ // Sort by version directory, normalizing version components to 3 digits; -+ // stable sort ensures that lib64 remains after lib. -+ getNormalizedVersion := func(index int) string { -+ _, version := filepath.Split(dirnames[index]) -+ parts := strings.Split(version, ".") -+ for i := range parts { -+ for len(parts[i]) < 3 { -+ parts[i] = "0" + parts[i] -+ } -+ } -+ return strings.Join(parts, ".") -+ } -+ return getNormalizedVersion(i) < getNormalizedVersion(j) -+ }) - // Check for the highest version first. - for i := len(dirnames) - 1; i >= 0; i-- { -- path := filepath.Join(clangVersionRoot, dirnames[i], "include") -+ path := filepath.Join(dirnames[i], "include") - _, err := os.Stat(filepath.Join(path, "stdint.h")) - if err == nil { - return path --- -2.26.2 - diff --git a/sources b/sources index 2d3ee7a..043e498 100644 --- a/sources +++ b/sources @@ -1,4 +1,4 @@ -SHA512 (tinygo-0.15.0.tar.gz) = f23b705bdbe8ba9e426aeee1fb6095c74d9e4ed8f55db83475627f9932a64411a167a4cb9b4fb3f4be4ee769ad4b4c61dfc7c4db2adf6adbe0b1162789f4caa6 +SHA512 (tinygo-0.16.0.tar.gz) = fa17cbd92d2c3961df1dcb5e906070f391ce0485111f5190b812dd7b2098a4a86b657bcc4b1edb19cd7fb707824f6fc719d8554669ba806b23e9f38518fd4cc6 SHA512 (avr-6624554c02b237b23dc17d53e992bf54033fc228.tar.gz) = 1aa157bd761db38f8680614fa1cf47d7009508f65291b7eaaa5aba1ae76d35103f68a42947b7269a170d2f1cf8fb09941a5d74070fe6d204b68dd15a9ad2ed29 SHA512 (cmsis-9fe411cef1cef5de58e5957b89760759de44e393-clean.tar.xz) = f131fc241f61982c49f334eb502c2f13da61eb7bdaa641ee84a8de30c4d576b735b8aadeafd7d75351473a2df6a42de6a236ecc5dcc616ee6cfcc07af29446f9 SHA512 (cmsis_svd-d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd-clean.tar.xz) = f3040f089e0714aa7d8b234a0becf8ca77934e9aa6510ff56f68add2881ade1f52176b461fbdf6218df077f3bf66505ca4d1ef94d03d28dfad1b53801dbfc88f diff --git a/tinygo.spec b/tinygo.spec index 98bd5af..e95bef4 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -6,18 +6,14 @@ # https://github.com/tinygo-org/tinygo %global goipath github.com/tinygo-org/tinygo -Version: 0.15.0 +Version: 0.16.0 %global CMSIS_commit 9fe411cef1cef5de58e5957b89760759de44e393 %global avr_commit 6624554c02b237b23dc17d53e992bf54033fc228 %if %{fedora} > 32 %global clang_version 11 %else -%if %{fedora} > 31 %global clang_version 10 -%else -%global clang_version 9 -%endif %endif %global cmsis_svd_commit d9b58694cef35b39ddf61c07ef7e6347d6ec3cbd %global compiler_rt_version 9.0.0 @@ -68,12 +64,8 @@ Patch0001: 0001-Use-Fedora-command-names.patch Patch0002: 0002-Skip-ARM-Linux-tests.patch # We can't include STM32 .svd files because of their weird license. Patch0003: 0003-Skip-STM32-tests.patch -# https://github.com/tinygo-org/tinygo/pull/1399 -Patch0004: 0004-Also-check-lib64-for-clang-include-path.patch -# https://github.com/tinygo-org/tinygo/pull/1056 -Patch0005: 0005-main-add-initial-support-for-in-development-LLVM-11.patch -# https://github.com/tinygo-org/tinygo/pull/1424 -Patch0006: 0006-Make-lib64-clang-include-path-check-more-robust.patch +# We don't have wasmtime to run these. +Patch0004: 0004-Skip-WASI-tests.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x @@ -94,6 +86,10 @@ BuildRequires: golang(tinygo.org/x/go-llvm) BuildRequires: avr-gcc BuildRequires: avr-libc +BuildRequires: glibc-devel +%ifarch x86_64 +BuildRequires: glibc-devel(x86-32) +%endif # We don't have glibc for arm, so skip these. #BuildRequires: gcc-arm-linux-gnu #BuildRequires: gcc-aarch64-linux-gnu @@ -122,8 +118,6 @@ Recommends: qemu-system-arm-core %patch0002 -p1 %patch0003 -p1 %patch0004 -p1 -%patch0005 -p1 -%patch0006 -p1 tar -C lib -xf %{SOURCE2} rmdir lib/CMSIS