diff options
Diffstat (limited to 'meta/recipes-devtools/go/go-1.13/0006-cmd-dist-separate-host-and-target-builds.patch')
-rw-r--r-- | meta/recipes-devtools/go/go-1.13/0006-cmd-dist-separate-host-and-target-builds.patch | 279 |
1 files changed, 279 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go-1.13/0006-cmd-dist-separate-host-and-target-builds.patch b/meta/recipes-devtools/go/go-1.13/0006-cmd-dist-separate-host-and-target-builds.patch new file mode 100644 index 0000000000..354aaca3a1 --- /dev/null +++ b/meta/recipes-devtools/go/go-1.13/0006-cmd-dist-separate-host-and-target-builds.patch | |||
@@ -0,0 +1,279 @@ | |||
1 | From 10735bb84df17ba657f76835f483cd8543a879c1 Mon Sep 17 00:00:00 2001 | ||
2 | From: Alex Kube <alexander.j.kube@gmail.com> | ||
3 | Date: Wed, 23 Oct 2019 21:18:12 +0430 | ||
4 | Subject: [PATCH 6/9] cmd/dist: separate host and target builds | ||
5 | |||
6 | Upstream-Status: Inappropriate [OE specific] | ||
7 | |||
8 | Change the dist tool to allow for OE-style cross- | ||
9 | and 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 | |||
26 | Note that for --host-only builds, it would be nice to specify | ||
27 | just the "cmd" package to build only the go commands/tools, | ||
28 | the staleness checks in the dist tool will fail if the "std" | ||
29 | library has not also been built. So host-only builds have to | ||
30 | build everything anyway. | ||
31 | |||
32 | Adapted to Go 1.13 from patches originally submitted to | ||
33 | the meta/recipes-devtools/go tree by | ||
34 | Matt Madison <matt@madison.systems>. | ||
35 | |||
36 | Signed-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 | diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go | ||
42 | index 683ca6f..0ad082b 100644 | ||
43 | --- a/src/cmd/dist/build.go | ||
44 | +++ b/src/cmd/dist/build.go | ||
45 | @@ -41,6 +41,7 @@ var ( | ||
46 | goldflags string | ||
47 | workdir string | ||
48 | tooldir string | ||
49 | + build_tooldir string | ||
50 | oldgoos string | ||
51 | oldgoarch string | ||
52 | exe string | ||
53 | @@ -53,6 +54,7 @@ var ( | ||
54 | |||
55 | rebuildall bool | ||
56 | defaultclang bool | ||
57 | + crossBuild bool | ||
58 | |||
59 | vflag int // verbosity | ||
60 | ) | ||
61 | @@ -247,6 +249,8 @@ func xinit() { | ||
62 | if tooldir = os.Getenv("GOTOOLDIR"); tooldir == "" { | ||
63 | tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch) | ||
64 | } | ||
65 | + | ||
66 | + build_tooldir = pathf("%s/pkg/tool/native_native", goroot) | ||
67 | } | ||
68 | |||
69 | // compilerEnv returns a map from "goos/goarch" to the | ||
70 | @@ -478,8 +482,10 @@ func setup() { | ||
71 | p := pathf("%s/pkg/%s_%s", goroot, gohostos, gohostarch) | ||
72 | if rebuildall { | ||
73 | xremoveall(p) | ||
74 | + xremoveall(build_tooldir) | ||
75 | } | ||
76 | xmkdirall(p) | ||
77 | + xmkdirall(build_tooldir) | ||
78 | |||
79 | if goos != gohostos || goarch != gohostarch { | ||
80 | p := pathf("%s/pkg/%s_%s", goroot, goos, goarch) | ||
81 | @@ -1207,12 +1213,29 @@ func cmdbootstrap() { | ||
82 | |||
83 | var noBanner bool | ||
84 | var debug bool | ||
85 | + var hostOnly bool | ||
86 | + var targetOnly bool | ||
87 | + var toBuild = []string{"std", "cmd"} | ||
88 | + | ||
89 | flag.BoolVar(&rebuildall, "a", rebuildall, "rebuild all") | ||
90 | flag.BoolVar(&debug, "d", debug, "enable debugging of bootstrap process") | ||
91 | flag.BoolVar(&noBanner, "no-banner", noBanner, "do not print banner") | ||
92 | + flag.BoolVar(&hostOnly, "host-only", hostOnly, "build only host binaries, not target") | ||
93 | + flag.BoolVar(&targetOnly, "target-only", targetOnly, "build only target binaries, not host") | ||
94 | |||
95 | - xflagparse(0) | ||
96 | + xflagparse(-1) | ||
97 | |||
98 | + if hostOnly && targetOnly { | ||
99 | + fatalf("specify only one of --host-only or --target-only\n") | ||
100 | + } | ||
101 | + crossBuild = hostOnly || targetOnly | ||
102 | + if flag.NArg() > 0 { | ||
103 | + if crossBuild { | ||
104 | + toBuild = flag.Args() | ||
105 | + } else { | ||
106 | + fatalf("package names not permitted without --host-only or --target-only\n") | ||
107 | + } | ||
108 | + } | ||
109 | // Set GOPATH to an internal directory. We shouldn't actually | ||
110 | // need to store files here, since the toolchain won't | ||
111 | // depend on modules outside of vendor directories, but if | ||
112 | @@ -1266,8 +1289,13 @@ func cmdbootstrap() { | ||
113 | xprintf("\n") | ||
114 | } | ||
115 | |||
116 | - gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now | ||
117 | - goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now | ||
118 | + // For split host/target cross/cross-canadian builds, we don't | ||
119 | + // want to be setting these flags until after we have compiled | ||
120 | + // the toolchain that runs on the build host. | ||
121 | + if !crossBuild { | ||
122 | + gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now | ||
123 | + goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now | ||
124 | + } | ||
125 | goBootstrap := pathf("%s/go_bootstrap", tooldir) | ||
126 | cmdGo := pathf("%s/go", gobin) | ||
127 | if debug { | ||
128 | @@ -1296,7 +1324,11 @@ func cmdbootstrap() { | ||
129 | xprintf("\n") | ||
130 | } | ||
131 | xprintf("Building Go toolchain2 using go_bootstrap and Go toolchain1.\n") | ||
132 | - os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch)) | ||
133 | + if crossBuild { | ||
134 | + os.Setenv("CC", defaultcc[""]) | ||
135 | + } else { | ||
136 | + os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch)) | ||
137 | + } | ||
138 | goInstall(goBootstrap, append([]string{"-i"}, toolchain...)...) | ||
139 | if debug { | ||
140 | run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") | ||
141 | @@ -1333,50 +1365,84 @@ func cmdbootstrap() { | ||
142 | } | ||
143 | checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...) | ||
144 | |||
145 | - if goos == oldgoos && goarch == oldgoarch { | ||
146 | - // Common case - not setting up for cross-compilation. | ||
147 | - timelog("build", "toolchain") | ||
148 | - if vflag > 0 { | ||
149 | - xprintf("\n") | ||
150 | + if crossBuild { | ||
151 | + gogcflags = os.Getenv("GO_GCFLAGS") | ||
152 | + goldflags = os.Getenv("GO_LDFLAGS") | ||
153 | + tool_files, _ := filepath.Glob(pathf("%s/*", tooldir)) | ||
154 | + for _, f := range tool_files { | ||
155 | + copyfile(pathf("%s/%s", build_tooldir, filepath.Base(f)), f, writeExec) | ||
156 | + xremove(f) | ||
157 | + } | ||
158 | + os.Setenv("GOTOOLDIR", build_tooldir) | ||
159 | + goBootstrap = pathf("%s/go_bootstrap", build_tooldir) | ||
160 | + if hostOnly { | ||
161 | + timelog("build", "host toolchain") | ||
162 | + if vflag > 0 { | ||
163 | + xprintf("\n") | ||
164 | + } | ||
165 | + xprintf("Building %s for host, %s/%s.\n", strings.Join(toBuild, ","), goos, goarch) | ||
166 | + goInstall(goBootstrap, toBuild...) | ||
167 | + checkNotStale(goBootstrap, toBuild...) | ||
168 | + // Skip cmdGo staleness checks here, since we can't necessarily run the cmdGo binary | ||
169 | + | ||
170 | + timelog("build", "target toolchain") | ||
171 | + if vflag > 0 { | ||
172 | + xprintf("\n") | ||
173 | + } | ||
174 | + } else if targetOnly { | ||
175 | + goos = oldgoos | ||
176 | + goarch = oldgoarch | ||
177 | + os.Setenv("GOOS", goos) | ||
178 | + os.Setenv("GOARCH", goarch) | ||
179 | + os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch)) | ||
180 | + xprintf("Building %s for target, %s/%s.\n", strings.Join(toBuild, ","), goos, goarch) | ||
181 | + goInstall(goBootstrap, toBuild...) | ||
182 | + checkNotStale(goBootstrap, toBuild...) | ||
183 | + // Skip cmdGo staleness checks here, since we can't run the target's cmdGo binary | ||
184 | } | ||
185 | - xprintf("Building packages and commands for %s/%s.\n", goos, goarch) | ||
186 | } else { | ||
187 | - // GOOS/GOARCH does not match GOHOSTOS/GOHOSTARCH. | ||
188 | - // Finish GOHOSTOS/GOHOSTARCH installation and then | ||
189 | - // run GOOS/GOARCH installation. | ||
190 | - timelog("build", "host toolchain") | ||
191 | - if vflag > 0 { | ||
192 | - xprintf("\n") | ||
193 | - } | ||
194 | - xprintf("Building packages and commands for host, %s/%s.\n", goos, goarch) | ||
195 | + | ||
196 | + if goos == oldgoos && goarch == oldgoarch { | ||
197 | + // Common case - not setting up for cross-compilation. | ||
198 | + timelog("build", "toolchain") | ||
199 | + if vflag > 0 { | ||
200 | + xprintf("\n") | ||
201 | + } | ||
202 | + xprintf("Building packages and commands for %s/%s.\n", goos, goarch) | ||
203 | + } else { | ||
204 | + // GOOS/GOARCH does not match GOHOSTOS/GOHOSTARCH. | ||
205 | + // Finish GOHOSTOS/GOHOSTARCH installation and then | ||
206 | + // run GOOS/GOARCH installation. | ||
207 | + timelog("build", "host toolchain") | ||
208 | + if vflag > 0 { | ||
209 | + xprintf("\n") | ||
210 | + } | ||
211 | + xprintf("Building packages and commands for host, %s/%s.\n", goos, goarch) | ||
212 | + goInstall(goBootstrap, "std", "cmd") | ||
213 | + checkNotStale(goBootstrap, "std", "cmd") | ||
214 | + checkNotStale(cmdGo, "std", "cmd") | ||
215 | + | ||
216 | + timelog("build", "target toolchain") | ||
217 | + if vflag > 0 { | ||
218 | + xprintf("\n") | ||
219 | + } | ||
220 | + goos = oldgoos | ||
221 | + goarch = oldgoarch | ||
222 | + os.Setenv("GOOS", goos) | ||
223 | + os.Setenv("GOARCH", goarch) | ||
224 | + os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch)) | ||
225 | + xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch) | ||
226 | + } | ||
227 | goInstall(goBootstrap, "std", "cmd") | ||
228 | checkNotStale(goBootstrap, "std", "cmd") | ||
229 | checkNotStale(cmdGo, "std", "cmd") | ||
230 | |||
231 | - timelog("build", "target toolchain") | ||
232 | - if vflag > 0 { | ||
233 | - xprintf("\n") | ||
234 | + if debug { | ||
235 | + run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") | ||
236 | + run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch)) | ||
237 | + checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...) | ||
238 | + copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec) | ||
239 | } | ||
240 | - goos = oldgoos | ||
241 | - goarch = oldgoarch | ||
242 | - os.Setenv("GOOS", goos) | ||
243 | - os.Setenv("GOARCH", goarch) | ||
244 | - os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch)) | ||
245 | - xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch) | ||
246 | - } | ||
247 | - targets := []string{"std", "cmd"} | ||
248 | - if goos == "js" && goarch == "wasm" { | ||
249 | - // Skip the cmd tools for js/wasm. They're not usable. | ||
250 | - targets = targets[:1] | ||
251 | - } | ||
252 | - goInstall(goBootstrap, targets...) | ||
253 | - checkNotStale(goBootstrap, targets...) | ||
254 | - checkNotStale(cmdGo, targets...) | ||
255 | - if debug { | ||
256 | - run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") | ||
257 | - run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch)) | ||
258 | - checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...) | ||
259 | - copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec) | ||
260 | } | ||
261 | |||
262 | // Check that there are no new files in $GOROOT/bin other than | ||
263 | @@ -1393,8 +1459,11 @@ func cmdbootstrap() { | ||
264 | } | ||
265 | } | ||
266 | |||
267 | - // Remove go_bootstrap now that we're done. | ||
268 | - xremove(pathf("%s/go_bootstrap", tooldir)) | ||
269 | + // Except that for split host/target cross-builds, we need to | ||
270 | + // keep it. | ||
271 | + if !crossBuild { | ||
272 | + xremove(pathf("%s/go_bootstrap", tooldir)) | ||
273 | + } | ||
274 | |||
275 | if goos == "android" { | ||
276 | // Make sure the exec wrapper will sync a fresh $GOROOT to the device. | ||
277 | -- | ||
278 | 2.17.1 (Apple Git-112) | ||
279 | |||