Skip to content

Commit

Permalink
Force DEV=0 when cross-compiling to darwin/amd64 (#32274)
Browse files Browse the repository at this point in the history
* Force DEV=0 when cross compiling for darwin/amd64.

elastic/golang-crossbuild#217

* Revert "Revert "Fix flags for dev build (#31955)" (#32250)"

This reverts commit ba5d0cb.
  • Loading branch information
cmacknz authored and chrisberkhout committed Jun 1, 2023
1 parent f8dde5f commit 232761b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Avoid panicking in `add_fields` processor when input event.Fields is a nil map. {pull}28219[28219]
- Drop event batch when get HTTP status 413 from Elasticsearch to avoid infinite loop {issue}14350[14350] {pull}29368[29368]
- Allow to use metricbeat for named mssql instances. {issue}24076[24076] {pull}30859[30859]
- Setting DEV=true when running `mage build` now correctly generates binaries without optimisations and with debug symbols {pull}31955[31955]

==== Added

Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func DefaultBuildArgs() BuildArgs {

if DevBuild {
// Disable optimizations (-N) and inlining (-l) for debugging.
args.ExtraFlags = append(args.ExtraFlags, `-gcflags`, `"all=-N -l"`)
args.ExtraFlags = append(args.ExtraFlags, `-gcflags=all=-N -l`)
} else {
// Strip all debug symbols from binary (does not affect Go stack traces).
args.LDFlags = append(args.LDFlags, "-s")
Expand Down
8 changes: 7 additions & 1 deletion dev-tools/mage/crossbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,19 @@ func (b GolangCrossBuilder) Build() error {
args = append(args, "-v", hostDir+":/go/pkg/mod:ro")
}

if b.Platform == "darwin/amd64" {
fmt.Printf(">> %v: Forcing DEV=0 for %s: https://github.com/elastic/golang-crossbuild/issues/217\n", b.Target, b.Platform)
args = append(args, "--env", "DEV=0")
} else {
args = append(args, "--env", fmt.Sprintf("DEV=%v", DevBuild))
}

args = append(args,
"--rm",
"--env", "GOFLAGS=-mod=readonly",
"--env", "MAGEFILE_VERBOSE="+verbose,
"--env", "MAGEFILE_TIMEOUT="+EnvOr("MAGEFILE_TIMEOUT", ""),
"--env", fmt.Sprintf("SNAPSHOT=%v", Snapshot),
"--env", fmt.Sprintf("DEV=%v", DevBuild),
"-v", repoInfo.RootDir+":"+mountPoint,
"-w", workDir,
image,
Expand Down

0 comments on commit 232761b

Please sign in to comment.