Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed May 5, 2024
0 parents commit 6d78c52
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Go

on:
push:
branches:
- 'master'
tags:
- '*'

jobs:
docker:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the Docker image
run: |
tag=latest
[[ "$GITHUB_REF" =~ ^refs/tags/ ]] && tag="${GITHUB_REF/refs\/tags\//}"
docker build . --tag "ghcr.io/carapace-sh/go:${tag}"
docker push "ghcr.io/carapace-sh/go:${tag}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch.diff
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "go-src"]
path = go-src
url = https://github.com/golang/go
branch = release-branch.go1.22
23 changes: 23 additions & 0 deletions 1-plugin-patch/patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/src/runtime/plugin.go b/src/runtime/plugin.go
index 4b6821b..40d1158 100644
--- a/src/runtime/plugin.go
+++ b/src/runtime/plugin.go
@@ -51,12 +51,12 @@ func plugin_lastmoduleinit() (path string, syms map[string]any, initTasks []*ini
throw("plugin: new module data overlaps with previous moduledata")
}
}
- for _, pkghash := range md.pkghashes {
- if pkghash.linktimehash != *pkghash.runtimehash {
- md.bad = true
- return "", nil, nil, "plugin was built with a different version of package " + pkghash.modulename
- }
- }
+ // for _, pkghash := range md.pkghashes {
+ // if pkghash.linktimehash != *pkghash.runtimehash {
+ // md.bad = true
+ // return "", nil, nil, "plugin was built with a different version of package " + pkghash.modulename
+ // }
+ // }

// Initialize the freshly loaded module.
modulesinit()
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:1.22.1 as build
ADD . /go-src
RUN cd /go-src && make build

FROM golang:1.22.1 as build-termux
ADD . /go-src
RUN cd /go-src && make build-termux

FROM golang:1.22.1
COPY --from=build --link /usr/local/go/ /usr/local/go
COPY --from=build-termux --link /usr/local/go/ /usr/local/go-termux/
RUN ln -s /usr/local/go-termux/bin/go /usr/local/bin/go-termux
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
define apply
@echo "Patching Runtime with ./$1/patch.diff..."
@git -C go-src apply ../$1/patch.diff
endef

default:
@echo "Select make target..."

clean: patch
@echo "Resetting Go to clean state..."
@git -C go-src restore .
@git -C go-src clean -f .

build: clean
$(call apply,1-plugin-patch)
@echo "Building Go from source..."
@cd go-src/src && ./make.bash

build-termux: clean
$(call apply,1-plugin-patch)

@cp -T go-src/src/net/conf.go go-src/src/net/conf_android.go
@cp -T go-src/src/net/dnsclient_unix.go go-src/src/net/dnsclient_android.go
$(call apply,termux/1-hardcoded-etc-resolv-conf)
$(call apply,termux/2-fix-GOPROXY-and-GOSUMDB-default-is-empty)
$(call apply,termux/3-src-crypto-x509-root_linux.go)
$(call apply,termux/4-src-os-file_unix.go.patch)

@echo "Building Go from source..."
@cd go-src/src && ./make.bash

patch:
@echo "Creating patch..."
@git -C go-src diff > patch.diff
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Golang

Fork of [golang/go](https://github.com/golang/go) based on [DomBlack/ForkingGoRuntime](https://github.com/DomBlack/ForkingGoRuntime).

## Patches
1. lenient plugin support ([golang/go#31354](https://github.com/golang/go/issues/31354#issuecomment-848824708))
1 change: 1 addition & 0 deletions go-src
Submodule go-src added at 619b41
71 changes: 71 additions & 0 deletions termux/1-hardcoded-etc-resolv-conf/patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
--- a/src/net/conf.go 2024-02-02 23:39:55.000000000 +0530
+++ b/src/net/conf.go 2024-02-18 22:34:10.016000996 +0530
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

+//go:build !android
+
package net

import (
--- a/src/net/conf_android.go 2024-02-18 22:31:59.680000988 +0530
+++ b/src/net/conf_android.go 2024-02-18 22:41:52.060001024 +0530
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

+//go:build android
+
package net

import (
@@ -414,7 +416,7 @@
var haveMDNSAllow bool
switch c.mdnsTest {
case mdnsFromSystem:
- _, err := os.Stat("/etc/mdns.allow")
+ _, err := os.Stat("/data/data/com.termux/files/etc/mdns.allow")
if err != nil && !errors.Is(err, fs.ErrNotExist) {
// Let libc figure out what is going on.
return hostLookupCgo, dnsConf
--- a/src/net/dnsclient_unix.go 2024-02-02 23:39:55.000000000 +0530
+++ b/src/net/dnsclient_unix.go 2024-02-18 22:36:17.948001004 +0530
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

+//go:build !android
+
// DNS client: see RFC 1035.
// Has to be linked into package net for Dial.

--- a/src/net/dnsclient_android.go 2024-02-18 22:32:31.136000990 +0530
+++ b/src/net/dnsclient_android.go 2024-02-18 22:43:13.612001028 +0530
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

+//go:build android
+
// DNS client: see RFC 1035.
// Has to be linked into package net for Dial.

@@ -367,7 +369,7 @@
var resolvConf resolverConfig

func getSystemDNSConfig() *dnsConfig {
- resolvConf.tryUpdate("/etc/resolv.conf")
+ resolvConf.tryUpdate("/data/data/com.termux/files/etc/resolv.conf")
return resolvConf.dnsConfig.Load()
}

@@ -375,7 +377,7 @@
func (conf *resolverConfig) init() {
// Set dnsConfig and lastChecked so we don't parse
// resolv.conf twice the first time.
- conf.dnsConfig.Store(dnsReadConfig("/etc/resolv.conf"))
+ conf.dnsConfig.Store(dnsReadConfig("/data/data/com.termux/files/etc/resolv.conf"))
conf.lastChecked = time.Now()

// Prepare ch so that only one update of resolverConfig may
15 changes: 15 additions & 0 deletions termux/2-fix-GOPROXY-and-GOSUMDB-default-is-empty/patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/cmd/go/internal/cfg/cfg.go b/src/cmd/go/internal/cfg/cfg.go
index afb595a..f74f980 100644
--- a/src/cmd/go/internal/cfg/cfg.go
+++ b/src/cmd/go/internal/cfg/cfg.go
@@ -411,8 +411,8 @@ var (
GORISCV64 = envOr("GORISCV64", fmt.Sprintf("rva%du64", buildcfg.GORISCV64))
GOWASM = envOr("GOWASM", fmt.Sprint(buildcfg.GOWASM))

- GOPROXY = envOr("GOPROXY", "")
- GOSUMDB = envOr("GOSUMDB", "")
+ GOPROXY = envOr("GOPROXY", "https://proxy.golang.org,direct")
+ GOSUMDB = envOr("GOSUMDB", "sum.golang.org")
GOPRIVATE = Getenv("GOPRIVATE")
GONOPROXY = envOr("GONOPROXY", GOPRIVATE)
GONOSUMDB = envOr("GONOSUMDB", GOPRIVATE)
12 changes: 12 additions & 0 deletions termux/3-src-crypto-x509-root_linux.go/patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/src/crypto/x509/root_linux.go b/src/crypto/x509/root_linux.go
index 8e79ccb..1176471 100644
--- a/src/crypto/x509/root_linux.go
+++ b/src/crypto/x509/root_linux.go
@@ -8,6 +8,7 @@ import "internal/goos"

// Possible certificate files; stop after finding one.
var certFiles = []string{
+ "/data/data/com.termux/files/etc/tls/cert.pem", // Termux
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc.
"/etc/pki/tls/certs/ca-bundle.crt", // Fedora/RHEL 6
"/etc/ssl/ca-bundle.pem", // OpenSUSE
13 changes: 13 additions & 0 deletions termux/4-src-os-file_unix.go.patch/patch.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/os/file_unix.go b/src/os/file_unix.go
index a527b23..3a302f9 100644
--- a/src/os/file_unix.go
+++ b/src/os/file_unix.go
@@ -392,7 +392,7 @@ func tempDir() string {
dir := Getenv("TMPDIR")
if dir == "" {
if runtime.GOOS == "android" {
- dir = "/data/local/tmp"
+ dir = "/data/data/com.termux/files/tmp"
} else {
dir = "/tmp"
}

0 comments on commit 6d78c52

Please sign in to comment.