Skip to content

Commit

Permalink
disable the use of cgo in packages "net" and "os/user"
Browse files Browse the repository at this point in the history
  • Loading branch information
0xe3b0c4 committed Aug 9, 2022
1 parent 066a8e5 commit 3f8f36b
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,12 @@ func doInstall(cmdline []string) {
tc.Root = build.DownloadGo(csdb, dlgoVersion)
}

// Disable CLI markdown doc generation in release builds.
buildTags := []string{"urfave_cli_no_docs"}

// Configure the build.
env := build.Env()
gobuild := tc.Go("build", buildFlags(env, *staticlink)...)
gobuild := tc.Go("build", buildFlags(env, *staticlink, buildTags)...)

// arm64 CI builders are memory-constrained and can't handle concurrent builds,
// better disable it. This check isn't the best, it should probably
Expand Down Expand Up @@ -246,7 +249,7 @@ func doInstall(cmdline []string) {
}

// buildFlags returns the go tool flags for building.
func buildFlags(env build.Environment, staticlink bool) (flags []string) {
func buildFlags(env build.Environment, staticLinking bool, buildTags []string) (flags []string) {
var ld []string
if env.Commit != "" {
ld = append(ld, "-X", "main.gitCommit="+env.Commit)
Expand All @@ -257,19 +260,26 @@ func buildFlags(env build.Environment, staticlink bool) (flags []string) {
if runtime.GOOS == "darwin" {
ld = append(ld, "-s")
}
// Enforce the stacksize to 8M, which is the case on most platforms apart from
// alpine Linux.
if runtime.GOOS == "linux" {
staticlinkflag := ""
if staticlink {
staticlinkflag = "-static"
staticflag := ""
if staticLinking {
staticflag = " -static"
// Under static linking, use of certain glibc features must be
// disabled to avoid shared library dependencies.
buildTags = append(buildTags, "osusergo", "netgo")
}
ld = append(ld, "-extldflags", fmt.Sprintf("' -Wl,-z,stack-size=0x800000 %s'", staticlinkflag))
// Enforce the stacksize to 8M, which is the case on most platforms apart from
// alpine Linux.
extflag := "'-Wl,-z,stack-size=0x800000" + staticflag + "'"
ld = append(ld, "-extldflags", extflag)
}

if len(ld) > 0 {
flags = append(flags, "-ldflags", strings.Join(ld, " "))
}
if len(buildTags) > 0 {
flags = append(flags, "-tags", strings.Join(buildTags, ","))
}
return flags
}

Expand Down

0 comments on commit 3f8f36b

Please sign in to comment.