55
55
56
56
rebuildall bool
57
57
noOpt bool
58
+ isRelease bool
58
59
59
60
vflag int // verbosity
60
61
)
@@ -257,6 +258,9 @@ func xinit() {
257
258
xatexit (rmworkdir )
258
259
259
260
tooldir = pathf ("%s/pkg/tool/%s_%s" , goroot , gohostos , gohostarch )
261
+
262
+ goversion := findgoversion ()
263
+ isRelease = strings .HasPrefix (goversion , "release." ) || strings .HasPrefix (goversion , "go" )
260
264
}
261
265
262
266
// compilerEnv returns a map from "goos/goarch" to the
@@ -302,7 +306,7 @@ func compilerEnv(envName, def string) map[string]string {
302
306
303
307
// clangos lists the operating systems where we prefer clang to gcc.
304
308
var clangos = []string {
305
- "darwin" , // macOS 10.9 and later require clang
309
+ "darwin" , "ios" , // macOS 10.9 and later require clang
306
310
"freebsd" , // FreeBSD 10 and later do not ship gcc
307
311
"openbsd" , // OpenBSD ships with GCC 4.2, which is now quite old.
308
312
}
@@ -519,8 +523,6 @@ func setup() {
519
523
}
520
524
521
525
// Special release-specific setup.
522
- goversion := findgoversion ()
523
- isRelease := strings .HasPrefix (goversion , "release." ) || (strings .HasPrefix (goversion , "go" ) && ! strings .Contains (goversion , "beta" ))
524
526
if isRelease {
525
527
// Make sure release-excluded things are excluded.
526
528
for _ , dir := range unreleased {
@@ -529,20 +531,29 @@ func setup() {
529
531
}
530
532
}
531
533
}
532
- if isRelease || os .Getenv ("GO_BUILDER_NAME" ) != "" {
533
- // Add -trimpath for reproducible builds of releases.
534
- // Include builders so that -trimpath is well-tested ahead of releases.
535
- // Do not include local development, so that people working in the
536
- // main branch for day-to-day work on the Go toolchain itself can
537
- // still have full paths for stack traces for compiler crashes and the like.
538
- // toolenv = append(toolenv, "GOFLAGS=-trimpath")
539
- }
540
534
}
541
535
542
536
/*
543
537
* Tool building
544
538
*/
545
539
540
+ // mustLinkExternal is a copy of internal/platform.MustLinkExternal,
541
+ // duplicated here to avoid version skew in the MustLinkExternal function
542
+ // during bootstrapping.
543
+ func mustLinkExternal (goos , goarch string ) bool {
544
+ switch goos {
545
+ case "android" :
546
+ if goarch != "arm64" {
547
+ return true
548
+ }
549
+ case "ios" :
550
+ if goarch == "arm64" {
551
+ return true
552
+ }
553
+ }
554
+ return false
555
+ }
556
+
546
557
// deptab lists changes to the default dependencies for a given prefix.
547
558
// deps ending in /* read the whole directory; deps beginning with -
548
559
// exclude files with that prefix.
@@ -1266,14 +1277,33 @@ func timelog(op, name string) {
1266
1277
fmt .Fprintf (timeLogFile , "%s %+.1fs %s %s\n " , t .Format (time .UnixDate ), t .Sub (timeLogStart ).Seconds (), op , name )
1267
1278
}
1268
1279
1269
- // toolenv is the environment to use when building cmd.
1270
- // We disable cgo to get static binaries for cmd/go and cmd/pprof,
1271
- // so that they work on systems without the same dynamic libraries
1272
- // as the original build system.
1273
- // In release branches, we add -trimpath for reproducible builds.
1274
- // In the main branch we leave it off, so that compiler crashes and
1275
- // the like have full path names for easier navigation to source files.
1276
- var toolenv = []string {"CGO_ENABLED=0" }
1280
+ // toolenv returns the environment to use when building commands in cmd.
1281
+ //
1282
+ // This is a function instead of a variable because the exact toolenv depends
1283
+ // on the GOOS and GOARCH, and (at least for now) those are modified in place
1284
+ // to switch between the host and target configurations when cross-compiling.
1285
+ func toolenv () []string {
1286
+ var env []string
1287
+ if ! mustLinkExternal (goos , goarch ) {
1288
+ // Unless the platform requires external linking,
1289
+ // we disable cgo to get static binaries for cmd/go and cmd/pprof,
1290
+ // so that they work on systems without the same dynamic libraries
1291
+ // as the original build system.
1292
+ env = append (env , "CGO_ENABLED=0" )
1293
+ }
1294
+ if isRelease || os .Getenv ("GO_BUILDER_NAME" ) != "" {
1295
+ // Add -trimpath for reproducible builds of releases.
1296
+ // Include builders so that -trimpath is well-tested ahead of releases.
1297
+ // Do not include local development, so that people working in the
1298
+ // main branch for day-to-day work on the Go toolchain itself can
1299
+ // still have full paths for stack traces for compiler crashes and the like.
1300
+ //
1301
+ // TODO(bcmills): This was added but commented out in CL 454836.
1302
+ // Uncomment or delete it.
1303
+ // env = append(env, "GOFLAGS=-trimpath")
1304
+ }
1305
+ return env
1306
+ }
1277
1307
1278
1308
var toolchain = []string {"cmd/asm" , "cmd/cgo" , "cmd/compile" , "cmd/link" }
1279
1309
@@ -1414,7 +1444,7 @@ func cmdbootstrap() {
1414
1444
os .Setenv ("CC" , compilerEnvLookup ("CC" , defaultcc , goos , goarch ))
1415
1445
// Now that cmd/go is in charge of the build process, enable GOEXPERIMENT.
1416
1446
os .Setenv ("GOEXPERIMENT" , goexperiment )
1417
- goInstall (toolenv , goBootstrap , toolchain ... )
1447
+ goInstall (toolenv () , goBootstrap , toolchain ... )
1418
1448
if debug {
1419
1449
run ("" , ShowOutput | CheckExit , pathf ("%s/compile" , tooldir ), "-V=full" )
1420
1450
copyfile (pathf ("%s/compile2" , tooldir ), pathf ("%s/compile" , tooldir ), writeExec )
@@ -1441,7 +1471,7 @@ func cmdbootstrap() {
1441
1471
xprintf ("\n " )
1442
1472
}
1443
1473
xprintf ("Building Go toolchain3 using go_bootstrap and Go toolchain2.\n " )
1444
- goInstall (toolenv , goBootstrap , append ([]string {"-a" }, toolchain ... )... )
1474
+ goInstall (toolenv () , goBootstrap , append ([]string {"-a" }, toolchain ... )... )
1445
1475
if debug {
1446
1476
run ("" , ShowOutput | CheckExit , pathf ("%s/compile" , tooldir ), "-V=full" )
1447
1477
copyfile (pathf ("%s/compile3" , tooldir ), pathf ("%s/compile" , tooldir ), writeExec )
@@ -1470,9 +1500,9 @@ func cmdbootstrap() {
1470
1500
xprintf ("\n " )
1471
1501
}
1472
1502
xprintf ("Building commands for host, %s/%s.\n " , goos , goarch )
1473
- goInstall (toolenv , goBootstrap , "cmd" )
1474
- checkNotStale (toolenv , goBootstrap , "cmd" )
1475
- checkNotStale (toolenv , gorootBinGo , "cmd" )
1503
+ goInstall (toolenv () , goBootstrap , "cmd" )
1504
+ checkNotStale (toolenv () , goBootstrap , "cmd" )
1505
+ checkNotStale (toolenv () , gorootBinGo , "cmd" )
1476
1506
1477
1507
timelog ("build" , "target toolchain" )
1478
1508
if vflag > 0 {
@@ -1486,15 +1516,15 @@ func cmdbootstrap() {
1486
1516
xprintf ("Building packages and commands for target, %s/%s.\n " , goos , goarch )
1487
1517
}
1488
1518
goInstall (nil , goBootstrap , "std" )
1489
- goInstall (toolenv , goBootstrap , "cmd" )
1490
- checkNotStale (toolenv , goBootstrap , append (toolchain , "runtime/internal/sys" )... )
1519
+ goInstall (toolenv () , goBootstrap , "cmd" )
1520
+ checkNotStale (toolenv () , goBootstrap , append (toolchain , "runtime/internal/sys" )... )
1491
1521
checkNotStale (nil , goBootstrap , "std" )
1492
- checkNotStale (toolenv , goBootstrap , "cmd" )
1522
+ checkNotStale (toolenv () , goBootstrap , "cmd" )
1493
1523
checkNotStale (nil , gorootBinGo , "std" )
1494
- checkNotStale (toolenv , gorootBinGo , "cmd" )
1524
+ checkNotStale (toolenv () , gorootBinGo , "cmd" )
1495
1525
if debug {
1496
1526
run ("" , ShowOutput | CheckExit , pathf ("%s/compile" , tooldir ), "-V=full" )
1497
- checkNotStale (toolenv , goBootstrap , append (toolchain , "runtime/internal/sys" )... )
1527
+ checkNotStale (toolenv () , goBootstrap , append (toolchain , "runtime/internal/sys" )... )
1498
1528
copyfile (pathf ("%s/compile4" , tooldir ), pathf ("%s/compile" , tooldir ), writeExec )
1499
1529
}
1500
1530
0 commit comments