[MacPorts] #60128: golang portgroup 1.0: add support for -ldflags

MacPorts noreply at macports.org
Tue Feb 25 07:59:20 UTC 2020


#60128: golang portgroup 1.0: add support for -ldflags
--------------------------+--------------------
 Reporter:  emcrisostomo  |      Owner:  (none)
     Type:  enhancement   |     Status:  new
 Priority:  Normal        |  Milestone:
Component:  base          |    Version:  2.6.2
 Keywords:                |       Port:
--------------------------+--------------------
 The {{{go build}}} command may optional specify linker flags using
 {{{-ldflags}}} that are passed to {{{go tool link}}}. I see two
 opportunities for improvements here: one, is to specify an additional
 variable to pass link variables, and the other is possibly adding
 additional support for {{{-X}}} flags.

 The basic issue here (as discussed briefly in https://github.com/macports
 /macports-ports/pull/6442), is that {{{-ldflags}}} have to be specified in
 {{{build.cmd}}}, where they are basically appended. If specified in
 {{{build.args}}}, the build fails because they're set after the
 {{{build.target}}}, while {{{go}}} expects them between the
 {{{build.cmd}}} and the {{{build.args}}}.

 Additionally, in Go it's idiomatic to set build-time variable through the
 {{{-X}}} link flag, resulting in multiple space-separated, quoted {{{-X}}}
 flags passed down as a single {{{-ldflags}}} argument, as in the
 referenced pull request:

 {{{
 build.cmd ${go.bin} build -ldflags \
         "\"-X
 github.com/docker/cli/cli/version.GitCommit=${docker_gitcommit} -X
 github.com/docker/cli/cli/version.Version=${version} -X
 \\\"github.com/docker/cli/cli/version.BuildTime=${build_time}\\\"\""
 }}}


 I suggest adding such support in the portgroup, to enable passing
 {{{ldflags}}} in a dedicated variable, and optionally offer some facility
 to simplify the resulting port syntax.

-- 
Ticket URL: <https://trac.macports.org/ticket/60128>
MacPorts <https://www.macports.org/>
Ports system for macOS


More information about the macports-tickets mailing list