summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go-1.15
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/go/go-1.15')
-rw-r--r--meta/recipes-devtools/go/go-1.15/0001-allow-CC-and-CXX-to-have-multiple-words.patch33
-rw-r--r--meta/recipes-devtools/go/go-1.15/0002-cmd-go-make-content-based-hash-generation-less-pedan.patch219
-rw-r--r--meta/recipes-devtools/go/go-1.15/0003-allow-GOTOOLDIR-to-be-overridden-in-the-environment.patch47
-rw-r--r--meta/recipes-devtools/go/go-1.15/0004-ld-add-soname-to-shareable-objects.patch45
-rw-r--r--meta/recipes-devtools/go/go-1.15/0005-make.bash-override-CC-when-building-dist-and-go_boot.patch39
-rw-r--r--meta/recipes-devtools/go/go-1.15/0006-cmd-dist-separate-host-and-target-builds.patch274
-rw-r--r--meta/recipes-devtools/go/go-1.15/0007-cmd-go-make-GOROOT-precious-by-default.patch104
-rw-r--r--meta/recipes-devtools/go/go-1.15/0008-use-GOBUILDMODE-to-set-buildmode.patch42
8 files changed, 803 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go-1.15/0001-allow-CC-and-CXX-to-have-multiple-words.patch b/meta/recipes-devtools/go/go-1.15/0001-allow-CC-and-CXX-to-have-multiple-words.patch
new file mode 100644
index 0000000000..5f4823be22
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0001-allow-CC-and-CXX-to-have-multiple-words.patch
@@ -0,0 +1,33 @@
1From 9e3dc44cdfa58d96504d0a789dc82617dd5bef55 Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:01:13 +0430
4Subject: [PATCH 1/9] cmd/go: Allow CC and CXX to have multiple words
5
6Upstream-Status: Inappropriate [OE specific]
7
8Adapted to Go 1.13 from patches originally submitted to
9the meta/recipes-devtools/go tree by
10Matt Madison <matt@madison.systems>.
11
12Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
13
14---
15 src/cmd/go/internal/envcmd/env.go | 4 ++--
16 1 file changed, 2 insertions(+), 2 deletions(-)
17
18--- a/src/cmd/go/internal/envcmd/env.go
19+++ b/src/cmd/go/internal/envcmd/env.go
20@@ -103,11 +103,11 @@ func MkEnv() []cfg.EnvVar {
21
22 cc := cfg.DefaultCC(cfg.Goos, cfg.Goarch)
23 if env := strings.Fields(cfg.Getenv("CC")); len(env) > 0 {
24- cc = env[0]
25+ cc = strings.Join(env, " ")
26 }
27 cxx := cfg.DefaultCXX(cfg.Goos, cfg.Goarch)
28 if env := strings.Fields(cfg.Getenv("CXX")); len(env) > 0 {
29- cxx = env[0]
30+ cxx = strings.Join(env, " ")
31 }
32 env = append(env, cfg.EnvVar{Name: "AR", Value: envOr("AR", "ar")})
33 env = append(env, cfg.EnvVar{Name: "CC", Value: cc})
diff --git a/meta/recipes-devtools/go/go-1.15/0002-cmd-go-make-content-based-hash-generation-less-pedan.patch b/meta/recipes-devtools/go/go-1.15/0002-cmd-go-make-content-based-hash-generation-less-pedan.patch
new file mode 100644
index 0000000000..d0511c0c40
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0002-cmd-go-make-content-based-hash-generation-less-pedan.patch
@@ -0,0 +1,219 @@
1From a13ae484e41139094505d2834437e9262a5315f7 Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:14:22 +0430
4Subject: [PATCH 2/9] cmd/go: make content-based hash generation less pedantic
5
6Upstream-Status: Inappropriate [OE specific]
7
8Go 1.10's build tool now uses content-based hashes to
9determine when something should be built or re-built.
10This same mechanism is used to maintain a built-artifact
11cache for speeding up builds.
12
13However, the hashes it generates include information that
14doesn't work well with OE, nor with using a shared runtime
15library.
16
17First, it embeds path names to source files, unless
18building within GOROOT. This prevents the building
19of a package in GOPATH for later staging into GOROOT.
20
21This patch adds support for the environment variable
22GOPATH_OMIT_IN_ACTIONID. If present, path name
23embedding is disabled.
24
25Second, if cgo is enabled, the build ID for cgo-related
26packages will include the current value of the environment
27variables for invoking the compiler (CC, CXX, FC) and
28any CGO_xxFLAGS variables. Only if the settings used
29during a compilation exactly match, character for character,
30the values used for compiling runtime/cgo or any other
31cgo-enabled package being imported, will the tool
32decide that the imported package is up-to-date.
33
34This is done to help ensure correctness, but is overly
35simplistic and effectively prevents the reuse of built
36artifacts that use cgo (or shared runtime, which includes
37runtime/cgo).
38
39This patch filters out all compiler flags except those
40beginning with '-m'. The default behavior can be restored
41by setting the CGO_PEDANTIC environment variable.
42
43Adapted to Go 1.13 from patches originally submitted to
44the meta/recipes-devtools/go tree by
45Matt Madison <matt@madison.systems>.
46
47Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
48---
49 src/cmd/go/internal/envcmd/env.go | 2 +-
50 src/cmd/go/internal/work/exec.go | 66 ++++++++++++++++++++++---------
51 2 files changed, 49 insertions(+), 19 deletions(-)
52
53--- a/src/cmd/go/internal/envcmd/env.go
54+++ b/src/cmd/go/internal/envcmd/env.go
55@@ -157,7 +157,7 @@ func ExtraEnvVars() []cfg.EnvVar {
56 func ExtraEnvVarsCostly() []cfg.EnvVar {
57 var b work.Builder
58 b.Init()
59- cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{})
60+ cppflags, cflags, cxxflags, fflags, ldflags, err := b.CFlags(&load.Package{}, false)
61 if err != nil {
62 // Should not happen - b.CFlags was given an empty package.
63 fmt.Fprintf(os.Stderr, "go: invalid cflags: %v\n", err)
64--- a/src/cmd/go/internal/work/exec.go
65+++ b/src/cmd/go/internal/work/exec.go
66@@ -33,6 +33,8 @@ import (
67 "cmd/go/internal/str"
68 )
69
70+var omitGopath = os.Getenv("GOPATH_OMIT_IN_ACTIONID") != ""
71+
72 // actionList returns the list of actions in the dag rooted at root
73 // as visited in a depth-first post-order traversal.
74 func actionList(root *Action) []*Action {
75@@ -209,7 +211,7 @@ func (b *Builder) buildActionID(a *Actio
76 // Assume b.WorkDir is being trimmed properly.
77 // When -trimpath is used with a package built from the module cache,
78 // use the module path and version instead of the directory.
79- if !p.Goroot && !cfg.BuildTrimpath && !strings.HasPrefix(p.Dir, b.WorkDir) {
80+ if !p.Goroot && !omitGopath && !cfg.BuildTrimpath && !strings.HasPrefix(p.Dir, b.WorkDir) {
81 fmt.Fprintf(h, "dir %s\n", p.Dir)
82 } else if cfg.BuildTrimpath && p.Module != nil {
83 fmt.Fprintf(h, "module %s@%s\n", p.Module.Path, p.Module.Version)
84@@ -228,13 +230,13 @@ func (b *Builder) buildActionID(a *Actio
85 }
86 if len(p.CgoFiles)+len(p.SwigFiles) > 0 {
87 fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
88- cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
89- fmt.Fprintf(h, "CC=%q %q %q %q\n", b.ccExe(), cppflags, cflags, ldflags)
90+ cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p, true)
91+ fmt.Fprintf(h, "CC=%q %q %q %q\n", b.ccExe(true), cppflags, cflags, ldflags)
92 if len(p.CXXFiles)+len(p.SwigFiles) > 0 {
93- fmt.Fprintf(h, "CXX=%q %q\n", b.cxxExe(), cxxflags)
94+ fmt.Fprintf(h, "CXX=%q %q\n", b.cxxExe(true), cxxflags)
95 }
96 if len(p.FFiles) > 0 {
97- fmt.Fprintf(h, "FC=%q %q\n", b.fcExe(), fflags)
98+ fmt.Fprintf(h, "FC=%q %q\n", b.fcExe(true), fflags)
99 }
100 // TODO(rsc): Should we include the SWIG version or Fortran/GCC/G++/Objective-C compiler versions?
101 }
102@@ -2298,33 +2300,48 @@ var (
103 // gccCmd returns a gcc command line prefix
104 // defaultCC is defined in zdefaultcc.go, written by cmd/dist.
105 func (b *Builder) GccCmd(incdir, workdir string) []string {
106- return b.compilerCmd(b.ccExe(), incdir, workdir)
107+ return b.compilerCmd(b.ccExe(false), incdir, workdir)
108 }
109
110 // gxxCmd returns a g++ command line prefix
111 // defaultCXX is defined in zdefaultcc.go, written by cmd/dist.
112 func (b *Builder) GxxCmd(incdir, workdir string) []string {
113- return b.compilerCmd(b.cxxExe(), incdir, workdir)
114+ return b.compilerCmd(b.cxxExe(false), incdir, workdir)
115 }
116
117 // gfortranCmd returns a gfortran command line prefix.
118 func (b *Builder) gfortranCmd(incdir, workdir string) []string {
119- return b.compilerCmd(b.fcExe(), incdir, workdir)
120+ return b.compilerCmd(b.fcExe(false), incdir, workdir)
121 }
122
123 // ccExe returns the CC compiler setting without all the extra flags we add implicitly.
124-func (b *Builder) ccExe() []string {
125- return b.compilerExe(origCC, cfg.DefaultCC(cfg.Goos, cfg.Goarch))
126+func (b *Builder) ccExe(filtered bool) []string {
127+ return b.compilerExe(origCC, cfg.DefaultCC(cfg.Goos, cfg.Goarch), filtered)
128 }
129
130 // cxxExe returns the CXX compiler setting without all the extra flags we add implicitly.
131-func (b *Builder) cxxExe() []string {
132- return b.compilerExe(origCXX, cfg.DefaultCXX(cfg.Goos, cfg.Goarch))
133+func (b *Builder) cxxExe(filtered bool) []string {
134+ return b.compilerExe(origCXX, cfg.DefaultCXX(cfg.Goos, cfg.Goarch), filtered)
135 }
136
137 // fcExe returns the FC compiler setting without all the extra flags we add implicitly.
138-func (b *Builder) fcExe() []string {
139- return b.compilerExe(cfg.Getenv("FC"), "gfortran")
140+func (b *Builder) fcExe(filtered bool) []string {
141+ return b.compilerExe(os.Getenv("FC"), "gfortran", filtered)
142+}
143+
144+var filterFlags = os.Getenv("CGO_PEDANTIC") == ""
145+
146+func filterCompilerFlags(flags []string) []string {
147+ var newflags []string
148+ if !filterFlags {
149+ return flags
150+ }
151+ for _, flag := range flags {
152+ if strings.HasPrefix(flag, "-m") {
153+ newflags = append(newflags, flag)
154+ }
155+ }
156+ return newflags
157 }
158
159 // compilerExe returns the compiler to use given an
160@@ -2333,11 +2350,16 @@ func (b *Builder) fcExe() []string {
161 // of the compiler but can have additional arguments if they
162 // were present in the environment value.
163 // For example if CC="gcc -DGOPHER" then the result is ["gcc", "-DGOPHER"].
164-func (b *Builder) compilerExe(envValue string, def string) []string {
165+func (b *Builder) compilerExe(envValue string, def string, filtered bool) []string {
166 compiler := strings.Fields(envValue)
167 if len(compiler) == 0 {
168 compiler = []string{def}
169 }
170+
171+ if filtered {
172+ return append(compiler[0:1], filterCompilerFlags(compiler[1:])...)
173+ }
174+
175 return compiler
176 }
177
178@@ -2510,7 +2532,7 @@ func envList(key, def string) []string {
179 }
180
181 // CFlags returns the flags to use when invoking the C, C++ or Fortran compilers, or cgo.
182-func (b *Builder) CFlags(p *load.Package) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
183+func (b *Builder) CFlags(p *load.Package, filtered bool) (cppflags, cflags, cxxflags, fflags, ldflags []string, err error) {
184 defaults := "-g -O2"
185
186 if cppflags, err = buildFlags("CPPFLAGS", "", p.CgoCPPFLAGS, checkCompilerFlags); err != nil {
187@@ -2529,6 +2551,14 @@ func (b *Builder) CFlags(p *load.Package
188 return
189 }
190
191+ if filtered {
192+ cppflags = filterCompilerFlags(cppflags)
193+ cflags = filterCompilerFlags(cflags)
194+ cxxflags = filterCompilerFlags(cxxflags)
195+ fflags = filterCompilerFlags(fflags)
196+ ldflags = filterCompilerFlags(ldflags)
197+ }
198+
199 return
200 }
201
202@@ -2543,7 +2573,7 @@ var cgoRe = lazyregexp.New(`[/\\:]`)
203
204 func (b *Builder) cgo(a *Action, cgoExe, objdir string, pcCFLAGS, pcLDFLAGS, cgofiles, gccfiles, gxxfiles, mfiles, ffiles []string) (outGo, outObj []string, err error) {
205 p := a.Package
206- cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p)
207+ cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, cgoFFLAGS, cgoLDFLAGS, err := b.CFlags(p, false)
208 if err != nil {
209 return nil, nil, err
210 }
211@@ -2902,7 +2932,7 @@ func (b *Builder) swigIntSize(objdir str
212
213 // Run SWIG on one SWIG input file.
214 func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
215- cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p)
216+ cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _, err := b.CFlags(p, false)
217 if err != nil {
218 return "", "", err
219 }
diff --git a/meta/recipes-devtools/go/go-1.15/0003-allow-GOTOOLDIR-to-be-overridden-in-the-environment.patch b/meta/recipes-devtools/go/go-1.15/0003-allow-GOTOOLDIR-to-be-overridden-in-the-environment.patch
new file mode 100644
index 0000000000..662c705471
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0003-allow-GOTOOLDIR-to-be-overridden-in-the-environment.patch
@@ -0,0 +1,47 @@
1From 28ada8896b76d620240bafc22aa395071d601482 Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:15:37 +0430
4Subject: [PATCH 3/9] cmd/go: Allow GOTOOLDIR to be overridden in the environment
5
6to allow for split host/target build roots
7
8Adapted to Go 1.13 from patches originally submitted to
9the meta/recipes-devtools/go tree by
10Matt Madison <matt@madison.systems>.
11
12Upstream-Status: Inappropriate [OE specific]
13
14Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
15---
16 src/cmd/dist/build.go | 4 +++-
17 src/cmd/go/internal/cfg/cfg.go | 6 +++++-
18 2 files changed, 8 insertions(+), 2 deletions(-)
19
20--- a/src/cmd/dist/build.go
21+++ b/src/cmd/dist/build.go
22@@ -246,7 +246,9 @@ func xinit() {
23 workdir = xworkdir()
24 xatexit(rmworkdir)
25
26- tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch)
27+ if tooldir = os.Getenv("GOTOOLDIR"); tooldir == "" {
28+ tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch)
29+ }
30 }
31
32 // compilerEnv returns a map from "goos/goarch" to the
33--- a/src/cmd/go/internal/cfg/cfg.go
34+++ b/src/cmd/go/internal/cfg/cfg.go
35@@ -64,7 +64,11 @@ func defaultContext() build.Context {
36 // variables. This matches the initialization of ToolDir in
37 // go/build, except for using ctxt.GOROOT rather than
38 // runtime.GOROOT.
39- build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
40+ if s := os.Getenv("GOTOOLDIR"); s != "" {
41+ build.ToolDir = filepath.Clean(s)
42+ } else {
43+ build.ToolDir = filepath.Join(ctxt.GOROOT, "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH)
44+ }
45 }
46
47 ctxt.GOPATH = envOr("GOPATH", ctxt.GOPATH)
diff --git a/meta/recipes-devtools/go/go-1.15/0004-ld-add-soname-to-shareable-objects.patch b/meta/recipes-devtools/go/go-1.15/0004-ld-add-soname-to-shareable-objects.patch
new file mode 100644
index 0000000000..da29923920
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0004-ld-add-soname-to-shareable-objects.patch
@@ -0,0 +1,45 @@
1From bf5cf5301ae5914498454c87293d1df2e1d8489f Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:16:32 +0430
4Subject: [PATCH 4/9] ld: add soname to shareable objects
5
6so that OE's shared library dependency handling
7can find them.
8
9Adapted to Go 1.13 from patches originally submitted to
10the meta/recipes-devtools/go tree by
11Matt Madison <matt@madison.systems>.
12
13Upstream-Status: Inappropriate [OE specific]
14
15Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
16---
17 src/cmd/link/internal/ld/lib.go | 3 +++
18 1 file changed, 3 insertions(+)
19
20--- a/src/cmd/link/internal/ld/lib.go
21+++ b/src/cmd/link/internal/ld/lib.go
22@@ -1446,6 +1446,7 @@ func (ctxt *Link) hostlink() {
23 argv = append(argv, "-Wl,-z,relro")
24 }
25 argv = append(argv, "-shared")
26+ argv = append(argv, fmt.Sprintf("-Wl,-soname,%s", filepath.Base(*flagOutfile)))
27 if ctxt.HeadType != objabi.Hwindows {
28 // Pass -z nodelete to mark the shared library as
29 // non-closeable: a dlclose will do nothing.
30@@ -1457,6 +1458,7 @@ func (ctxt *Link) hostlink() {
31 argv = append(argv, "-Wl,-z,relro")
32 }
33 argv = append(argv, "-shared")
34+ argv = append(argv, fmt.Sprintf("-Wl,-soname,%s", filepath.Base(*flagOutfile)))
35 case BuildModePlugin:
36 if ctxt.HeadType == objabi.Hdarwin {
37 argv = append(argv, "-dynamiclib")
38@@ -1465,6 +1467,7 @@ func (ctxt *Link) hostlink() {
39 argv = append(argv, "-Wl,-z,relro")
40 }
41 argv = append(argv, "-shared")
42+ argv = append(argv, fmt.Sprintf("-Wl,-soname,%s", filepath.Base(*flagOutfile)))
43 }
44 }
45
diff --git a/meta/recipes-devtools/go/go-1.15/0005-make.bash-override-CC-when-building-dist-and-go_boot.patch b/meta/recipes-devtools/go/go-1.15/0005-make.bash-override-CC-when-building-dist-and-go_boot.patch
new file mode 100644
index 0000000000..59c12d9546
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0005-make.bash-override-CC-when-building-dist-and-go_boot.patch
@@ -0,0 +1,39 @@
1From f05ef3ded52b98537c10efd0b15cd9612471524d Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:17:16 +0430
4Subject: [PATCH 5/9] make.bash: override CC when building dist and
5 go_bootstrap
6
7for handling OE cross-canadian builds.
8
9Adapted to Go 1.13 from patches originally submitted to
10the meta/recipes-devtools/go tree by
11Matt Madison <matt@madison.systems>.
12
13Upstream-Status: Inappropriate [OE specific]
14
15Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
16---
17 src/make.bash | 4 ++--
18 1 file changed, 2 insertions(+), 2 deletions(-)
19
20--- a/src/make.bash
21+++ b/src/make.bash
22@@ -178,7 +178,7 @@ if [ "$GOROOT_BOOTSTRAP" = "$GOROOT" ];
23 exit 1
24 fi
25 rm -f cmd/dist/dist
26-GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" GO111MODULE=off "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
27+CC="${BUILD_CC:-${CC}}" GOROOT="$GOROOT_BOOTSTRAP" GOOS="" GOARCH="" GO111MODULE=off "$GOROOT_BOOTSTRAP/bin/go" build -o cmd/dist/dist ./cmd/dist
28
29 # -e doesn't propagate out of eval, so check success by hand.
30 eval $(./cmd/dist/dist env -p || echo FAIL=true)
31@@ -209,7 +209,7 @@ fi
32 # Run dist bootstrap to complete make.bash.
33 # Bootstrap installs a proper cmd/dist, built with the new toolchain.
34 # Throw ours, built with Go 1.4, away after bootstrap.
35-./cmd/dist/dist bootstrap $buildall $vflag $GO_DISTFLAGS "$@"
36+CC="${BUILD_CC:-${CC}}" ./cmd/dist/dist bootstrap $buildall $vflag $GO_DISTFLAGS "$@"
37 rm -f ./cmd/dist/dist
38
39 # DO NOT ADD ANY NEW CODE HERE.
diff --git a/meta/recipes-devtools/go/go-1.15/0006-cmd-dist-separate-host-and-target-builds.patch b/meta/recipes-devtools/go/go-1.15/0006-cmd-dist-separate-host-and-target-builds.patch
new file mode 100644
index 0000000000..7aee0bac43
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0006-cmd-dist-separate-host-and-target-builds.patch
@@ -0,0 +1,274 @@
1From 10735bb84df17ba657f76835f483cd8543a879c1 Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:18:12 +0430
4Subject: [PATCH 6/9] cmd/dist: separate host and target builds
5
6Upstream-Status: Inappropriate [OE specific]
7
8Change the dist tool to allow for OE-style cross-
9and cross-canadian builds:
10
11 - command flags --host-only and --target only are added;
12 if one is present, the other changes mentioned below
13 take effect, and arguments may also be specified on
14 the command line to enumerate the package(s) to be
15 built.
16
17 - for OE cross builds, go_bootstrap is always built for
18 the current build host, and is moved, along with the supporting
19 toolchain (asm, compile, etc.) to a separate 'native_native'
20 directory under GOROOT/pkg/tool.
21
22 - go_bootstrap is not automatically removed after the build,
23 so it can be reused later (e.g., building both static and
24 shared runtime).
25
26Note that for --host-only builds, it would be nice to specify
27just the "cmd" package to build only the go commands/tools,
28the staleness checks in the dist tool will fail if the "std"
29library has not also been built. So host-only builds have to
30build everything anyway.
31
32Adapted to Go 1.13 from patches originally submitted to
33the meta/recipes-devtools/go tree by
34Matt Madison <matt@madison.systems>.
35
36Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
37---
38 src/cmd/dist/build.go | 155 ++++++++++++++++++++++++++++++------------
39 1 file changed, 112 insertions(+), 43 deletions(-)
40
41--- a/src/cmd/dist/build.go
42+++ b/src/cmd/dist/build.go
43@@ -41,6 +41,7 @@ var (
44 goldflags string
45 workdir string
46 tooldir string
47+ build_tooldir string
48 oldgoos string
49 oldgoarch string
50 exe string
51@@ -53,6 +54,7 @@ var (
52
53 rebuildall bool
54 defaultclang bool
55+ crossBuild bool
56
57 vflag int // verbosity
58 )
59@@ -249,6 +251,8 @@ func xinit() {
60 if tooldir = os.Getenv("GOTOOLDIR"); tooldir == "" {
61 tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch)
62 }
63+
64+ build_tooldir = pathf("%s/pkg/tool/native_native", goroot)
65 }
66
67 // compilerEnv returns a map from "goos/goarch" to the
68@@ -480,8 +484,10 @@ func setup() {
69 p := pathf("%s/pkg/%s_%s", goroot, gohostos, gohostarch)
70 if rebuildall {
71 xremoveall(p)
72+ xremoveall(build_tooldir)
73 }
74 xmkdirall(p)
75+ xmkdirall(build_tooldir)
76
77 if goos != gohostos || goarch != gohostarch {
78 p := pathf("%s/pkg/%s_%s", goroot, goos, goarch)
79@@ -1244,12 +1250,29 @@ func cmdbootstrap() {
80
81 var noBanner bool
82 var debug bool
83+ var hostOnly bool
84+ var targetOnly bool
85+ var toBuild = []string{"std", "cmd"}
86+
87 flag.BoolVar(&rebuildall, "a", rebuildall, "rebuild all")
88 flag.BoolVar(&debug, "d", debug, "enable debugging of bootstrap process")
89 flag.BoolVar(&noBanner, "no-banner", noBanner, "do not print banner")
90+ flag.BoolVar(&hostOnly, "host-only", hostOnly, "build only host binaries, not target")
91+ flag.BoolVar(&targetOnly, "target-only", targetOnly, "build only target binaries, not host")
92
93- xflagparse(0)
94+ xflagparse(-1)
95
96+ if hostOnly && targetOnly {
97+ fatalf("specify only one of --host-only or --target-only\n")
98+ }
99+ crossBuild = hostOnly || targetOnly
100+ if flag.NArg() > 0 {
101+ if crossBuild {
102+ toBuild = flag.Args()
103+ } else {
104+ fatalf("package names not permitted without --host-only or --target-only\n")
105+ }
106+ }
107 // Set GOPATH to an internal directory. We shouldn't actually
108 // need to store files here, since the toolchain won't
109 // depend on modules outside of vendor directories, but if
110@@ -1303,8 +1326,13 @@ func cmdbootstrap() {
111 xprintf("\n")
112 }
113
114- gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now
115- goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
116+ // For split host/target cross/cross-canadian builds, we don't
117+ // want to be setting these flags until after we have compiled
118+ // the toolchain that runs on the build host.
119+ if !crossBuild {
120+ gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now
121+ goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
122+ }
123 goBootstrap := pathf("%s/go_bootstrap", tooldir)
124 cmdGo := pathf("%s/go", gobin)
125 if debug {
126@@ -1333,7 +1361,11 @@ func cmdbootstrap() {
127 xprintf("\n")
128 }
129 xprintf("Building Go toolchain2 using go_bootstrap and Go toolchain1.\n")
130- os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
131+ if crossBuild {
132+ os.Setenv("CC", defaultcc[""])
133+ } else {
134+ os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
135+ }
136 goInstall(goBootstrap, append([]string{"-i"}, toolchain...)...)
137 if debug {
138 run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
139@@ -1370,50 +1402,84 @@ func cmdbootstrap() {
140 }
141 checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
142
143- if goos == oldgoos && goarch == oldgoarch {
144- // Common case - not setting up for cross-compilation.
145- timelog("build", "toolchain")
146- if vflag > 0 {
147- xprintf("\n")
148+ if crossBuild {
149+ gogcflags = os.Getenv("GO_GCFLAGS")
150+ goldflags = os.Getenv("GO_LDFLAGS")
151+ tool_files, _ := filepath.Glob(pathf("%s/*", tooldir))
152+ for _, f := range tool_files {
153+ copyfile(pathf("%s/%s", build_tooldir, filepath.Base(f)), f, writeExec)
154+ xremove(f)
155+ }
156+ os.Setenv("GOTOOLDIR", build_tooldir)
157+ goBootstrap = pathf("%s/go_bootstrap", build_tooldir)
158+ if hostOnly {
159+ timelog("build", "host toolchain")
160+ if vflag > 0 {
161+ xprintf("\n")
162+ }
163+ xprintf("Building %s for host, %s/%s.\n", strings.Join(toBuild, ","), goos, goarch)
164+ goInstall(goBootstrap, toBuild...)
165+ checkNotStale(goBootstrap, toBuild...)
166+ // Skip cmdGo staleness checks here, since we can't necessarily run the cmdGo binary
167+
168+ timelog("build", "target toolchain")
169+ if vflag > 0 {
170+ xprintf("\n")
171+ }
172+ } else if targetOnly {
173+ goos = oldgoos
174+ goarch = oldgoarch
175+ os.Setenv("GOOS", goos)
176+ os.Setenv("GOARCH", goarch)
177+ os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
178+ xprintf("Building %s for target, %s/%s.\n", strings.Join(toBuild, ","), goos, goarch)
179+ goInstall(goBootstrap, toBuild...)
180+ checkNotStale(goBootstrap, toBuild...)
181+ // Skip cmdGo staleness checks here, since we can't run the target's cmdGo binary
182 }
183- xprintf("Building packages and commands for %s/%s.\n", goos, goarch)
184 } else {
185- // GOOS/GOARCH does not match GOHOSTOS/GOHOSTARCH.
186- // Finish GOHOSTOS/GOHOSTARCH installation and then
187- // run GOOS/GOARCH installation.
188- timelog("build", "host toolchain")
189- if vflag > 0 {
190- xprintf("\n")
191+
192+ if goos == oldgoos && goarch == oldgoarch {
193+ // Common case - not setting up for cross-compilation.
194+ timelog("build", "toolchain")
195+ if vflag > 0 {
196+ xprintf("\n")
197+ }
198+ xprintf("Building packages and commands for %s/%s.\n", goos, goarch)
199+ } else {
200+ // GOOS/GOARCH does not match GOHOSTOS/GOHOSTARCH.
201+ // Finish GOHOSTOS/GOHOSTARCH installation and then
202+ // run GOOS/GOARCH installation.
203+ timelog("build", "host toolchain")
204+ if vflag > 0 {
205+ xprintf("\n")
206+ }
207+ xprintf("Building packages and commands for host, %s/%s.\n", goos, goarch)
208+ goInstall(goBootstrap, "std", "cmd")
209+ checkNotStale(goBootstrap, "std", "cmd")
210+ checkNotStale(cmdGo, "std", "cmd")
211+
212+ timelog("build", "target toolchain")
213+ if vflag > 0 {
214+ xprintf("\n")
215+ }
216+ goos = oldgoos
217+ goarch = oldgoarch
218+ os.Setenv("GOOS", goos)
219+ os.Setenv("GOARCH", goarch)
220+ os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
221+ xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch)
222 }
223- xprintf("Building packages and commands for host, %s/%s.\n", goos, goarch)
224 goInstall(goBootstrap, "std", "cmd")
225 checkNotStale(goBootstrap, "std", "cmd")
226 checkNotStale(cmdGo, "std", "cmd")
227
228- timelog("build", "target toolchain")
229- if vflag > 0 {
230- xprintf("\n")
231- }
232- goos = oldgoos
233- goarch = oldgoarch
234- os.Setenv("GOOS", goos)
235- os.Setenv("GOARCH", goarch)
236- os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
237- xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch)
238- }
239- targets := []string{"std", "cmd"}
240- if goos == "js" && goarch == "wasm" {
241- // Skip the cmd tools for js/wasm. They're not usable.
242- targets = targets[:1]
243- }
244- goInstall(goBootstrap, targets...)
245- checkNotStale(goBootstrap, targets...)
246- checkNotStale(cmdGo, targets...)
247- if debug {
248- run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
249- run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch))
250- checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
251- copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec)
252+ if debug {
253+ run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
254+ run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch))
255+ checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
256+ copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec)
257+ }
258 }
259
260 // Check that there are no new files in $GOROOT/bin other than
261@@ -1430,8 +1496,11 @@ func cmdbootstrap() {
262 }
263 }
264
265- // Remove go_bootstrap now that we're done.
266- xremove(pathf("%s/go_bootstrap", tooldir))
267+ // Except that for split host/target cross-builds, we need to
268+ // keep it.
269+ if !crossBuild {
270+ xremove(pathf("%s/go_bootstrap", tooldir))
271+ }
272
273 if goos == "android" {
274 // Make sure the exec wrapper will sync a fresh $GOROOT to the device.
diff --git a/meta/recipes-devtools/go/go-1.15/0007-cmd-go-make-GOROOT-precious-by-default.patch b/meta/recipes-devtools/go/go-1.15/0007-cmd-go-make-GOROOT-precious-by-default.patch
new file mode 100644
index 0000000000..4b4d0d4f3d
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0007-cmd-go-make-GOROOT-precious-by-default.patch
@@ -0,0 +1,104 @@
1From 9ba507e076c744f4d394418e4a849e68cd426a4a Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:18:56 +0430
4Subject: [PATCH 7/9] cmd/go: make GOROOT precious by default
5
6Upstream-Status: Inappropriate [OE specific]
7
8The go build tool normally rebuilds whatever it detects is
9stale. This can be a problem when GOROOT is intended to
10be read-only and the go runtime has been built as a shared
11library, since we don't want every application to be rebuilding
12the shared runtime - particularly in cross-build/packaging
13setups, since that would lead to 'abi mismatch' runtime errors.
14
15This patch prevents the install and linkshared actions from
16installing to GOROOT unless overridden with the GOROOT_OVERRIDE
17environment variable.
18
19Adapted to Go 1.13 from patches originally submitted to
20the meta/recipes-devtools/go tree by
21Matt Madison <matt@madison.systems>.
22
23Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
24---
25 src/cmd/go/internal/work/action.go | 3 +++
26 src/cmd/go/internal/work/build.go | 6 ++++++
27 src/cmd/go/internal/work/exec.go | 25 +++++++++++++++++++++++++
28 3 files changed, 34 insertions(+)
29
30--- a/src/cmd/go/internal/work/action.go
31+++ b/src/cmd/go/internal/work/action.go
32@@ -670,6 +670,9 @@ func (b *Builder) addTransitiveLinkDeps(
33 if p1 == nil || p1.Shlib == "" || haveShlib[filepath.Base(p1.Shlib)] {
34 continue
35 }
36+ if goRootPrecious && (p1.Standard || p1.Goroot) {
37+ continue
38+ }
39 haveShlib[filepath.Base(p1.Shlib)] = true
40 // TODO(rsc): The use of ModeInstall here is suspect, but if we only do ModeBuild,
41 // we'll end up building an overall library or executable that depends at runtime
42--- a/src/cmd/go/internal/work/build.go
43+++ b/src/cmd/go/internal/work/build.go
44@@ -167,6 +167,8 @@ See also: go install, go get, go clean.
45
46 const concurrentGCBackendCompilationEnabledByDefault = true
47
48+var goRootPrecious bool = true
49+
50 func init() {
51 // break init cycle
52 CmdBuild.Run = runBuild
53@@ -179,6 +181,10 @@ func init() {
54
55 AddBuildFlags(CmdBuild, DefaultBuildFlags)
56 AddBuildFlags(CmdInstall, DefaultBuildFlags)
57+
58+ if x := os.Getenv("GOROOT_OVERRIDE"); x != "" {
59+ goRootPrecious = false
60+ }
61 }
62
63 // Note that flags consulted by other parts of the code
64--- a/src/cmd/go/internal/work/exec.go
65+++ b/src/cmd/go/internal/work/exec.go
66@@ -468,6 +468,23 @@ func (b *Builder) build(a *Action) (err
67 return errors.New("binary-only packages are no longer supported")
68 }
69
70+ if goRootPrecious && (a.Package.Standard || a.Package.Goroot) {
71+ _, err := os.Stat(a.Package.Target)
72+ if err == nil {
73+ a.built = a.Package.Target
74+ a.Target = a.Package.Target
75+ a.buildID = b.fileHash(a.Package.Target)
76+ a.Package.Stale = false
77+ a.Package.StaleReason = "GOROOT-resident package"
78+ return nil
79+ }
80+ a.Package.Stale = true
81+ a.Package.StaleReason = "missing or invalid GOROOT-resident package"
82+ if b.IsCmdList {
83+ return nil
84+ }
85+ }
86+
87 if err := b.Mkdir(a.Objdir); err != nil {
88 return err
89 }
90@@ -1520,6 +1537,14 @@ func BuildInstallFunc(b *Builder, a *Act
91 return err
92 }
93
94+ if goRootPrecious && a.Package != nil {
95+ p := a.Package
96+ if p.Standard || p.Goroot {
97+ err := fmt.Errorf("attempting to install package %s into read-only GOROOT", p.ImportPath)
98+ return err
99+ }
100+ }
101+
102 if err := b.Mkdir(a.Objdir); err != nil {
103 return err
104 }
diff --git a/meta/recipes-devtools/go/go-1.15/0008-use-GOBUILDMODE-to-set-buildmode.patch b/meta/recipes-devtools/go/go-1.15/0008-use-GOBUILDMODE-to-set-buildmode.patch
new file mode 100644
index 0000000000..4e5d5021d6
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.15/0008-use-GOBUILDMODE-to-set-buildmode.patch
@@ -0,0 +1,42 @@
1From 971b5626339ce0c4d57f9721c9a81af566c5a044 Mon Sep 17 00:00:00 2001
2From: Alex Kube <alexander.j.kube@gmail.com>
3Date: Wed, 23 Oct 2019 21:19:26 +0430
4Subject: [PATCH 8/9] cmd/go: Use GOBUILDMODE to set buildmode
5
6Upstream-Status: Denied [upstream choose antoher solution: `17a256b
7cmd/go: -buildmode=pie for android/arm']
8
9While building go itself, the go build system does not support
10to set `-buildmode=pie' from environment.
11
12Add GOBUILDMODE to support it which make PIE executables the default
13build mode, as PIE executables are required as of Yocto
14
15Refers: https://groups.google.com/forum/#!topic/golang-dev/gRCe5URKewI
16
17Adapted to Go 1.13 from patches originally submitted to
18the meta/recipes-devtools/go tree by
19Hongxu Jia <hongxu.jia@windriver.com>
20
21Signed-off-by: Alexander J Kube <alexander.j.kube@gmail.com>
22---
23 src/cmd/go/internal/work/build.go | 8 +++++++-
24 1 file changed, 7 insertions(+), 1 deletion(-)
25
26--- a/src/cmd/go/internal/work/build.go
27+++ b/src/cmd/go/internal/work/build.go
28@@ -254,7 +254,13 @@ func AddBuildFlags(cmd *base.Command, ma
29
30 cmd.Flag.Var(&load.BuildAsmflags, "asmflags", "")
31 cmd.Flag.Var(buildCompiler{}, "compiler", "")
32- cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "")
33+
34+ if bm := os.Getenv("GOBUILDMODE"); bm != "" {
35+ cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", bm, "")
36+ } else {
37+ cmd.Flag.StringVar(&cfg.BuildBuildmode, "buildmode", "default", "")
38+ }
39+
40 cmd.Flag.Var(&load.BuildGcflags, "gcflags", "")
41 cmd.Flag.Var(&load.BuildGccgoflags, "gccgoflags", "")
42 if mask&OmitModFlag == 0 {