1.\" $OpenBSD: go-module.5,v 1.4 2021/07/25 11:29:42 espie Exp $ 2.\" 3.\" Copyright (c) 2008 Marc Espie 4.\" 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd $Mdocdate: July 25 2021 $ 28.Dt GO-MODULE 5 29.Os 30.Sh NAME 31.Nm go-module 32.Nd lang/go port module 33.Sh DESCRIPTION 34This manual page documents the behavior of setting 35.Li MODULES=lang/go 36in the 37.Xr ports 7 38tree. 39.Pp 40Adds Go toolchain support. 41Requires 42.Ev ALL_TARGET 43to be set to canonical Go import path of port. 44(Module sets it automatically for ports that use 45.Ev GH_ACCOUNT 46and 47.Ev GH_PROJECT 48macros.) 49.Pp 50During execution of 51.Cm pre-configure 52target module moves source code from 53.Pa ${MODGO_SUBDIR} 54to 55.Pa ${WRKSRC} , 56subdirectory of 57.Pa ${MODGO_WORKSPACE} 58- specially-crafted Go workspace located at 59.Pa ${WRKDIR}/go . 60During 61.Cm do-build 62module calls 63.Dq go install 64with 65.Ev GOPATH 66set to 67.Pa ${MODGO_WORKSPACE} , 68runs its output through sed to prevent writes outside 69.Ev WRKDIR 70sandbox and sends output to 71.Xr sh 1 . 72During 73.Cm do-install 74it copies executables from 75.Pa ${MODGO_WORKSPACE}/bin 76to 77.Pa ${PREFIX}/bin , 78and/or directories 79.Pa ${MODGO_WORKSPACE}/pkg 80and 81.Pa ${MODGO_WORKSPACE}/src 82to 83.Pa ${PREFIX}/go , 84depending on 85.Ev MODGO_TYPE 86contents. 87.Pp 88Sets 89.Ev BUILD_DEPENDS , 90.Ev RUN_DEPENDS , 91.Ev ALL_TARGET , 92.Ev TEST_TARGET , 93.Ev ONLY_FOR_ARCHS , 94.Ev SEPARATE_BUILD , 95and 96.Ev WRKSRC . 97.Pp 98Appends to 99.Ev CATEGORIES . 100.Pp 101Defines: 102.Bl -tag -width MODGO_WORKSPACE 103.It Ev MODGO_TYPE 104Type of port. 105May be any combination of: 106.Bl -tag -width lib 107.It bin 108ordinary binary, which should be installed to 109.Pa ${PREFIX}/bin , 110.It lib 111library, which should come with source code. 112.El 113.Pp 114Defaults to 115.Ar bin . 116.It Ev MODGO_WORKSPACE 117Path to Go workspace set up for port build process. 118Defaults to 119.Pa ${WRKDIR}/go . 120See Go documentation for details. 121.It Ev MODGO_SUBDIR 122Path to Go source code within port's sources tarball. 123Defaults to 124.Pa ${WRKDIST} . 125.It Ev MODGO_SETUP_WORKSPACE 126Commands setting up Go workspace for building ports. 127By default, happens during execution of 128.Cm pre-configure 129target. 130.It Ev MODGO_BUILDDEP 131Controls whether contents of 132.Ev MODGO_BUILD_DEPENDS 133are appended to port's 134.Ev BUILD_DEPENDS . 135Defaults to 136.Ar Yes . 137.It Ev MODGO_MODNAME 138Name of Go module as defined in the 139.Pa go.mod 140file contained in a project. 141If this is set, 142.Ev MODGO_MODULES , 143.Ev MODGO_MODFILES 144and 145.Ev MODGO_VERSION 146need to be defined as well. 147Setting this will also set 148.Ev ALL_TARGET . 149When 150.Ev MODGO_MODFILES 151is set, and a "cmd" directory is found in 152.Ev WRKSRC , 153"./cmd/..." is also built by 154.Cm do-build 155automatically. 156.It Ev MODGO_VERSION 157Sets the specific version of a Go module to use. 158For example: v0.1.3. 159.It Ev MODGO_MODULES 160List of modules and their specific versions that an application depends on. 161.It Ev MODGO_MODFILES 162List of go.mod files and their versions that are required for dependency 163resolution. 164These are required by Go to determine the full dependency graph. 165.El 166.Pp 167Additionally defines 168.Ev MODGO_PACKAGES , 169.Ev MODGO_SOURCES 170and 171.Ev MODGO_TOOLS 172(paths for installed Go packages, sources and tools respectively), 173.Ev MODGO_CMD 174and 175.Ev MODGO_FLAGS 176(source code build command and flags passed as its arguments), 177.Ev MODGO_LDFLAGS , 178.Ev MODGO_BUILD_CMD 179and 180.Ev MODGO_TEST_CMD 181(commands for building and testing go packages; normally called with canonical 182Go package names as arguments), 183.Ev MODGO_{BUILD,INSTALL,TEST}_TARGET 184and 185.Ev MODGO_{BUILD,RUN}_DEPENDS . 186.Pp 187This module adds one 188.Xr make 1 189target: 190.Bl -tag -width modgo-gen-modules 191.It Cm modgo-gen-modules 192Generate the 193.Ev MODGO_MODULES 194and the 195.Ev MODGO_MODFILES 196lists. 197If 198.Ev MODGO_VERSION 199is set to "latest", the latest known-to-Go version of a package will be used 200to build the list of modules. 201Similarly, if 202.Ev MODGO_VERSION 203is empty, the latest version will be fetched. 204.El 205.Sh SEE ALSO 206.Xr port-modules 5 207