Skip to content

Commit aac6a82

Browse files
committed
Build custom go version from source
1 parent 4f1820f commit aac6a82

File tree

2 files changed

+57
-11
lines changed

2 files changed

+57
-11
lines changed

Dockerfile

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ ENV NDK_VER="27.2.12479018"
2020
# GoLang conf
2121
## Go version & hash from https://go.dev/dl/ (Hash from Archive Linux x86-64) : debian bullseye provides go1.15.15, which can only build go source up to go 1.19
2222
ENV GOLANG_VERSION=1.23.5
23-
ENV GOLANG_SHA256=cbcad4a6482107c7c7926df1608106c189417163428200ce357695cc7e01d091
23+
ENV GOLANG_PREBUILT_SHA256=cbcad4a6482107c7c7926df1608106c189417163428200ce357695cc7e01d091
24+
ENV GOLANG_SOURCE_SHA256=a6f3f4bbd3e6bdd626f79b668f212fbb5649daf75084fb79b678a0ae4d97423b
2425
## GoMobile version from https://github.com/golang/mobile (Latest commit, as there is no tag yet)
2526
ENV GOMOBILEHASH=c31d5b91ecc32c0d598b8fe8457d244ca0b4e815
2627

@@ -56,6 +57,7 @@ RUN ln -sf $ANDROID_HOME/ndk/$NDK_VER $ANDROID_HOME/ndk-bundle
5657

5758
# Go section of this Dockerfile from Docker golang: https://github.com/docker-library/golang/blob/master/1.21/bullseye/Dockerfile
5859
# Adapted from alpine apk to debian apt
60+
# Customized to bootstrap with the pre-buit binary, then build custom version from source which includes https://go-review.googlesource.com/c/go/+/408395
5961

6062
## set up nsswitch.conf for Go's "netgo" implementation
6163
## - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
@@ -74,20 +76,25 @@ RUN set -eux; \
7476
; \
7577
rm -rf /var/lib/apt/lists/*
7678

77-
ENV PATH=/usr/local/go/bin:$PATH
7879
RUN set -eux; \
7980
arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
8081
url=; \
8182
case "$arch" in \
8283
'amd64') \
83-
url="https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz"; \
84+
url_prebuilt="https://dl.google.com/go/go$GOLANG_VERSION.linux-amd64.tar.gz"; \
85+
url_src="https://dl.google.com/go/go$GOLANG_VERSION.src.tar.gz"; \
8486
;; \
8587
*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
8688
esac; \
87-
wget -O go.tgz.asc "$url.asc"; \
88-
wget -O go.tgz "$url" --progress=dot:giga;
89+
wget -O go_prebuilt.tgz.asc "$url_prebuilt.asc"; \
90+
wget -O go_prebuilt.tgz "$url_prebuilt" --progress=dot:giga; \
91+
wget -O go_src.tgz.asc "$url_src.asc"; \
92+
wget -O go_src.tgz "$url_src" --progress=dot:giga;
93+
94+
RUN echo "$GOLANG_PREBUILT_SHA256 go_prebuilt.tgz" | sha256sum -c -;
95+
RUN echo "$GOLANG_SOURCE_SHA256 go_src.tgz" | sha256sum -c -;
8996

90-
RUN echo "$GOLANG_SHA256 *go.tgz" | sha256sum -c -;
97+
ADD custom-seald-build.diff /root/
9198

9299
RUN set -eux; \
93100
# https://github.com/golang/go/issues/14739#issuecomment-324767697
@@ -96,18 +103,31 @@ RUN set -eux; \
96103
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 'EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796'; \
97104
# let's also fetch the specific subkey of that key explicitly that we expect "go.tgz.asc" to be signed by, just to make sure we definitely have it
98105
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys '2F52 8D36 D67B 69ED F998 D857 78BD 6547 3CB3 BD13'; \
99-
gpg --batch --verify go.tgz.asc go.tgz; \
106+
gpg --batch --verify go_prebuilt.tgz.asc go_prebuilt.tgz; \
107+
gpg --batch --verify go_src.tgz.asc go_src.tgz; \
100108
gpgconf --kill all; \
101-
rm -rf "$GNUPGHOME" go.tgz.asc; \
109+
rm -rf "$GNUPGHOME" go_prebuilt.tgz.asc go_src.tgz.asc; \
102110
\
103-
tar -C /usr/local -xzf go.tgz; \
104-
rm go.tgz; \
111+
tar -C /usr/local -xzf go_prebuilt.tgz; \
112+
rm go_prebuilt.tgz; \
105113
\
106-
go version
114+
mv /usr/local/go /usr/local/go_prebuilt; \
115+
export PATH=/usr/local/go_prebuilt/bin:$PATH; \
116+
go version; \
117+
\
118+
tar -C /usr/local -xzf go_src.tgz; \
119+
rm go_src.tgz; \
120+
cd /usr/local/go; \
121+
git apply --reject /root/custom-seald-build.diff; \
122+
cd src; \
123+
./all.bash; \
124+
rm -r /usr/local/go_prebuilt /root/custom-seald-build.diff
107125

108126
# persist new go in PATH
109127
ENV PATH=/usr/local/go/bin:$PATH
110128

129+
RUN go version | grep "custom-seald-build"
130+
111131
ENV GOMOBILEPATH=/gomobile
112132
# Setup /workspace
113133
RUN mkdir $GOMOBILEPATH

custom-seald-build.diff

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go
2+
index 5329cb3cd2..e542918754 100644
3+
--- a/src/cmd/cgo/out.go
4+
+++ b/src/cmd/cgo/out.go
5+
@@ -1039,7 +1039,7 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
6+
// string.h for memset, and is also robust to C++
7+
// types with constructors. Both GCC and LLVM optimize
8+
// this into just zeroing _cgo_a.
9+
- fmt.Fprintf(fgcc, "\ttypedef %s %v _cgo_argtype;\n", ctype, p.packedAttribute())
10+
+ fmt.Fprintf(fgcc, "\ttypedef %s %v __attribute__((aligned(8))) _cgo_argtype;\n", ctype, p.packedAttribute())
11+
fmt.Fprintf(fgcc, "\tstatic _cgo_argtype _cgo_zero;\n")
12+
fmt.Fprintf(fgcc, "\t_cgo_argtype _cgo_a = _cgo_zero;\n")
13+
if gccResult != "void" && (len(fntype.Results.List) > 1 || len(fntype.Results.List[0].Names) > 1) {
14+
diff --git a/src/cmd/go/internal/version/version.go b/src/cmd/go/internal/version/version.go
15+
index 4a0132a3fe..257ec05408 100644
16+
--- a/src/cmd/go/internal/version/version.go
17+
+++ b/src/cmd/go/internal/version/version.go
18+
@@ -78,7 +78,7 @@ func runVersion(ctx context.Context, cmd *base.Command, args []string) {
19+
if gover.TestVersion != "" {
20+
v = gover.TestVersion + " (TESTGO_VERSION)"
21+
}
22+
- fmt.Printf("go version %s %s/%s\n", v, runtime.GOOS, runtime.GOARCH)
23+
+ fmt.Printf("go version %s %s/%s custom-seald-build\n", v, runtime.GOOS, runtime.GOARCH)
24+
return
25+
}
26+

0 commit comments

Comments
 (0)