Packaging golang for secondary architectures, go-srpm-macros

Jan Chaloupka jchaloup at
Thu Jul 9 09:18:35 UTC 2015


at the moment golang packages are built only on primary architectures 
(defined by %go_arches macro) due to golang compiler architecture 
support. For secondary architectures gcc-go is available. In order to 
provide an easy way for packagers to package golang projects for 
secondary architectures as well, go-srpm-macros packages is introduced. 
It provides basic macros that can be used within spec files. Currently 
golang package ships /usr/lib/rpm/macros.d/macros.golang file, which 
defines %gopath and %go_arches macros. As secondary architectures has no 
golang package these macros are not available. Thus I am proposing to 
move these macros to go-srpm-macros package and provide additional ones:

# Define arches for PA and SA
%golang_arches   %{ix86} x86_64 %{arm}
%gccgo_arches    %{power64} s390x aarch64
%go_arches       %{golang_arches} %{gccgo_arches}

# Where to set GOPATH for builds
%gopath          %{_datadir}/gocode

# Minimal version of gcc providing gcc-go
%gccgo_min_vers  5.0.0

# Define commands for building
%golang_build    go build -compiler gc
%gcc_go_build    go build -compiler gccgo -gccgoflags "$RPM_OPT_FLAGS"

# Define commands for testing
%golang_test     go test -compiler gc
%gcc_go_test     go test -compiler gccgo -gccgoflags "$RPM_OPT_FLAGS"

Meaning of %golang_arches and %gccgo_arches is obvious. %go_arches is 
extended for secondary architectures. Spec files using %go_arches macros 
will not get touched by this change as it takes effect only on secondary 
architectures. %golang_build, resp. %golang_test and %gcc_go_build, 
resp. %gcc_go_test macros provides an easy way to run go build, resp. go 
test commands for golang and gcc-go compiler without typing the minimal 
list of options. The reason to define %golang_build and %gcc_go_build 
instead of %go_build for both compilers is to cover a case when gcc-go 
and golang have a different set of options. So packagers are aware of 
which compiler/command they use for building. The same holds for the 'go 
test' command.

Recommended use in spec file:
1) To choose the correct compiler:
%ifarch %{golang_arches}
BuildRequires: golang
BuildRequires: gcc-go >= %{gccgo_min_vers}

2) To choose the correct command for building and testing:
%ifarch %{golang_arches}
%{golang_build} -o bin/binary %{import_path}/binary
%{golang_test} %{import_path}/binary
%{gcc_go_build} -o bin/binary %{import_path}/binary
%{gcc_go_test} %{import_path}/binary

At the same time packaging guidelines for golang will be extended to 
provide information about secondary architectures.

What are the steps to accomplish this task?
1) finish review of go-srpm-macros [1]
2) add go-srpm-macros as a run-time dependency of redhat-rpm-config for 
f21-f23 and el6
3) remove /usr/lib/rpm/macros.d/macros.golang from golang
4) update packaging guidelines

I will fill all necessary bugs/tickets if needed and update packaging 

Florian, I would like to make go-srpm-macros a run-time dependency of 
redhat-rpm-config. Thus I believe go-srpm-macros needs an extra caution 
so it does not break minimal buildroot. Can you check out the 
macros.go-srpm file in the package [1]? The file define only one line 
macros, no %if nor %ifarch.


Any feedback and questions are welcomed and appreciated.

Thanks to all involved in helping us.

Kind Regards
Jan Chaloupka

More information about the devel mailing list