Skip to content

Commit

Permalink
fix(script/go.bash): support Ubuntu 22.04 LTS and Debian 11 (ooni#1487)
Browse files Browse the repository at this point in the history
This commit is part of ooni/probe#2664. We use
a different strategy for downloading and executing the correct version
of Go. We have vendored and adapted to code at `golang.org/dl` such that
it works with versions of Go as old as the version of Go used by Ubuntu
22.04 LTS and Debian 11.
  • Loading branch information
bassosimone authored and Murphy-OrangeMud committed Feb 13, 2024
1 parent 71802a5 commit fa9d3c2
Show file tree
Hide file tree
Showing 13 changed files with 720 additions and 146 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/gofixpath.yml → .github/workflows/gobash.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Ensures that ./internal/cmd/buildtool gofixpath {command} [arguments] downloads the correct
# version of go and executes {command} with [arguments] with "go" being the right version.
# Ensures that ./script/go.bash works as intended with many versions of "go".
#
# See https://github.com/ooni/probe/issues/2664.

name: gofixpath
name: gobash
on:
push:
branches:
Expand All @@ -21,7 +20,14 @@ jobs:
build_with_specific_go_version:
strategy:
matrix:
goversion: ["1.19", "1.20", "1.21"] # when releasing check whether we need to update this array
goversion:
- "1.15" # debian 11 "bullseye"
- "1.16"
- "1.17"
- "1.18" # ubuntu 22.04 LTS
- "1.19" # debian 12 "bookworm"
- "1.20"
- "1.21"
system: [ubuntu-latest, macos-latest]
runs-on: "${{ matrix.system }}"
steps:
Expand Down
97 changes: 38 additions & 59 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,22 @@ Debian/Ubuntu. Once `ooniprobe` is installed, refer to the

## Developer instructions

This repository _should really_ use the Go version mentioned by the
[GOVERSION](GOVERSION) file (i.e., go1.20.12). Using a later version of
Go _should_ work as intended. Using an older version of Go is
_definitely not recommended_ and _may not even compile_. Here's why: we rely
on packages forked from the standard library; so, it is
more robust to use the same version of Go from which
we forked those packages from.
To setup development for this repository you need Go >= 1.15. The
`./script/go.bash` script will automatically download the expected
version of Go mentioned in the [GOVERSION](GOVERSION) file (i.e.,
go1.20.12) and use it for building.

You can also bypass `./script/go.bash` and build ooniprobe manually using
`go build ...` but, in such a case, note that:

1. using an older version that the one mentioned in [GOVERSION](GOVERSION)
is _definitely not recommended_ and _may not even compile_;

2. using later versions _should_ work as intended for core functionality
but extra functionality may be disabled or not working as intended.

Here's why: we rely on packages forked from the standard library; so, it is
more robust to use the same version of Go from which we forked those packages from.

You will also need a C compiler. On Linux and other Unix systems
both GCC and Clang will work. If you're using Windows, we
Expand All @@ -81,48 +90,29 @@ mingw-w64 cross-compiler.

The following commands show how to setup a development
environment using Debian 12 ("bookworm"). The same instructions
should also work for Debian-based distribution (e.g., Ubuntu)
as long as you're using Go >= 1.19.
should also work for Ubuntu 22.04 LTS.

```bash
# install the compilers, git, and the root CA
sudo apt install golang build-essential ca-certificates git

# [optional] install mingw-w64 if you're targeting windows
sudo apt install mingw-w64

# install the required go version binary
go install -v golang.org/dl/go1.20.12@latest

# fetch the whole go distribution
$HOME/go/bin/go1.20.12 download
```

You can automate the last two steps by using `./script/go.bash` as your
Go compiler, as explained below.

### Fedora developer setup

The following commands show how to setup a development
environment using Fedora, as long as your Fedora uses Go >= 1.19.
environment using Fedora, as long as your Fedora uses Go >= 1.15.

```bash
# install the compilers and git
sudo dnf install golang make gcc gcc-c++ git

# [optional] install mingw-w64 if you're targeting windows
sudo dnf install mingw64-gcc mingw64-gcc-c++

# install the required go version binary
go install -v golang.org/dl/go1.20.12@latest

# fetch the whole go distribution
$HOME/go/bin/go1.20.12 download
```

You can automate the last two steps by using `./script/go.bash` as your
Go compiler, as explained below.

### macOS developer setup

The following commands show how to setup a development
Expand All @@ -135,29 +125,35 @@ Then, you need to follow these instructions:
```bash
# install the compiler
brew install go
```

# install the required go version binary
go install -v golang.org/dl/go1.20.12@latest
### The `./script/go.bash` script

# fetch the whole go distribution
$HOME/go/bin/go1.20.12 download
The `./script/go.bash` script requires Go >= 1.15 and automates installing and
using the correct version of Go. Running this script as follows:

```bash
./script/go.bash build -v -ldflags '-s -w' ./internal/cmd/miniooni
```

You can automate the last two steps by using `./script/go.bash` as your
Go compiler, as explained below.
Is equivalent to running these commands:

```bash
go install -v golang.org/dl/go1.20.12@latest
$HOME/go/bin/go1.20.12 download
$HOME/sdk/go1.20.12/bin/go build -v -ldflags '-s -w' ./internal/cmd/miniooni
```

### Build instructions without using `./script/go.bash`
### Common build targets

This section describe how to manually use the correct version of Go you have
installed. You can alternatively use the `./script/go.bash` wrapper to automatically
use the correct Go version (provided you have Go >= 1.19 installed), as described
in a subsequent section of this file.
This section shows how to build using `./script/go.bash`. If you want to bypass
using this script, just run `go` instead of `./script/go.bash`.

Once you have installed the correct Go version and a C compiler,
you can compile `ooniprobe` using:

```bash
$HOME/go/bin/go1.20.12 build -v -ldflags '-s -w' ./cmd/ooniprobe
./script/go.bash build -v -ldflags '-s -w' ./cmd/ooniprobe
```

This command will generate a stripped binary called `ooniprobe`
Expand All @@ -166,7 +162,7 @@ in the toplevel directory.
Likewise, you can compile `miniooni` using:

```bash
$HOME/go/bin/go1.20.12 build -v -ldflags '-s -w' ./internal/cmd/miniooni
./script/go.bash build -v -ldflags '-s -w' ./internal/cmd/miniooni
```

This command will generate a stripped binary called `miniooni`
Expand All @@ -175,29 +171,12 @@ in the toplevel directory.
And `oohelperd` using:

```bash
$HOME/go/bin/go1.20.12 build -v -ldflags '-s -w' ./internal/cmd/oohelperd
./script/go.bash build -v -ldflags '-s -w' ./internal/cmd/oohelperd
```

This command will generate a stripped binary called `oohelperd`
in the toplevel directory.

### Alternative: using the `./script/go.bash` script

The `./script/go.bash` script requires Go >= 1.19 and automates installing and
using the correct version of Go. Running this script as follows:

```bash
./script/go.bash build -v -ldflags '-s -w' ./internal/cmd/miniooni
```

Is equivalent to running these commands:

```bash
go install -v golang.org/dl/go1.20.12@latest
$HOME/go/bin/go1.20.12 download
$HOME/sdk/go1.20.12/bin/go build -v -ldflags '-s -w' ./internal/cmd/miniooni
```

## Contributing

Please, see [CONTRIBUTING.md](CONTRIBUTING.md).
Expand Down
78 changes: 0 additions & 78 deletions internal/cmd/buildtool/gofixpath.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/cmd/buildtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func main() {
root.AddCommand(androidSubcommand())
root.AddCommand(darwinSubcommand())
root.AddCommand(genericSubcommand())
root.AddCommand(gofixpathSubcommand())
root.AddCommand(iosSubcommand())
root.AddCommand(linuxSubcommand())
root.AddCommand(oohelperdSubcommand())
Expand Down
1 change: 1 addition & 0 deletions pkg/gobash/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/gobash.exe
3 changes: 3 additions & 0 deletions pkg/gobash/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/ooni/probe-cli/pkg/gobash

go 1.16
22 changes: 22 additions & 0 deletions pkg/gobash/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"io/ioutil"
"log"
)

func main() {
// read the content of GOVERSION
data, err := ioutil.ReadFile("GOVERSION")
if err != nil {
log.Fatal(err)
}

// strip trailing newlines
for len(data) > 0 && data[len(data)-1] == '\r' || data[len(data)-1] == '\n' {
data = data[:len(data)-1]
}

// run the specified version of go
Run("go" + string(data))
}
14 changes: 14 additions & 0 deletions pkg/gobash/signal_notunix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build windows
// +build windows

package main

import (
"os"
)

var signalsToIgnore = []os.Signal{os.Interrupt}
15 changes: 15 additions & 0 deletions pkg/gobash/signal_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build darwin || freebsd || linux || openbsd
// +build darwin freebsd linux openbsd

package main

import (
"os"
"syscall"
)

var signalsToIgnore = []os.Signal{os.Interrupt, syscall.SIGQUIT}
Loading

0 comments on commit fa9d3c2

Please sign in to comment.