Opened 4 years ago

Last modified 21 months ago

#60128 new enhancement

golang portgroup 1.0: add support for -ldflags

Reported by: emcrisostomo (Enrico Maria Crisostomo) Owned by:
Priority: Normal Milestone:
Component: ports Version:
Keywords: portgroup Cc:
Port:

Description

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.

Change History (4)

comment:1 Changed 4 years ago by jmroot (Joshua Root)

Component: baseports
Version: 2.6.2

comment:2 Changed 4 years ago by emcrisostomo (Enrico Maria Crisostomo)

I just merged an update on another port (devel/dep) whose build script generates a very similar ldflags string and may benefit from the same changes in the golang portgroup.

comment:3 Changed 4 years ago by kencu (Ken)

there are also features like this

build.pre_args-prepend

These are a bit awkward perhaps, but may help you shoehorn flags in right where you want them to go, in certain cases.

Last edited 4 years ago by kencu (Ken) (previous) (diff)

comment:4 Changed 21 months ago by mascguy (Christopher Nielsen)

Keywords: portgroup added

Add keyword portgroup, to pg-related tickets

Note: See TracTickets for help on using tickets.