diff --git a/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch b/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch new file mode 100644 index 0000000..040ce02 --- /dev/null +++ b/0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch @@ -0,0 +1,111 @@ +From a9406dd9dd992c8160372b07b4b0811fb9a6ffad Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 6 Feb 2022 23:26:25 -0500 +Subject: [PATCH 1/6] Fix cross-Linux setup on non-amd64 arches + +In that case, an emulator is needed for amd64, and tests should be run +_for_ amd64 as a cross test. + +Signed-off-by: Elliott Sales de Andrade +--- + compileopts/target.go | 19 ++++++++++++++----- + main_test.go | 39 +++++++++++++++++++++------------------ + 2 files changed, 35 insertions(+), 23 deletions(-) + +diff --git a/compileopts/target.go b/compileopts/target.go +index ffdf7365..9e341537 100644 +--- a/compileopts/target.go ++++ b/compileopts/target.go +@@ -317,11 +317,20 @@ func defaultTarget(goos, goarch, triple string) (*TargetSpec, error) { + if goarch != runtime.GOARCH { + // Some educated guesses as to how to invoke helper programs. + spec.GDB = []string{"gdb-multiarch"} +- if goarch == "arm" && goos == "linux" { +- spec.Emulator = []string{"qemu-arm"} +- } +- if goarch == "arm64" && goos == "linux" { +- spec.Emulator = []string{"qemu-aarch64"} ++ if goos == "linux" { ++ switch goarch { ++ case "386": ++ // amd64 can _usually_ run 32-bit programs, so skip the emulator in that case. ++ if runtime.GOARCH != "amd64" { ++ spec.Emulator = []string{"qemu-i386"} ++ } ++ case "amd64": ++ spec.Emulator = []string{"qemu-x86_64"} ++ case "arm": ++ spec.Emulator = []string{"qemu-arm"} ++ case "arm64": ++ spec.Emulator = []string{"qemu-aarch64"} ++ } + } + } + if goos != runtime.GOOS { +diff --git a/main_test.go b/main_test.go +index cf3fc989..82c0b611 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -31,6 +31,13 @@ const TESTDATA = "testdata" + + var testTarget = flag.String("target", "", "override test target") + ++var supportedLinuxArches = map[string]string{ ++ "AMD64Linux": "linux/amd64", ++ "X86Linux": "linux/386", ++ "ARMLinux": "linux/arm/6", ++ "ARM64Linux": "linux/arm64", ++} ++ + var sema = make(chan struct{}, runtime.NumCPU()) + + func TestBuild(t *testing.T) { +@@ -180,18 +187,14 @@ func TestBuild(t *testing.T) { + }) + + if runtime.GOOS == "linux" { +- t.Run("X86Linux", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromOSARCH("linux/386", sema), tests, t) +- }) +- t.Run("ARMLinux", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromOSARCH("linux/arm/6", sema), tests, t) +- }) +- t.Run("ARM64Linux", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromOSARCH("linux/arm64", sema), tests, t) +- }) ++ for name, osArch := range supportedLinuxArches { ++ options := optionsFromOSARCH(osArch, sema) ++ if options.GOARCH != runtime.GOARCH { // Native architecture already run above. ++ t.Run(name, func(t *testing.T) { ++ runPlatTests(options, tests, t) ++ }) ++ } ++ } + t.Run("WebAssembly", func(t *testing.T) { + t.Parallel() + runPlatTests(optionsFromTarget("wasm", sema), tests, t) +@@ -475,12 +478,12 @@ func TestTest(t *testing.T) { + } + if !testing.Short() { + if runtime.GOOS == "linux" { +- targs = append(targs, +- // Linux +- targ{"X86Linux", optionsFromOSARCH("linux/386", sema)}, +- targ{"ARMLinux", optionsFromOSARCH("linux/arm/6", sema)}, +- targ{"ARM64Linux", optionsFromOSARCH("linux/arm64", sema)}, +- ) ++ for name, osArch := range supportedLinuxArches { ++ options := optionsFromOSARCH(osArch, sema) ++ if options.GOARCH != runtime.GOARCH { // Native architecture already run above. ++ targs = append(targs, targ{name, options}) ++ } ++ } + } + + targs = append(targs, +-- +2.31.1 + diff --git a/0001-Skip-WASI-tests.patch b/0001-Skip-WASI-tests.patch deleted file mode 100644 index a751eb3..0000000 --- a/0001-Skip-WASI-tests.patch +++ /dev/null @@ -1,38 +0,0 @@ -From 7916f90d20fe95c4facc83d79d2d99056225e375 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Tue, 15 Dec 2020 05:06:04 -0500 -Subject: [PATCH 1/5] Skip WASI tests. - -We do not have wasmtime available. - -Signed-off-by: Elliott Sales de Andrade ---- - main_test.go | 5 ----- - 1 file changed, 5 deletions(-) - -diff --git a/main_test.go b/main_test.go -index cf3fc989..316f69fa 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -196,10 +196,6 @@ func TestBuild(t *testing.T) { - t.Parallel() - runPlatTests(optionsFromTarget("wasm", sema), tests, t) - }) -- t.Run("WASI", func(t *testing.T) { -- t.Parallel() -- runPlatTests(optionsFromTarget("wasi", sema), tests, t) -- }) - } - } - -@@ -490,7 +486,6 @@ func TestTest(t *testing.T) { - - // Node/Wasmtime - targ{"WASM", optionsFromTarget("wasm", sema)}, -- targ{"WASI", optionsFromTarget("wasi", sema)}, - ) - } - for _, targ := range targs { --- -2.31.1 - diff --git a/0002-Skip-WASI-tests.patch b/0002-Skip-WASI-tests.patch new file mode 100644 index 0000000..63aa5e6 --- /dev/null +++ b/0002-Skip-WASI-tests.patch @@ -0,0 +1,38 @@ +From 64af5a0ac7d93ad931737358c1af852e99fbf647 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Tue, 15 Dec 2020 05:06:04 -0500 +Subject: [PATCH 2/6] Skip WASI tests. + +We do not have wasmtime available. + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 5 ----- + 1 file changed, 5 deletions(-) + +diff --git a/main_test.go b/main_test.go +index 82c0b611..d9f440b0 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -199,10 +199,6 @@ func TestBuild(t *testing.T) { + t.Parallel() + runPlatTests(optionsFromTarget("wasm", sema), tests, t) + }) +- t.Run("WASI", func(t *testing.T) { +- t.Parallel() +- runPlatTests(optionsFromTarget("wasi", sema), tests, t) +- }) + } + } + +@@ -493,7 +489,6 @@ func TestTest(t *testing.T) { + + // Node/Wasmtime + targ{"WASM", optionsFromTarget("wasm", sema)}, +- targ{"WASI", optionsFromTarget("wasi", sema)}, + ) + } + for _, targ := range targs { +-- +2.31.1 + diff --git a/0002-Use-system-mingw64-headers-and-crt.patch b/0002-Use-system-mingw64-headers-and-crt.patch deleted file mode 100644 index bd4bbec..0000000 --- a/0002-Use-system-mingw64-headers-and-crt.patch +++ /dev/null @@ -1,121 +0,0 @@ -From d0bd4aaedbbe1cc02af6e3046d813fd5697b6ef0 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 2 Jan 2022 05:47:18 -0500 -Subject: [PATCH 2/5] Use system mingw64 headers and crt - -Signed-off-by: Elliott Sales de Andrade ---- - builder/mingw-w64.go | 66 +++---------------------------------------- - compileopts/config.go | 7 ++--- - 2 files changed, 6 insertions(+), 67 deletions(-) - -diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go -index bdab730f..07ce05c8 100644 ---- a/builder/mingw-w64.go -+++ b/builder/mingw-w64.go -@@ -1,31 +1,11 @@ - package builder - - import ( -- "io" -- "os" -- "path/filepath" -- "strings" -- -- "github.com/tinygo-org/tinygo/goenv" -+ "fmt" - ) - - var MinGW = Library{ - name: "mingw-w64", -- makeHeaders: func(target, includeDir string) error { -- // copy _mingw.h -- srcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib", "mingw-w64") -- outf, err := os.Create(includeDir + "/_mingw.h") -- if err != nil { -- return err -- } -- defer outf.Close() -- inf, err := os.Open(srcDir + "/mingw-w64-headers/crt/_mingw.h.in") -- if err != nil { -- return err -- } -- _, err = io.Copy(outf, inf) -- return err -- }, - cflags: func(target, headerPath string) []string { - // No flags necessary because there are no files to compile. - return nil -@@ -44,47 +24,9 @@ var MinGW = Library{ - // compile these files. - func makeMinGWExtraLibs(tmpdir string) []*compileJob { - var jobs []*compileJob -- root := goenv.Get("TINYGOROOT") -- // Normally all the api-ms-win-crt-*.def files are all compiled to a single -- // .lib file. But to simplify things, we're going to leave them as separate -- // files. -- for _, name := range []string{ -- "kernel32.def.in", -- "api-ms-win-crt-conio-l1-1-0.def", -- "api-ms-win-crt-convert-l1-1-0.def", -- "api-ms-win-crt-environment-l1-1-0.def", -- "api-ms-win-crt-filesystem-l1-1-0.def", -- "api-ms-win-crt-heap-l1-1-0.def", -- "api-ms-win-crt-locale-l1-1-0.def", -- "api-ms-win-crt-math-l1-1-0.def.in", -- "api-ms-win-crt-multibyte-l1-1-0.def", -- "api-ms-win-crt-private-l1-1-0.def.in", -- "api-ms-win-crt-process-l1-1-0.def", -- "api-ms-win-crt-runtime-l1-1-0.def.in", -- "api-ms-win-crt-stdio-l1-1-0.def", -- "api-ms-win-crt-string-l1-1-0.def", -- "api-ms-win-crt-time-l1-1-0.def", -- "api-ms-win-crt-utility-l1-1-0.def", -- } { -- outpath := filepath.Join(tmpdir, filepath.Base(name)+".lib") -- inpath := filepath.Join(root, "lib/mingw-w64/mingw-w64-crt/lib-common/"+name) -- job := &compileJob{ -- description: "create lib file " + inpath, -- result: outpath, -- run: func(job *compileJob) error { -- defpath := inpath -- if strings.HasSuffix(inpath, ".in") { -- // .in files need to be preprocessed by a preprocessor (-E) -- // first. -- defpath = outpath + ".def" -- err := runCCompiler("-E", "-x", "c", "-Wp,-w", "-P", "-DDEF_X64", "-o", defpath, inpath, "-I"+goenv.Get("TINYGOROOT")+"/lib/mingw-w64/mingw-w64-crt/def-include/") -- if err != nil { -- return err -- } -- } -- return link("ld.lld", "-m", "i386pep", "-o", outpath, defpath) -- }, -- } -+ for _, name := range []string{"kernel32", "ucrt"} { -+ outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) -+ job := dummyCompileJob(outpath) - jobs = append(jobs, job) - } - return jobs -diff --git a/compileopts/config.go b/compileopts/config.go -index f33a4b1a..b8dd4c93 100644 ---- a/compileopts/config.go -+++ b/compileopts/config.go -@@ -248,12 +248,9 @@ func (c *Config) CFlags() []string { - root := goenv.Get("TINYGOROOT") - cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") - case "mingw-w64": -- root := goenv.Get("TINYGOROOT") -- path, _ := c.LibcPath("mingw-w64") - cflags = append(cflags, -- "--sysroot="+path, -- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"), -- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"), -+ "--sysroot=/usr/x86_64-w64-mingw32/sys-root", -+ "-isystem", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", - "-D_UCRT", - ) - case "": --- -2.31.1 - diff --git a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch deleted file mode 100644 index aed9c9b..0000000 --- a/0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +++ /dev/null @@ -1,43 +0,0 @@ -From f9c9b3633e322ebc3f15216afbb624bd0fb0f188 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Mon, 3 Jan 2022 22:39:31 -0500 -Subject: [PATCH 3/5] Skip some cross Linux tests where qemu is broken - -The upstream issues will hopefully be fixed soon: - -- https://gitlab.com/qemu-project/qemu/-/issues/447 -- https://gitlab.com/qemu-project/qemu/-/issues/690 - -Signed-off-by: Elliott Sales de Andrade ---- - main_test.go | 14 ++++++++++++++ - 1 file changed, 14 insertions(+) - -diff --git a/main_test.go b/main_test.go -index 316f69fa..dba5e784 100644 ---- a/main_test.go -+++ b/main_test.go -@@ -364,6 +364,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c - return - } - -+ // Skip running the test executable due to bugs in qemu. -+ // https://gitlab.com/qemu-project/qemu/-/issues/447 -+ // https://gitlab.com/qemu-project/qemu/-/issues/690 -+ switch runtime.GOARCH { -+ case "arm64": -+ if options.GOARCH == "386" || options.GOARCH == "arm" { -+ return -+ } -+ case "386": -+ if options.GOARCH == "arm" { -+ return -+ } -+ } -+ - // Reserve CPU time for the test to run. - // This attempts to ensure that the test is not CPU-starved. - options.Semaphore <- struct{}{} --- -2.31.1 - diff --git a/0003-Use-system-mingw64-headers-and-crt.patch b/0003-Use-system-mingw64-headers-and-crt.patch new file mode 100644 index 0000000..0d27d6f --- /dev/null +++ b/0003-Use-system-mingw64-headers-and-crt.patch @@ -0,0 +1,121 @@ +From 3d4375f7d44bfb3c865bdd460ad314ddf3de983d Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 2 Jan 2022 05:47:18 -0500 +Subject: [PATCH 3/6] Use system mingw64 headers and crt + +Signed-off-by: Elliott Sales de Andrade +--- + builder/mingw-w64.go | 66 +++---------------------------------------- + compileopts/config.go | 7 ++--- + 2 files changed, 6 insertions(+), 67 deletions(-) + +diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go +index bdab730f..07ce05c8 100644 +--- a/builder/mingw-w64.go ++++ b/builder/mingw-w64.go +@@ -1,31 +1,11 @@ + package builder + + import ( +- "io" +- "os" +- "path/filepath" +- "strings" +- +- "github.com/tinygo-org/tinygo/goenv" ++ "fmt" + ) + + var MinGW = Library{ + name: "mingw-w64", +- makeHeaders: func(target, includeDir string) error { +- // copy _mingw.h +- srcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib", "mingw-w64") +- outf, err := os.Create(includeDir + "/_mingw.h") +- if err != nil { +- return err +- } +- defer outf.Close() +- inf, err := os.Open(srcDir + "/mingw-w64-headers/crt/_mingw.h.in") +- if err != nil { +- return err +- } +- _, err = io.Copy(outf, inf) +- return err +- }, + cflags: func(target, headerPath string) []string { + // No flags necessary because there are no files to compile. + return nil +@@ -44,47 +24,9 @@ var MinGW = Library{ + // compile these files. + func makeMinGWExtraLibs(tmpdir string) []*compileJob { + var jobs []*compileJob +- root := goenv.Get("TINYGOROOT") +- // Normally all the api-ms-win-crt-*.def files are all compiled to a single +- // .lib file. But to simplify things, we're going to leave them as separate +- // files. +- for _, name := range []string{ +- "kernel32.def.in", +- "api-ms-win-crt-conio-l1-1-0.def", +- "api-ms-win-crt-convert-l1-1-0.def", +- "api-ms-win-crt-environment-l1-1-0.def", +- "api-ms-win-crt-filesystem-l1-1-0.def", +- "api-ms-win-crt-heap-l1-1-0.def", +- "api-ms-win-crt-locale-l1-1-0.def", +- "api-ms-win-crt-math-l1-1-0.def.in", +- "api-ms-win-crt-multibyte-l1-1-0.def", +- "api-ms-win-crt-private-l1-1-0.def.in", +- "api-ms-win-crt-process-l1-1-0.def", +- "api-ms-win-crt-runtime-l1-1-0.def.in", +- "api-ms-win-crt-stdio-l1-1-0.def", +- "api-ms-win-crt-string-l1-1-0.def", +- "api-ms-win-crt-time-l1-1-0.def", +- "api-ms-win-crt-utility-l1-1-0.def", +- } { +- outpath := filepath.Join(tmpdir, filepath.Base(name)+".lib") +- inpath := filepath.Join(root, "lib/mingw-w64/mingw-w64-crt/lib-common/"+name) +- job := &compileJob{ +- description: "create lib file " + inpath, +- result: outpath, +- run: func(job *compileJob) error { +- defpath := inpath +- if strings.HasSuffix(inpath, ".in") { +- // .in files need to be preprocessed by a preprocessor (-E) +- // first. +- defpath = outpath + ".def" +- err := runCCompiler("-E", "-x", "c", "-Wp,-w", "-P", "-DDEF_X64", "-o", defpath, inpath, "-I"+goenv.Get("TINYGOROOT")+"/lib/mingw-w64/mingw-w64-crt/def-include/") +- if err != nil { +- return err +- } +- } +- return link("ld.lld", "-m", "i386pep", "-o", outpath, defpath) +- }, +- } ++ for _, name := range []string{"kernel32", "ucrt"} { ++ outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) ++ job := dummyCompileJob(outpath) + jobs = append(jobs, job) + } + return jobs +diff --git a/compileopts/config.go b/compileopts/config.go +index f33a4b1a..b8dd4c93 100644 +--- a/compileopts/config.go ++++ b/compileopts/config.go +@@ -248,12 +248,9 @@ func (c *Config) CFlags() []string { + root := goenv.Get("TINYGOROOT") + cflags = append(cflags, "--sysroot="+root+"/lib/wasi-libc/sysroot") + case "mingw-w64": +- root := goenv.Get("TINYGOROOT") +- path, _ := c.LibcPath("mingw-w64") + cflags = append(cflags, +- "--sysroot="+path, +- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "crt"), +- "-isystem", filepath.Join(root, "lib", "mingw-w64", "mingw-w64-headers", "defaults", "include"), ++ "--sysroot=/usr/x86_64-w64-mingw32/sys-root", ++ "-isystem", "/usr/x86_64-w64-mingw32/sys-root/mingw/include", + "-D_UCRT", + ) + case "": +-- +2.31.1 + diff --git a/0004-Fix-LLVM-build-constraints.patch b/0004-Fix-LLVM-build-constraints.patch deleted file mode 100644 index de561de..0000000 --- a/0004-Fix-LLVM-build-constraints.patch +++ /dev/null @@ -1,78 +0,0 @@ -From 146b1fd103b0dbc178c1ac8c0ecfcc8b82d632ae Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Wed, 2 Feb 2022 06:54:20 -0500 -Subject: [PATCH 4/5] Fix LLVM build constraints - -Signed-off-by: Elliott Sales de Andrade ---- - cgo/libclang_config_llvm11.go | 8 ++++---- - cgo/libclang_config_llvm12.go | 8 ++++---- - cgo/libclang_config_llvm13.go | 8 ++++---- - 3 files changed, 12 insertions(+), 12 deletions(-) - -diff --git a/cgo/libclang_config_llvm11.go b/cgo/libclang_config_llvm11.go -index 262303fb..1d89c9db 100644 ---- a/cgo/libclang_config_llvm11.go -+++ b/cgo/libclang_config_llvm11.go -@@ -5,12 +5,12 @@ package cgo - - /* - #cgo linux CFLAGS: -I/usr/lib/llvm-11/include --#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@11/include --#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include -+#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@11/include -+#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include - #cgo freebsd CFLAGS: -I/usr/local/llvm11/include - #cgo linux LDFLAGS: -L/usr/lib/llvm-11/lib -lclang --#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi --#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi -+#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi -+#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi - #cgo freebsd LDFLAGS: -L/usr/local/llvm11/lib -lclang - */ - import "C" -diff --git a/cgo/libclang_config_llvm12.go b/cgo/libclang_config_llvm12.go -index 69808d2e..7ccf7141 100644 ---- a/cgo/libclang_config_llvm12.go -+++ b/cgo/libclang_config_llvm12.go -@@ -5,12 +5,12 @@ package cgo - - /* - #cgo linux CFLAGS: -I/usr/lib/llvm-12/include --#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@12/include --#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include -+#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@12/include -+#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include - #cgo freebsd CFLAGS: -I/usr/local/llvm12/include - #cgo linux LDFLAGS: -L/usr/lib/llvm-12/lib -lclang --#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi --#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi -+#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi -+#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi - #cgo freebsd LDFLAGS: -L/usr/local/llvm12/lib -lclang - */ - import "C" -diff --git a/cgo/libclang_config_llvm13.go b/cgo/libclang_config_llvm13.go -index b27b0916..83d3f414 100644 ---- a/cgo/libclang_config_llvm13.go -+++ b/cgo/libclang_config_llvm13.go -@@ -5,12 +5,12 @@ package cgo - - /* - #cgo linux CFLAGS: -I/usr/lib/llvm-13/include --#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@13/include --#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include -+#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@13/include -+#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include - #cgo freebsd CFLAGS: -I/usr/local/llvm13/include - #cgo linux LDFLAGS: -L/usr/lib/llvm-13/lib -lclang --#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi --#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi -+#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi -+#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi - #cgo freebsd LDFLAGS: -L/usr/local/llvm13/lib -lclang - */ - import "C" --- -2.31.1 - diff --git a/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch b/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch new file mode 100644 index 0000000..cf4b72f --- /dev/null +++ b/0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch @@ -0,0 +1,64 @@ +From 8c931c99e52b8dc080bdcb0a062f9ed189f4286d Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Mon, 3 Jan 2022 22:39:31 -0500 +Subject: [PATCH 4/6] Skip some cross Linux tests where qemu is broken + +The upstream issues will hopefully be fixed soon: + +- https://gitlab.com/qemu-project/qemu/-/issues/447 +- https://gitlab.com/qemu-project/qemu/-/issues/690 + +Signed-off-by: Elliott Sales de Andrade +--- + main_test.go | 28 ++++++++++++++++++++++++++++ + 1 file changed, 28 insertions(+) + +diff --git a/main_test.go b/main_test.go +index d9f440b0..d3daddc3 100644 +--- a/main_test.go ++++ b/main_test.go +@@ -246,6 +246,20 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) { + } + + func emuCheck(t *testing.T, options compileopts.Options) { ++ // Skip running the test executable due to bugs in qemu. ++ // https://gitlab.com/qemu-project/qemu/-/issues/447 ++ // https://gitlab.com/qemu-project/qemu/-/issues/690 ++ switch runtime.GOARCH { ++ case "arm64": ++ if options.GOARCH == "386" || options.GOARCH == "arm" { ++ t.Skipf("qemu is broken for this host/target architecture combination") ++ } ++ case "386": ++ if options.GOARCH == "arm" { ++ t.Skipf("qemu is broken for this host/target architecture combination") ++ } ++ } ++ + // Check if the emulator is installed. + spec, err := compileopts.LoadTarget(&options) + if err != nil { +@@ -367,6 +381,20 @@ func runTestWithConfig(name string, t *testing.T, options compileopts.Options, c + return + } + ++ // Skip running the test executable due to bugs in qemu. ++ // https://gitlab.com/qemu-project/qemu/-/issues/447 ++ // https://gitlab.com/qemu-project/qemu/-/issues/690 ++ switch runtime.GOARCH { ++ case "arm64": ++ if options.GOARCH == "386" || options.GOARCH == "arm" { ++ return ++ } ++ case "386": ++ if options.GOARCH == "arm" { ++ return ++ } ++ } ++ + // Reserve CPU time for the test to run. + // This attempts to ensure that the test is not CPU-starved. + options.Semaphore <- struct{}{} +-- +2.31.1 + diff --git a/0005-Fix-LLVM-build-constraints.patch b/0005-Fix-LLVM-build-constraints.patch new file mode 100644 index 0000000..dc5b54f --- /dev/null +++ b/0005-Fix-LLVM-build-constraints.patch @@ -0,0 +1,78 @@ +From e4522f22aced375f1a80d5075326e66c71c9a524 Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Wed, 2 Feb 2022 06:54:20 -0500 +Subject: [PATCH 5/6] Fix LLVM build constraints + +Signed-off-by: Elliott Sales de Andrade +--- + cgo/libclang_config_llvm11.go | 8 ++++---- + cgo/libclang_config_llvm12.go | 8 ++++---- + cgo/libclang_config_llvm13.go | 8 ++++---- + 3 files changed, 12 insertions(+), 12 deletions(-) + +diff --git a/cgo/libclang_config_llvm11.go b/cgo/libclang_config_llvm11.go +index 262303fb..1d89c9db 100644 +--- a/cgo/libclang_config_llvm11.go ++++ b/cgo/libclang_config_llvm11.go +@@ -5,12 +5,12 @@ package cgo + + /* + #cgo linux CFLAGS: -I/usr/lib/llvm-11/include +-#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@11/include +-#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include ++#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@11/include ++#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@11/include + #cgo freebsd CFLAGS: -I/usr/local/llvm11/include + #cgo linux LDFLAGS: -L/usr/lib/llvm-11/lib -lclang +-#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi +-#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi ++#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@11/lib -lclang -lffi ++#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@11/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm11/lib -lclang + */ + import "C" +diff --git a/cgo/libclang_config_llvm12.go b/cgo/libclang_config_llvm12.go +index 69808d2e..7ccf7141 100644 +--- a/cgo/libclang_config_llvm12.go ++++ b/cgo/libclang_config_llvm12.go +@@ -5,12 +5,12 @@ package cgo + + /* + #cgo linux CFLAGS: -I/usr/lib/llvm-12/include +-#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@12/include +-#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include ++#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@12/include ++#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@12/include + #cgo freebsd CFLAGS: -I/usr/local/llvm12/include + #cgo linux LDFLAGS: -L/usr/lib/llvm-12/lib -lclang +-#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi +-#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi ++#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@12/lib -lclang -lffi ++#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@12/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm12/lib -lclang + */ + import "C" +diff --git a/cgo/libclang_config_llvm13.go b/cgo/libclang_config_llvm13.go +index b27b0916..83d3f414 100644 +--- a/cgo/libclang_config_llvm13.go ++++ b/cgo/libclang_config_llvm13.go +@@ -5,12 +5,12 @@ package cgo + + /* + #cgo linux CFLAGS: -I/usr/lib/llvm-13/include +-#cgo darwin amd64 CFLAGS: -I/usr/local/opt/llvm@13/include +-#cgo darwin arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include ++#cgo darwin/amd64 CFLAGS: -I/usr/local/opt/llvm@13/include ++#cgo darwin/arm64 CFLAGS: -I/opt/homebrew/opt/llvm@13/include + #cgo freebsd CFLAGS: -I/usr/local/llvm13/include + #cgo linux LDFLAGS: -L/usr/lib/llvm-13/lib -lclang +-#cgo darwin amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi +-#cgo darwin arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi ++#cgo darwin/amd64 LDFLAGS: -L/usr/local/opt/llvm@13/lib -lclang -lffi ++#cgo darwin/arm64 LDFLAGS: -L/opt/homebrew/opt/llvm@13/lib -lclang -lffi + #cgo freebsd LDFLAGS: -L/usr/local/llvm13/lib -lclang + */ + import "C" +-- +2.31.1 + diff --git a/0005-Suggest-optional-packages-to-install-if-missing.patch b/0005-Suggest-optional-packages-to-install-if-missing.patch deleted file mode 100644 index 03609f8..0000000 --- a/0005-Suggest-optional-packages-to-install-if-missing.patch +++ /dev/null @@ -1,78 +0,0 @@ -From a3ef83de0286ef34933d397beec7b0b0808ebfc8 Mon Sep 17 00:00:00 2001 -From: Elliott Sales de Andrade -Date: Sun, 6 Feb 2022 03:49:16 -0500 -Subject: [PATCH 5/5] Suggest optional packages to install if missing - -Signed-off-by: Elliott Sales de Andrade ---- - builder/jobs.go | 17 +++++++++++++++++ - builder/mingw-w64.go | 2 +- - builder/tools.go | 6 +++++- - 3 files changed, 23 insertions(+), 2 deletions(-) - -diff --git a/builder/jobs.go b/builder/jobs.go -index 3d510974..d24a4165 100644 ---- a/builder/jobs.go -+++ b/builder/jobs.go -@@ -7,6 +7,7 @@ import ( - "container/heap" - "errors" - "fmt" -+ "os" - "runtime" - "sort" - "strings" -@@ -37,6 +38,22 @@ type compileJob struct { - duration time.Duration // how long it took to run this job (only set after finishing) - } - -+// checkIfPackagedFileExistsJob returns a new *compileJob that checks if a file -+// exists. If the file does not exist, the job will fail with an error -+// suggesting to install the named system packageToInstall. -+func checkIfPackagedFileExistsJob(fileName, packageToInstall string) *compileJob { -+ return &compileJob{ -+ description: fmt.Sprintf("check if %v exists", fileName), -+ result: fileName, -+ run: func(*compileJob) (err error) { -+ if _, err := os.Stat(fileName); errors.Is(err, os.ErrNotExist) { -+ return fmt.Errorf("%v does not exist; please install %v via dnf", fileName, packageToInstall) -+ } -+ return nil -+ }, -+ } -+} -+ - // dummyCompileJob returns a new *compileJob that produces an output without - // doing anything. This can be useful where a *compileJob producing an output is - // expected but nothing needs to be done, for example for a load from a cache. -diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go -index 07ce05c8..76bf5806 100644 ---- a/builder/mingw-w64.go -+++ b/builder/mingw-w64.go -@@ -26,7 +26,7 @@ func makeMinGWExtraLibs(tmpdir string) []*compileJob { - var jobs []*compileJob - for _, name := range []string{"kernel32", "ucrt"} { - outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) -- job := dummyCompileJob(outpath) -+ job := checkIfPackagedFileExistsJob(outpath, "mingw64-crt and mingw64-headers") - jobs = append(jobs, job) - } - return jobs -diff --git a/builder/tools.go b/builder/tools.go -index 53d89bf0..e55719b2 100644 ---- a/builder/tools.go -+++ b/builder/tools.go -@@ -46,5 +46,9 @@ func link(linker string, flags ...string) error { - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Dir = goenv.Get("TINYGOROOT") -- return cmd.Run() -+ err := cmd.Run() -+ if linker == "avr-gcc" && errors.Is(err, exec.ErrNotFound) { -+ return errors.New("avr-gcc not found; please install avr-gcc and avr-libc via dnf") -+ } -+ return err - } --- -2.31.1 - diff --git a/0006-Suggest-optional-packages-to-install-if-missing.patch b/0006-Suggest-optional-packages-to-install-if-missing.patch new file mode 100644 index 0000000..6ec8b61 --- /dev/null +++ b/0006-Suggest-optional-packages-to-install-if-missing.patch @@ -0,0 +1,78 @@ +From ca5254f583341c91a6fc5b77c8a515e00a4f63df Mon Sep 17 00:00:00 2001 +From: Elliott Sales de Andrade +Date: Sun, 6 Feb 2022 03:49:16 -0500 +Subject: [PATCH 6/6] Suggest optional packages to install if missing + +Signed-off-by: Elliott Sales de Andrade +--- + builder/jobs.go | 17 +++++++++++++++++ + builder/mingw-w64.go | 2 +- + builder/tools.go | 6 +++++- + 3 files changed, 23 insertions(+), 2 deletions(-) + +diff --git a/builder/jobs.go b/builder/jobs.go +index 3d510974..d24a4165 100644 +--- a/builder/jobs.go ++++ b/builder/jobs.go +@@ -7,6 +7,7 @@ import ( + "container/heap" + "errors" + "fmt" ++ "os" + "runtime" + "sort" + "strings" +@@ -37,6 +38,22 @@ type compileJob struct { + duration time.Duration // how long it took to run this job (only set after finishing) + } + ++// checkIfPackagedFileExistsJob returns a new *compileJob that checks if a file ++// exists. If the file does not exist, the job will fail with an error ++// suggesting to install the named system packageToInstall. ++func checkIfPackagedFileExistsJob(fileName, packageToInstall string) *compileJob { ++ return &compileJob{ ++ description: fmt.Sprintf("check if %v exists", fileName), ++ result: fileName, ++ run: func(*compileJob) (err error) { ++ if _, err := os.Stat(fileName); errors.Is(err, os.ErrNotExist) { ++ return fmt.Errorf("%v does not exist; please install %v via dnf", fileName, packageToInstall) ++ } ++ return nil ++ }, ++ } ++} ++ + // dummyCompileJob returns a new *compileJob that produces an output without + // doing anything. This can be useful where a *compileJob producing an output is + // expected but nothing needs to be done, for example for a load from a cache. +diff --git a/builder/mingw-w64.go b/builder/mingw-w64.go +index 07ce05c8..76bf5806 100644 +--- a/builder/mingw-w64.go ++++ b/builder/mingw-w64.go +@@ -26,7 +26,7 @@ func makeMinGWExtraLibs(tmpdir string) []*compileJob { + var jobs []*compileJob + for _, name := range []string{"kernel32", "ucrt"} { + outpath := fmt.Sprintf("/usr/x86_64-w64-mingw32/sys-root/mingw/lib/lib%s.a", name) +- job := dummyCompileJob(outpath) ++ job := checkIfPackagedFileExistsJob(outpath, "mingw64-crt and mingw64-headers") + jobs = append(jobs, job) + } + return jobs +diff --git a/builder/tools.go b/builder/tools.go +index 53d89bf0..e55719b2 100644 +--- a/builder/tools.go ++++ b/builder/tools.go +@@ -46,5 +46,9 @@ func link(linker string, flags ...string) error { + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Dir = goenv.Get("TINYGOROOT") +- return cmd.Run() ++ err := cmd.Run() ++ if linker == "avr-gcc" && errors.Is(err, exec.ErrNotFound) { ++ return errors.New("avr-gcc not found; please install avr-gcc and avr-libc via dnf") ++ } ++ return err + } +-- +2.31.1 + diff --git a/tinygo.spec b/tinygo.spec index 3988e2e..ec8cb02 100644 --- a/tinygo.spec +++ b/tinygo.spec @@ -63,17 +63,19 @@ Source62: https://musl.libc.org/musl.pub Source7: https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz Source8: https://github.com/keith-packard/picolibc/archive/%{picolibc_commit}/picolibc-%{picolibc_commit}.tar.gz Source9: https://github.com/WebAssembly/wasi-libc/archive/%{wasi_libc_commit}/wasi-libc-%{wasi_libc_commit}.tar.gz +# https://github.com/tinygo-org/tinygo/pull/2620 +Patch0001: 0001-Fix-cross-Linux-setup-on-non-amd64-arches.patch # We don't have wasmtime to run these. -Patch0001: 0001-Skip-WASI-tests.patch +Patch0002: 0002-Skip-WASI-tests.patch # Unbundling things -Patch0002: 0002-Use-system-mingw64-headers-and-crt.patch +Patch0003: 0003-Use-system-mingw64-headers-and-crt.patch # Skip testing some things where qemu is broken: # https://gitlab.com/qemu-project/qemu/-/issues/447 # https://gitlab.com/qemu-project/qemu/-/issues/690 -Patch0003: 0003-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch -Patch0004: 0004-Fix-LLVM-build-constraints.patch +Patch0004: 0004-Skip-some-cross-Linux-tests-where-qemu-is-broken.patch +Patch0005: 0005-Fix-LLVM-build-constraints.patch # Add Fedora specific dnf instructions -Patch0005: 0005-Suggest-optional-packages-to-install-if-missing.patch +Patch0006: 0006-Suggest-optional-packages-to-install-if-missing.patch # Not supported upstream yet. ExcludeArch: armv7hl ppc64le s390x