-
Notifications
You must be signed in to change notification settings - Fork 15
/
linuxcdeps.go
84 lines (79 loc) · 2.47 KB
/
linuxcdeps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
//
// Allows building C dependencies using Linux
//
import (
"fmt"
"path/filepath"
"runtime"
"github.com/ooni/probe-engine/pkg/cmd/buildtool/internal/buildtoolmodel"
"github.com/ooni/probe-engine/pkg/runtimex"
"github.com/spf13/cobra"
)
// linuxCdepsSubcommand returns the linuxCdeps sucommand.
func linuxCdepsSubcommand() *cobra.Command {
return &cobra.Command{
Use: "cdeps {zlib|openssl|libevent|tor} [zlib|openssl|libevent|tor...]",
Short: "Builds C dependencies on Linux systems (experimental)",
Run: func(cmd *cobra.Command, args []string) {
// Implementation note: perform the check here such that we can
// run unit test for the building code from any system
runtimex.Assert(
runtime.GOOS == "linux" && runtime.GOARCH == "amd64",
"this command requires linux/amd64",
)
for _, arg := range args {
linuxCdepsBuildMain(arg, &buildDeps{})
}
},
Args: cobra.MinimumNArgs(1),
}
}
// linuxCdepsBuildMain is the main of the linuxCdeps build.
func linuxCdepsBuildMain(name string, deps buildtoolmodel.Dependencies) {
cflags := []string{
// See https://airbus-seclab.github.io/c-compiler-security/
"-D_FORTIFY_SOURCE=2",
"-fstack-protector-strong",
"-fstack-clash-protection",
"-fPIC", // makes more sense than -fPIE given that we're building a library
"-fsanitize=bounds",
"-fsanitize-undefined-trap-on-error",
"-O2",
}
destdir := runtimex.Try1(filepath.Abs(filepath.Join( // must be absolute
"internal", "libtor", "linux", runtime.GOARCH,
)))
globalEnv := &cBuildEnv{
ANDROID_HOME: "",
ANDROID_NDK_ROOT: "",
AR: "",
BINPATH: "",
CC: "",
CFLAGS: cflags,
CONFIGURE_HOST: "",
DESTDIR: destdir,
CXX: "",
CXXFLAGS: cflags,
GOARCH: "",
GOARM: "",
LD: "",
LDFLAGS: []string{},
OPENSSL_COMPILER: "linux-x86_64",
OPENSSL_POST_COMPILER_FLAGS: []string{},
RANLIB: "",
STRIP: "",
}
switch name {
case "libevent":
cdepsLibeventBuildMain(globalEnv, deps)
case "openssl":
cdepsOpenSSLBuildMain(globalEnv, deps)
case "tor":
cdepsTorBuildMain(globalEnv, deps)
case "zlib":
cdepsZlibBuildMain(globalEnv, deps)
default:
panic(fmt.Errorf("unknown dependency: %s", name))
}
}