summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/go/go/0005-cmd-dist-separate-host-and-target-builds.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/go/go/0005-cmd-dist-separate-host-and-target-builds.patch')
-rw-r--r--meta/recipes-devtools/go/go/0005-cmd-dist-separate-host-and-target-builds.patch282
1 files changed, 282 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go/0005-cmd-dist-separate-host-and-target-builds.patch b/meta/recipes-devtools/go/go/0005-cmd-dist-separate-host-and-target-builds.patch
new file mode 100644
index 0000000000..29598449da
--- /dev/null
+++ b/meta/recipes-devtools/go/go/0005-cmd-dist-separate-host-and-target-builds.patch
@@ -0,0 +1,282 @@
1From 7a191e5191c8b813e929caedb3f3918bb08692a1 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 5/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 | 152 +++++++++++++++++++++++++++++++-----------
39 1 file changed, 113 insertions(+), 39 deletions(-)
40
41diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
42index 5d31718..1c7f308 100644
43--- a/src/cmd/dist/build.go
44+++ b/src/cmd/dist/build.go
45@@ -44,6 +44,7 @@ var (
46 goexperiment string
47 workdir string
48 tooldir string
49+ build_tooldir string
50 oldgoos string
51 oldgoarch string
52 exe string
53@@ -55,6 +56,7 @@ var (
54 rebuildall bool
55 defaultclang bool
56 noOpt bool
57+ crossBuild bool
58
59 vflag int // verbosity
60 )
61@@ -267,6 +269,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@@ -468,8 +472,10 @@ func setup() {
71 goosGoarch := pathf("%s/pkg/%s_%s", goroot, gohostos, gohostarch)
72 if rebuildall {
73 xremoveall(goosGoarch)
74+ xremoveall(build_tooldir)
75 }
76 xmkdirall(goosGoarch)
77+ xmkdirall(build_tooldir)
78 xatexit(func() {
79 if files := xreaddir(goosGoarch); len(files) == 0 {
80 xremove(goosGoarch)
81@@ -1276,17 +1282,35 @@ func cmdbootstrap() {
82
83 var noBanner, noClean 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(&noClean, "no-clean", noClean, "print deprecation warning")
93+ flag.BoolVar(&hostOnly, "host-only", hostOnly, "build only host binaries, not target")
94+ flag.BoolVar(&targetOnly, "target-only", targetOnly, "build only target binaries, not host")
95
96- xflagparse(0)
97+ xflagparse(-1)
98
99 if noClean {
100 xprintf("warning: --no-clean is deprecated and has no effect; use 'go install std cmd' instead\n")
101 }
102
103+ if hostOnly && targetOnly {
104+ fatalf("specify only one of --host-only or --target-only\n")
105+ }
106+ crossBuild = hostOnly || targetOnly
107+ if flag.NArg() > 0 {
108+ if crossBuild {
109+ toBuild = flag.Args()
110+ } else {
111+ fatalf("package names not permitted without --host-only or --target-only\n")
112+ }
113+ }
114+
115 // Set GOPATH to an internal directory. We shouldn't actually
116 // need to store files here, since the toolchain won't
117 // depend on modules outside of vendor directories, but if
118@@ -1354,9 +1378,14 @@ func cmdbootstrap() {
119 xprintf("\n")
120 }
121
122- gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now
123- setNoOpt()
124- goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
125+ // For split host/target cross/cross-canadian builds, we don't
126+ // want to be setting these flags until after we have compiled
127+ // the toolchain that runs on the build host.
128+ if !crossBuild {
129+ gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now
130+ setNoOpt()
131+ goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
132+ }
133 goBootstrap := pathf("%s/go_bootstrap", tooldir)
134 cmdGo := pathf("%s/go", gorootBin)
135 if debug {
136@@ -1385,7 +1414,11 @@ func cmdbootstrap() {
137 xprintf("\n")
138 }
139 xprintf("Building Go toolchain2 using go_bootstrap and Go toolchain1.\n")
140- os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
141+ if crossBuild {
142+ os.Setenv("CC", defaultcc[""])
143+ } else {
144+ os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
145+ }
146 // Now that cmd/go is in charge of the build process, enable GOEXPERIMENT.
147 os.Setenv("GOEXPERIMENT", goexperiment)
148 goInstall(goBootstrap, toolchain...)
149@@ -1421,46 +1454,84 @@ func cmdbootstrap() {
150 copyfile(pathf("%s/compile3", tooldir), pathf("%s/compile", tooldir), writeExec)
151 }
152
153- if goos == oldgoos && goarch == oldgoarch {
154- // Common case - not setting up for cross-compilation.
155- timelog("build", "toolchain")
156- if vflag > 0 {
157- xprintf("\n")
158+ if crossBuild {
159+ gogcflags = os.Getenv("GO_GCFLAGS")
160+ goldflags = os.Getenv("GO_LDFLAGS")
161+ tool_files, _ := filepath.Glob(pathf("%s/*", tooldir))
162+ for _, f := range tool_files {
163+ copyfile(pathf("%s/%s", build_tooldir, filepath.Base(f)), f, writeExec)
164+ xremove(f)
165+ }
166+ os.Setenv("GOTOOLDIR", build_tooldir)
167+ goBootstrap = pathf("%s/go_bootstrap", build_tooldir)
168+ if hostOnly {
169+ timelog("build", "host toolchain")
170+ if vflag > 0 {
171+ xprintf("\n")
172+ }
173+ xprintf("Building %s for host, %s/%s.\n", strings.Join(toBuild, ","), goos, goarch)
174+ goInstall(goBootstrap, toBuild...)
175+ checkNotStale(goBootstrap, toBuild...)
176+ // Skip cmdGo staleness checks here, since we can't necessarily run the cmdGo binary
177+
178+ timelog("build", "target toolchain")
179+ if vflag > 0 {
180+ xprintf("\n")
181+ }
182+ } else if targetOnly {
183+ goos = oldgoos
184+ goarch = oldgoarch
185+ os.Setenv("GOOS", goos)
186+ os.Setenv("GOARCH", goarch)
187+ os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
188+ xprintf("Building %s for target, %s/%s.\n", strings.Join(toBuild, ","), goos, goarch)
189+ goInstall(goBootstrap, toBuild...)
190+ checkNotStale(goBootstrap, toBuild...)
191+ // Skip cmdGo staleness checks here, since we can't run the target's cmdGo binary
192 }
193- xprintf("Building packages and commands for %s/%s.\n", goos, goarch)
194 } else {
195- // GOOS/GOARCH does not match GOHOSTOS/GOHOSTARCH.
196- // Finish GOHOSTOS/GOHOSTARCH installation and then
197- // run GOOS/GOARCH installation.
198- timelog("build", "host toolchain")
199- if vflag > 0 {
200- xprintf("\n")
201+
202+ if goos == oldgoos && goarch == oldgoarch {
203+ // Common case - not setting up for cross-compilation.
204+ timelog("build", "toolchain")
205+ if vflag > 0 {
206+ xprintf("\n")
207+ }
208+ xprintf("Building packages and commands for %s/%s.\n", goos, goarch)
209+ } else {
210+ // GOOS/GOARCH does not match GOHOSTOS/GOHOSTARCH.
211+ // Finish GOHOSTOS/GOHOSTARCH installation and then
212+ // run GOOS/GOARCH installation.
213+ timelog("build", "host toolchain")
214+ if vflag > 0 {
215+ xprintf("\n")
216+ }
217+ xprintf("Building packages and commands for host, %s/%s.\n", goos, goarch)
218+ goInstall(goBootstrap, "std", "cmd")
219+ checkNotStale(goBootstrap, "std", "cmd")
220+ checkNotStale(cmdGo, "std", "cmd")
221+
222+ timelog("build", "target toolchain")
223+ if vflag > 0 {
224+ xprintf("\n")
225+ }
226+ goos = oldgoos
227+ goarch = oldgoarch
228+ os.Setenv("GOOS", goos)
229+ os.Setenv("GOARCH", goarch)
230+ os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
231+ xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch)
232 }
233- xprintf("Building packages and commands for host, %s/%s.\n", goos, goarch)
234 goInstall(goBootstrap, "std", "cmd")
235 checkNotStale(goBootstrap, "std", "cmd")
236 checkNotStale(cmdGo, "std", "cmd")
237
238- timelog("build", "target toolchain")
239- if vflag > 0 {
240- xprintf("\n")
241+ if debug {
242+ run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
243+ run("", ShowOutput|CheckExit, pathf("%s/buildid", tooldir), pathf("%s/pkg/%s_%s/runtime/internal/sys.a", goroot, goos, goarch))
244+ checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
245+ copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec)
246 }
247- goos = oldgoos
248- goarch = oldgoarch
249- os.Setenv("GOOS", goos)
250- os.Setenv("GOARCH", goarch)
251- os.Setenv("CC", compilerEnvLookup(defaultcc, goos, goarch))
252- xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch)
253- }
254- targets := []string{"std", "cmd"}
255- goInstall(goBootstrap, targets...)
256- checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
257- checkNotStale(goBootstrap, targets...)
258- checkNotStale(cmdGo, targets...)
259- if debug {
260- run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
261- checkNotStale(goBootstrap, append(toolchain, "runtime/internal/sys")...)
262- copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec)
263 }
264
265 // Check that there are no new files in $GOROOT/bin other than
266@@ -1477,8 +1548,11 @@ func cmdbootstrap() {
267 }
268 }
269
270- // Remove go_bootstrap now that we're done.
271- xremove(pathf("%s/go_bootstrap", tooldir))
272+ // Except that for split host/target cross-builds, we need to
273+ // keep it.
274+ if !crossBuild {
275+ xremove(pathf("%s/go_bootstrap", tooldir))
276+ }
277
278 if goos == "android" {
279 // Make sure the exec wrapper will sync a fresh $GOROOT to the device.
280--
2812.30.2
282