Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(buildtool): use list for OpenSSL ./Configure flags #1367

Merged
merged 10 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions internal/cmd/buildtool/android.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ func androidSubcommand() *cobra.Command {
Use: "android",
Short: "Builds ooniprobe, miniooni, and oonimkall for android",
}

cmd.AddCommand(&cobra.Command{
Use: "gomobile",
Short: "Builds oonimkall for android using gomobile",
Run: func(cmd *cobra.Command, args []string) {
androidBuildGomobile(&buildDeps{})
},
})

cmd.AddCommand(&cobra.Command{
Use: "cli",
Short: "Builds ooniprobe and miniooni for usage within termux",
Run: func(cmd *cobra.Command, args []string) {
androidBuildCLIAll(&buildDeps{})
},
})

cmd.AddCommand(&cobra.Command{
Use: "cdeps {zlib|openssl|libevent|tor} [zlib|openssl|libevent|tor...]",
Short: "Cross compiles C dependencies for Android",
Expand All @@ -50,6 +53,7 @@ func androidSubcommand() *cobra.Command {
},
Args: cobra.MinimumNArgs(1),
})

return cmd
}

Expand Down Expand Up @@ -161,7 +165,7 @@ func androidBuildCLIProductArch(
androidHome string,
ndkDir string,
) {
cgo := newAndroidCBuildEnv(androidHome, ndkDir, ooniArch)
cgo := androidNewCBuildEnv(androidHome, ndkDir, ooniArch)

log.Infof("building %s for android/%s", product.Pkg, ooniArch)

Expand Down Expand Up @@ -203,33 +207,33 @@ func androidBuildCLIProductArch(
runtimex.Try0(shellx.RunEx(defaultShellxConfig(), argv, envp))
}

// newAndroidCBuildEnv creates a new [cBuildEnv] for the
// androidNewCBuildEnv creates a new [cBuildEnv] for the
// given ooniArch ("arm", "arm64", "386", "amd64").
func newAndroidCBuildEnv(androidHome, ndkDir, ooniArch string) *cBuildEnv {
func androidNewCBuildEnv(androidHome, ndkDir, ooniArch string) *cBuildEnv {
binpath := androidNDKBinPath(ndkDir)
destdir := runtimex.Try1(filepath.Abs(filepath.Join( // must be absolute
"internal", "libtor", "android", ooniArch,
)))
out := &cBuildEnv{
ANDROID_HOME: androidHome,
ANDROID_NDK_ROOT: ndkDir,
AS: "", // later
AR: filepath.Join(binpath, "llvm-ar"),
BINPATH: binpath,
CC: "", // later
CFLAGS: androidCflags(ooniArch),
CONFIGURE_HOST: "", // later
DESTDIR: destdir,
CXX: "", // later
CXXFLAGS: androidCflags(ooniArch),
GOARCH: ooniArch,
GOARM: "", // maybe later
LD: filepath.Join(binpath, "ld"),
LDFLAGS: []string{}, // empty
OPENSSL_API_DEFINE: "-D__ANDROID_API__=21",
OPENSSL_COMPILER: "", // later
RANLIB: filepath.Join(binpath, "llvm-ranlib"),
STRIP: filepath.Join(binpath, "llvm-strip"),
ANDROID_HOME: androidHome,
ANDROID_NDK_ROOT: ndkDir,
AS: "", // later
AR: filepath.Join(binpath, "llvm-ar"),
BINPATH: binpath,
CC: "", // later
CFLAGS: androidCflags(ooniArch),
CONFIGURE_HOST: "", // later
DESTDIR: destdir,
CXX: "", // later
CXXFLAGS: androidCflags(ooniArch),
GOARCH: ooniArch,
GOARM: "", // maybe later
LD: filepath.Join(binpath, "ld"),
LDFLAGS: []string{}, // empty
OPENSSL_COMPILER: "", // later
OPENSSL_POST_COMPILER_FLAGS: []string{"-D__ANDROID_API__=21"},
RANLIB: filepath.Join(binpath, "llvm-ranlib"),
STRIP: filepath.Join(binpath, "llvm-strip"),
}
switch ooniArch {
case "arm":
Expand Down Expand Up @@ -395,7 +399,7 @@ func androidCdepsBuildArch(
ndkDir string,
name string,
) {
cdenv := newAndroidCBuildEnv(androidHome, ndkDir, arch)
cdenv := androidNewCBuildEnv(androidHome, ndkDir, arch)
switch name {
case "libevent":
cdepsLibeventBuildMain(cdenv, deps)
Expand Down
45 changes: 23 additions & 22 deletions internal/cmd/buildtool/cbuildenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ type cBuildEnv struct {
// LDFLAGS contains the LDFLAGS to use when compiling.
LDFLAGS []string

// OPENSSL_API_DEFINE is an extra define we need to add on Android.
OPENSSL_API_DEFINE string

// OPENSSL_COMPILER is the compiler name for OpenSSL.
OPENSSL_COMPILER string

// OPENSSL_POST_COMPILER_FLAGS contains extra flags to pass after OPENSSL_COMPILER
OPENSSL_POST_COMPILER_FLAGS []string

// RANLIB is the path to the ranlib tool.
RANLIB string

Expand All @@ -86,29 +86,30 @@ type cBuildEnv struct {
// environment variables to CFLAGS, CXXFLAGS, etc.
func cBuildMerge(global, local *cBuildEnv) *cBuildEnv {
out := &cBuildEnv{
ANDROID_HOME: global.ANDROID_HOME,
ANDROID_NDK_ROOT: global.ANDROID_NDK_ROOT,
AR: global.AR,
AS: global.AS,
BINPATH: global.BINPATH,
CC: global.CC,
CFLAGS: append([]string{}, global.CFLAGS...),
CONFIGURE_HOST: global.CONFIGURE_HOST,
DESTDIR: global.DESTDIR,
CXX: global.CXX,
CXXFLAGS: append([]string{}, global.CXXFLAGS...),
GOARCH: global.GOARCH,
GOARM: global.GOARM,
LD: global.LD,
LDFLAGS: append([]string{}, global.LDFLAGS...),
OPENSSL_API_DEFINE: global.OPENSSL_API_DEFINE,
OPENSSL_COMPILER: global.OPENSSL_COMPILER,
RANLIB: global.RANLIB,
STRIP: global.STRIP,
ANDROID_HOME: global.ANDROID_HOME,
ANDROID_NDK_ROOT: global.ANDROID_NDK_ROOT,
AR: global.AR,
AS: global.AS,
BINPATH: global.BINPATH,
CC: global.CC,
CFLAGS: append([]string{}, global.CFLAGS...),
CONFIGURE_HOST: global.CONFIGURE_HOST,
DESTDIR: global.DESTDIR,
CXX: global.CXX,
CXXFLAGS: append([]string{}, global.CXXFLAGS...),
GOARCH: global.GOARCH,
GOARM: global.GOARM,
LD: global.LD,
LDFLAGS: append([]string{}, global.LDFLAGS...),
OPENSSL_COMPILER: global.OPENSSL_COMPILER,
OPENSSL_POST_COMPILER_FLAGS: append([]string{}, global.OPENSSL_POST_COMPILER_FLAGS...),
RANLIB: global.RANLIB,
STRIP: global.STRIP,
}
out.CFLAGS = append(out.CFLAGS, local.CFLAGS...)
out.CXXFLAGS = append(out.CXXFLAGS, local.CXXFLAGS...)
out.LDFLAGS = append(out.LDFLAGS, local.LDFLAGS...)
out.OPENSSL_POST_COMPILER_FLAGS = append(out.OPENSSL_POST_COMPILER_FLAGS, local.OPENSSL_POST_COMPILER_FLAGS...)
return out
}

Expand Down
4 changes: 1 addition & 3 deletions internal/cmd/buildtool/cdepsopenssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ func cdepsOpenSSLBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependencie
"no-rc2", "no-rc4", "no-rc5", "no-rmd160", "no-whirlpool", "no-dso",
"no-ui-console", "no-shared", "no-unit-test", globalEnv.OPENSSL_COMPILER,
))
if globalEnv.OPENSSL_API_DEFINE != "" {
argv.Append(globalEnv.OPENSSL_API_DEFINE)
}
argv.Append(globalEnv.OPENSSL_POST_COMPILER_FLAGS...)
argv.Append("--libdir=lib", "--prefix=/", "--openssldir=/")
runtimex.Try0(shellx.RunEx(defaultShellxConfig(), argv, envp))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type Dependencies interface {
// function returns the Android home path.
AndroidSDKCheck() string

// GOOS returns the current GOOS.
GOOS() string

// GOPATH returns the current GOPATH.
GOPATH() string

Expand Down Expand Up @@ -49,7 +52,4 @@ type Dependencies interface {
// WindowsMingwCheck makes sure we're using the
// expected version of mingw-w64.
WindowsMingwCheck()

// GOOS returns the current GOOS.
GOOS() string
}
36 changes: 18 additions & 18 deletions internal/cmd/buildtool/linuxcdeps.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ func linuxCdepsBuildMain(name string, deps buildtoolmodel.Dependencies) {
"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_API_DEFINE: "",
OPENSSL_COMPILER: "linux-x86_64",
RANLIB: "",
STRIP: "",
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":
Expand Down