github.com/iDigitalFlame/xmt@v0.5.4/tools/light_goroot.sh (about)

     1  #!/usr/bin/bash
     2  # Copyright (C) 2020 - 2023 iDigitalFlame
     3  #
     4  # This program is free software: you can redistribute it and/or modify
     5  # it under the terms of the GNU General Public License as published by
     6  # the Free Software Foundation, either version 3 of the License, or
     7  # any later version.
     8  #
     9  # This program is distributed in the hope that it will be useful,
    10  # but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  # GNU General Public License for more details.
    13  #
    14  # You should have received a copy of the GNU General Public License
    15  # along with this program.  If not, see <https://www.gnu.org/licenses/>.
    16  #
    17  
    18  echo "Making a Golang GOROOT clone to nuke stupid dependencies.."
    19  
    20  GOROOT_LITE="/tmp/go-root-lite"
    21  
    22  rsync -ar "${GOROOT}/" "$GOROOT_LITE"
    23  rm ${GOROOT_LITE}/src/fmt/*.go
    24  rm ${GOROOT_LITE}/src/unicode/*.go
    25  
    26  echo "Downloaded patched source.."
    27  git clone "https://github.com/iDigitalFlame/TinyPatchedGo" "${GOROOT_LITE}/patches"
    28  
    29  echo 'Removing bloated "fmt" and "unicode"..'
    30  mv ${GOROOT_LITE}/patches/fmt/*.go  "${GOROOT_LITE}/src/fmt/"
    31  mv ${GOROOT_LITE}/patches/unicode/*.go  "${GOROOT_LITE}/src/unicode/"
    32  
    33  sed -ie 's/return envProxyFunc()(req.URL)/return req.URL, nil/g' "${GOROOT_LITE}/src/net/http/transport.go"
    34  sed -ie 's/envProxyFuncValue = httpproxy.FromEnvironment().ProxyFunc()/envProxyFuncValue = nil/g' "${GOROOT_LITE}/src/net/http/transport.go"
    35  sed -ie 's/"golang.org\/x\/net\/http\/httpproxy"//g' "${GOROOT_LITE}/src/net/http/transport.go"
    36  rm "${GOROOT_LITE}/src/net/http/transport.goe"
    37  sed -ie 's/if a, err := idna.ToASCII(host); err == nil {/if a := ""; len(a) > 0 {/g' "${GOROOT_LITE}/src/net/http/h2_bundle.go"
    38  sed -ie 's/"golang.org\/x\/net\/idna"//g' "${GOROOT_LITE}/src/net/http/h2_bundle.go"
    39  rm "${GOROOT_LITE}/src/net/http/h2_bundle.goe"
    40  sed -ie 's/return idna.Lookup.ToASCII(v)/return v, nil/g' "${GOROOT_LITE}/src/net/http/request.go"
    41  sed -ie 's/"golang.org\/x\/net\/idna"//g' "${GOROOT_LITE}/src/net/http/request.go"
    42  rm "${GOROOT_LITE}/src/net/http/request.goe"
    43  sed -ie 's/host, err = idna.ToASCII(host)/host, err = host, nil/g' "${GOROOT_LITE}/src/vendor/golang.org/x/net/http/httpguts/httplex.go"
    44  sed -ie 's/"golang.org\/x\/net\/idna"//g' "${GOROOT_LITE}/src/vendor/golang.org/x/net/http/httpguts/httplex.go"
    45  rm "${GOROOT_LITE}/src/vendor/golang.org/x/net/http/httpguts/httplex.goe"
    46  export GOROOT=$GOROOT_LITE
    47  
    48  echo "Vendering dependencies.."
    49  rm -rf "vendor"
    50  go mod tidy
    51  go mod verify
    52  go mod vendor
    53  
    54  echo "Done."
    55  echo 'Make sure to run "export GOROOT=/tmp/go-root-lite" before starting any builds!'