Opened 12 months ago

Last modified 10 months ago

#68340 new defect

go @1.17.13_0: environment variables for olders macOS versions cause bash to print "wrong substitution" and thus compiles fail.

Reported by: garoffoli (garoffoli) Owned by:
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc: RobK88, tehcog (tehcog)
Port: go

Description

I've installed Go on my Mac running 10.9.5, after the install the follow message appears:

go has the following notes:
    Please note: Go 1.21 does not build on macOS 10.12 and older, so Go 1.17.13
    has been installed.
    go had to be specially patched and built to work on your platform.

    It likely won't work out of the box when building other projects, so make
    sure change your environment to use the following variables:
      * GO_EXTLINK_ENABLED="1"
    to always force go to use the external gcc or clang linker and
      * GO_LDFLAGS="\"-extldflags=${configure.ldflags}\""
      * CGO_LDFLAGS="-g -O2 ${configure.ldflags}"
    to force-link any binary against the legacy support library. Use exactly the
    quoting provided here, even if it may look odd, or compilation will fail.

    Failure to do so will leave you unable to create binaries that use features
    not natively available on your system, either directly or through a go core
    dependency.

However, when i copy the environment variables in .profiles. Bash throws up this error:

-bash: "-extldflags=${configure.ldflags}": wrong substitution
-bash: -g -O2 ${configure.ldflags}: wrong substitution

And because of this, i can't even compile a simple Hello World executable. (I attached the build log)

Attachments (1)

buildlog.log (5.9 KB) - added by garoffoli (garoffoli) 12 months ago.
Build Log

Download all attachments as: .zip

Change History (11)

Changed 12 months ago by garoffoli (garoffoli)

Attachment: buildlog.log added

Build Log

comment:1 Changed 12 months ago by garoffoli (garoffoli)

Summary: go @1.17.13_0: environmental variables for olders macOS versions cause bash to print "wrong substitution" and thus compiles fail.go @1.17.13_0: environment variables for olders macOS versions cause bash to print "wrong substitution" and thus compiles fail.

comment:2 Changed 12 months ago by kencu (Ken)

the instructions don’t say it explicitly, but they are for Portfile additions, not for bash .profile additions.

comment:3 in reply to:  2 Changed 12 months ago by garoffoli (garoffoli)

Replying to kencu:

the instructions don’t say it explicitly, but they are for Portfile additions, not for bash .profile additions.

How I can do that? Try to set these variables using

go env -w CGO_LDFLAGS="-g -O2 ${configure.ldflags}"

still gives a wrong substitution error

comment:4 Changed 10 months ago by RobK88

@garoffoli - You will get a substitution error when running go env -w CGO_LDFLAGS="-g -O2 ${configure.ldflags}" in bash since ${configure.ldflags} is NOT defined in bash.

${configure.ldflags} is defined in MacPorts. When you set CGO_LDFLAGS="-g -O2 ${configure.ldflags}"in a Portfile, the environment variable will be set properly by MacPorts since Macports knows the value for ${configure.ldflags}. Bash does not.

comment:5 Changed 10 months ago by RobK88

@garoffoli - Here is an example of setting these environment variables in a Portfile for a go program. One would include this code block in the Portfile:

pre-build {
#   Sierra and earlier
    if { ${os.platform} eq "darwin" && ${os.major} < 17 } {
        build.env-append    GO_EXTLINK_ENABLED="1" \
                            GO_LDFLAGS="\"-extldflags=${configure.ldflags}\"" \
                            CGO_LDFLAGS="-g -O2 ${configure.ldflags}"
    }
}

depends_build-append    port:legacy-support

Make sure you add the legacy-support port as a build dependency.

Version 6, edited 10 months ago by RobK88 (previous) (next) (diff)

comment:6 Changed 10 months ago by RobK88

I also have seen code written like this:

PortGroup           legacysupport 1.1

legacysupport.newest_darwin_requires_legacy 16

pre-build {
#   Sierra and earlier
    if {${os.platform} eq "darwin" && ${os.major} <= ${legacysupport.newest_darwin_requires_legacy}} {
        build.env-append    GO_EXTLINK_ENABLED="1" \
                            GO_LDFLAGS="\"-extldflags=${configure.ldflags}\"" \
                            CGO_LDFLAGS="-g -O2 ${configure.ldflags}"
    }
}
Last edited 10 months ago by RobK88 (previous) (diff)

comment:7 Changed 10 months ago by RobK88

Cc: RobK88 added

comment:8 Changed 10 months ago by RobK88

P.S. The sample code above will not help you at this time. There is another problem! The legacy go compiler, @1.7.13, that runs on Lion, Mtn Lion etc is now completely broken.

See https://trac.macports.org/ticket/68700

Last edited 10 months ago by RobK88 (previous) (diff)

comment:9 Changed 10 months ago by tehcog (tehcog)

I haven't been able to get anything that uses 'go' to upgrade for quite some time now on Mavericks (exa: [66296 https://trac.macports.org/ticket/66296], fzf: [66295 https://trac.macports.org/ticket/66295]). Looks like the same may be becomming true with rust as well ([68719 https://trac.macports.org/ticket/68719]). I can understand google breaking everything as it is now to be expected, but Et tu, Rust? o_0

comment:10 Changed 10 months ago by tehcog (tehcog)

Cc: tehcog added
Note: See TracTickets for help on using tickets.