diff --git a/internal/cmd/buildtool/android.go b/internal/cmd/buildtool/android.go index c8ac93a389..e2f6286b98 100644 --- a/internal/cmd/buildtool/android.go +++ b/internal/cmd/buildtool/android.go @@ -26,6 +26,7 @@ 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", @@ -33,6 +34,7 @@ func androidSubcommand() *cobra.Command { androidBuildGomobile(&buildDeps{}) }, }) + cmd.AddCommand(&cobra.Command{ Use: "cli", Short: "Builds ooniprobe and miniooni for usage within termux", @@ -40,6 +42,7 @@ func androidSubcommand() *cobra.Command { androidBuildCLIAll(&buildDeps{}) }, }) + cmd.AddCommand(&cobra.Command{ Use: "cdeps {zlib|openssl|libevent|tor} [zlib|openssl|libevent|tor...]", Short: "Cross compiles C dependencies for Android", @@ -50,6 +53,7 @@ func androidSubcommand() *cobra.Command { }, Args: cobra.MinimumNArgs(1), }) + return cmd } @@ -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) @@ -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": @@ -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) diff --git a/internal/cmd/buildtool/cbuildenv.go b/internal/cmd/buildtool/cbuildenv.go index 5550118248..666e6cd1fc 100644 --- a/internal/cmd/buildtool/cbuildenv.go +++ b/internal/cmd/buildtool/cbuildenv.go @@ -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 @@ -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 } diff --git a/internal/cmd/buildtool/cdepsopenssl.go b/internal/cmd/buildtool/cdepsopenssl.go index dbecb9f624..9dad79eaba 100644 --- a/internal/cmd/buildtool/cdepsopenssl.go +++ b/internal/cmd/buildtool/cdepsopenssl.go @@ -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)) diff --git a/internal/cmd/buildtool/internal/buildtoolmodel/buildtoolmodel.go b/internal/cmd/buildtool/internal/buildtoolmodel/buildtoolmodel.go index 67966e3f85..2ac8f89ec6 100644 --- a/internal/cmd/buildtool/internal/buildtoolmodel/buildtoolmodel.go +++ b/internal/cmd/buildtool/internal/buildtoolmodel/buildtoolmodel.go @@ -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 @@ -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 } diff --git a/internal/cmd/buildtool/linuxcdeps.go b/internal/cmd/buildtool/linuxcdeps.go index e238b738af..347108613d 100644 --- a/internal/cmd/buildtool/linuxcdeps.go +++ b/internal/cmd/buildtool/linuxcdeps.go @@ -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":