1 |
On Wed, Sep 11, 2019 at 05:28:22PM -0700, Alec Warner wrote: |
2 |
> On Wed, Sep 11, 2019 at 5:05 PM William Hubbs <williamh@g.o> wrote: |
3 |
> |
4 |
> > On Wed, Sep 11, 2019 at 04:31:00PM -0700, Alec Warner wrote: |
5 |
> > > On Wed, Sep 11, 2019 at 10:28 AM William Hubbs <williamh@g.o> |
6 |
> > wrote: |
7 |
> > > |
8 |
> > > > Copyright: Sony Interactive Entertainment Inc. |
9 |
> > > > Signed-off-by: William Hubbs <williamh@g.o> |
10 |
> > > > --- |
11 |
> > > > eclass/go-module.eclass | 76 +++++++++++++++++++++++++++++++++++++++++ |
12 |
> > > > 1 file changed, 76 insertions(+) |
13 |
> > > > create mode 100644 eclass/go-module.eclass |
14 |
> > > > |
15 |
> > > > diff --git a/eclass/go-module.eclass b/eclass/go-module.eclass |
16 |
> > > > new file mode 100644 |
17 |
> > > > index 00000000000..7009fcd3beb |
18 |
> > > > --- /dev/null |
19 |
> > > > +++ b/eclass/go-module.eclass |
20 |
> > > > @@ -0,0 +1,76 @@ |
21 |
> > > > +# Copyright 1999-2015 Gentoo Foundation |
22 |
> > > > +# Distributed under the terms of the GNU General Public License v2 |
23 |
> > > > + |
24 |
> > > > +# @ECLASS: go-module.eclass |
25 |
> > > > +# @MAINTAINER: |
26 |
> > > > +# William Hubbs <williamh@g.o> |
27 |
> > > > +# @SUPPORTED_EAPIS: 7 |
28 |
> > > > +# @BLURB: basic eclass for building software written in the go |
29 |
> > > > +# programming language that uses go modules. |
30 |
> > > > +# @DESCRIPTION: |
31 |
> > > > +# This eclass provides a convenience src_prepare() phase and some |
32 |
> > basic |
33 |
> > > > +# settings needed for all software written in the go programming |
34 |
> > > > +# language that uses go modules. |
35 |
> > > > +# |
36 |
> > > > +# You will know the software you are packaging uses modules because |
37 |
> > > > +# it will have files named go.sum and go.mod in its top-level source |
38 |
> > > > +# directory. If it does not have these files, use the golang-* |
39 |
> > eclasses. |
40 |
> > > > +# |
41 |
> > > > +# If the software you are packaging uses modules, the next question is |
42 |
> > > > +# whether it has a directory named "vendor" at the top-level of the |
43 |
> > > > source tree. |
44 |
> > > > +# |
45 |
> > > > +# If it doesn't, you need to create a tarball of what would be in the |
46 |
> > > > +# vendor directory and mirror it locally. This is done with the |
47 |
> > > > +# following commands if upstream is using a git repository: |
48 |
> > > > +# |
49 |
> > > > +# @CODE: |
50 |
> > > > +# |
51 |
> > > > +# $ cd /my/clone/of/upstream |
52 |
> > > > +# $ git checkout <release> |
53 |
> > > > +# $ go mod vendor |
54 |
> > > > +# $ tar cvf project-version-vendor.tar.gz vendor |
55 |
> > > > +# |
56 |
> > > > +# @CODE: |
57 |
> > > > +# |
58 |
> > > > +# Other than this, all you need to do is inherit this eclass then |
59 |
> > > > +# make sure the exported src_prepare function is run. |
60 |
> > > > + |
61 |
> > > > +case ${EAPI:-0} in |
62 |
> > > > + 7) ;; |
63 |
> > > > + *) die "${ECLASS} API in EAPI ${EAPI} not yet established." |
64 |
> > > > +esac |
65 |
> > > > + |
66 |
> > > > +if [[ -z ${_GO_MODULE} ]]; then |
67 |
> > > > + |
68 |
> > > > +_GO_MODULE=1 |
69 |
> > > > + |
70 |
> > > > +BDEPEND=">=dev-lang/go-1.12" |
71 |
> > > > + |
72 |
> > > > +# Do not download dependencies from the internet |
73 |
> > > > +# make build output verbose by default |
74 |
> > > > +export GOFLAGS="-mod=vendor -v -x" |
75 |
> > > > + |
76 |
> > > > +# Do not complain about CFLAGS etc since go projects do not use them. |
77 |
> > > > +QA_FLAGS_IGNORED='.*' |
78 |
> > > > + |
79 |
> > > > +# Upstream does not support stripping go packages |
80 |
> > > > +RESTRICT="strip" |
81 |
> > > > |
82 |
> > > |
83 |
> > > https://golang.org/cmd/link/ implies you can pass -s -w to the compiler |
84 |
> > to |
85 |
> > > reduce binary size. |
86 |
> > > |
87 |
> > > Does that not work in portage by default, or does upstream just consider |
88 |
> > > that bad practice? |
89 |
> > |
90 |
> > I haven't tried it, but here are the definitions of -s and -w. |
91 |
> > |
92 |
> > -s Omit the symbol table and debug information. |
93 |
> > -w Omit the DWARF symbol table. |
94 |
> > |
95 |
> > These look like Go's equivalent of stripping the binaries, and I have my |
96 |
> > doubts as to whether we should force this. |
97 |
> > |
98 |
> |
99 |
> I don't care if you strip or not (I'm not even sure portage knows how to do |
100 |
> it for go binaries) but I'm fairly sure the reason isn't because "upstream |
101 |
> does not support stripping go binaries" because they clearly do...unless |
102 |
> upstream is portage here...? |
103 |
|
104 |
Well, go binaries aren't supposed to be stripped using strip(1), which |
105 |
is how portage strips binaries. You strip go binaries by passing -s and |
106 |
-w to ldflags, so it has to be done during the build. |
107 |
|
108 |
In order to do it right I would have to have a pms-compatible way to |
109 |
check restrictions/features, and there isn't one that I'm aware of. |
110 |
|
111 |
If there is a way to do this, I'm all ears, or I can update the comment |
112 |
in the eclass. |
113 |
|
114 |
William |