Golang
This document explains how to use the golang and golangmodules declarative build systems when packaging for openRuyi.
In general, for Go library packages, most of the packaging content can be generated by automation tools, with little or no manual work required.
Dependencies
To use the golang or golangmodules build system, add the following BuildRequires:
BuildRequires: go
BuildRequires: go-rpm-macros
Required macros
At a minimum, you should define _name and go_import_path near the top of the spec file. The former is typically the Go library's name, while the latter is usually its import path.
Examples
Both the golang and golangmodules build systems can directly use the same common %prep configuration:
BuildOption(prep): -n %{_name}-%{version}
Packaging library-only content
In most cases, library packaging does not require compilation. Therefore, the golangmodules build system already includes the necessary %install and %check logic.
If additional test arguments are needed, you can specify them as follows:
BuildOption(check): -vet=off -short
Packaging binaries together with libraries
Depending on the package, you may choose either the golang or golangmodules build system. If you need functionality provided by the other build system, you can invoke it directly.
For example, when packaging this type of software with the golangmodules build system, it also needs to build and install binaries:
# Build binaries for tools
%build
%go_common
cd %{_builddir}/go/src/%{go_import_path}
go install -trimpath -v -p %{?_smp_build_ncpus} ./cmd/...
# Install binaries for tools
%install -a
install -d %{buildroot}%{_bindir}
install -m 0755 %{_builddir}/go/bin/* %{buildroot}%{_bindir}/
Conversely, if you're using the golang build system for such a package, but also need to install the Go library source code:
# This is for the source package
%install -a
%buildsystem_golangmodules_install
Build system macro files
The macro files for the two Go build systems are:
-
/usr/lib/rpm/macros.d/macros.buildsystem.golang -
/usr/lib/rpm/macros.d/macros.buildsystem.golangmodules