Go package guidelines

This document covers standards and guidelines on writing PKGBUILDs for Go.

Arch package guidelines

32-bitCLRCMakeCrossDKMSEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernelLispMesonMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRustShellVCSWebWine

General guidelines

Package naming

For Go library modules, use golang-modulename. Also use the prefix if the package provides a program that is strongly coupled to the Go ecosystem. For other applications, use only the program name.

Note: The package name should be entirely lowercase.

Building

Dependencies

Go 1.11 introduced the initial support for go modules. This allows Go upstream code to declare dependencies and pin them to the given project version. Currently our packaging efforts utilize this to vendor dependencies.

Upstream project without go modules

For upstream code that does not utilise Go modules, the following workaround exists. Consider filing an issue upstream.

PKGBUILD
url=https://github.com/upstream_user/upstream_project

prepare() {
  cd "$pkgname-$pkgver"
  go mod init "${url#https://}" # strip https:// from canonical URL
  go mod tidy
}
Note: Any such hacks makes the package unreproducible as modules will change between package builds.

Flags and build options

Most Makefiles written for go applications do not respect the build flags provided by build systems along with overwriting GOFLAGS, this causes Go binaries to not be compiled with RELRO as we need CGO_CFLAGS and CGO_LDFLAGS to be set for the compiler. This needs to be patched into the Makefile, or the Makefile should be omitted.

Flag meaning

  • enables PIE compilation for binary harderning.
  • important for reproducible builds so full build paths and module paths are not embedded.
  • ensure the module files are not updated in any go actions.
  • is not important, but it ensures that go modules creates a write-able path. Default is read-only.

Output directory

There are currently a few ways to build all go binaries in a project.

build(){
    cd "$pkgname-$pkgver"
    go build -o output-binary .
}

... is a shorthand for the compiler to recursively descend into the directory and find all binaries. It can be used in conjunction with a output directory to build everything.

Example packages

gollark: I managed to get a 3G PB prize IOU for a 3G prize from CB prize. That was a weird day.
gollark: Via madness, there are actually 3G PB prizes in existence.
gollark: If you particularly care it's probably possible to get something more compact than JSON, but I guess that usually won't matter.
gollark: Well, obviously.
gollark: I know it in that I know the syntax and semantics of that syntax, and concepts up to about "monad", but not the fancy stuff like you'd see on /r/haskell.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.