Building a custom fork of Go

Note

For your reference, here is the relevant offical document: Installing Go from source.

Lantern requires a custom fork of Go, which doesn’t provide pre-built binary files, so we’ll have to compile it by ourselves.

Install Go compiler binaries

The Go tool chain is written in Go. To build it, you need a Go compiler installed.

  1. Launch a MinGW64 shell, which you can find at C:\msys64\mingw64.exe, if you haven’t yet.

  2. Change the current directory to your home directory:

    cd $HOME
    
  3. According to the offical document, you can use a binary release as a bootstrap tool chain, see the downloads page. However, the link seems to be blocked, so let’s build the bootstrap tool chain from source instead.

    1. First, download the source by:

      wget https://storage.googleapis.com/golang/go1.4-bootstrap-20170531.tar.gz
      

      And a compressed file of 10.79 MB will be downloaded.

      Note

      If the download fails, try the following command:

      wget http://ulantern.readthedocs.io/en/latest/_downloads/go1.4-bootstrap-20170531.tar.gz
      
    2. Next, unpack it. This is going to take several seconds:

      mkdir Go1.4/ && tar -zxvf go1.4-bootstrap-20170531.tar.gz -C Go1.4/ --strip-components=1
      
    3. Finally, cd to the src subdirectory and run make.bat. This would take a while:

      cd Go1.4/src/
      ./make.bat
      
  4. Now it’s return to the home directory:

    cd $HOME
    
  5. (Optional) Now you can delete the compressed file, if you want:

    rm go1.4-bootstrap-20170531.tar.gz
    

Fetch the Go repository

  1. Create a directory named Lantern. It will be containing the repository (i.e. source code) of Go and Lantern:

    mkdir Lantern
    
  2. Change directory to Lantern:

    cd Lantern
    
  3. Download the custom fork of Go from Github:

    git clone https://github.com/getlantern/go.git
    cd go
    git checkout lantern
    

    Note

    When you see a multi-line line code block, run the command on each line one aftr one.

Install Go

  1. Build the Go distribution:

    cd src
    ./all.bat
    

    all.bat would also run some tests after building Go. If you wish to skip the tests, run the following commands instead:

    cd src
    ./make.bat
    
  2. Then, add the bin directory to $PATH:

    echo "# getlantern/go" >> ~/.bashrc
    echo "export GOROOT=$HOME/Lantern/go" >> ~/.bashrc
    echo "export PATH=$PATH:$GOROOT/bin" >> ~/.bashrc
    source ~/.bashrc
    
  3. Go to the final step, Building Lantern.