From 12a61a21e9925ea8ffa1d3743d6c6294690d511e Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 10 Oct 2023 15:06:26 +0200 Subject: [PATCH 1/8] x --- internal/cmd/buildtool/android.go | 12 ++-- internal/cmd/buildtool/ios.go | 111 ++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 4 deletions(-) diff --git a/internal/cmd/buildtool/android.go b/internal/cmd/buildtool/android.go index c8ac93a389..1068fd59a7 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,9 +207,9 @@ 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, @@ -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/ios.go b/internal/cmd/buildtool/ios.go index 9208b8c00d..500b8d789d 100644 --- a/internal/cmd/buildtool/ios.go +++ b/internal/cmd/buildtool/ios.go @@ -5,10 +5,14 @@ package main // import ( + "errors" + "fmt" "path/filepath" + "runtime" "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/cmd/buildtool/internal/buildtoolmodel" + "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/shellx" "github.com/spf13/cobra" ) @@ -19,6 +23,7 @@ func iosSubcommand() *cobra.Command { Use: "ios", Short: "Builds oonimkall and its dependencies for iOS", } + cmd.AddCommand(&cobra.Command{ Use: "gomobile", Short: "Builds oonimkall for iOS using gomobile", @@ -26,6 +31,18 @@ func iosSubcommand() *cobra.Command { iosBuildGomobile(&buildDeps{}) }, }) + + cmd.AddCommand(&cobra.Command{ + Use: "cdeps {zlib|openssl|libevent|tor} [zlib|openssl|libevent|tor...]", + Short: "Cross compiles C dependencies for iOS", + Run: func(cmd *cobra.Command, args []string) { + for _, arg := range args { + iosCdepsBuildMain(arg, &buildDeps{}) + } + }, + Args: cobra.MinimumNArgs(1), + }) + return cmd } @@ -41,6 +58,100 @@ func iosBuildGomobile(deps buildtoolmodel.Dependencies) { output: filepath.Join("MOBILE", "ios", "oonimkall.xcframework"), target: "ios", } + log.Info("building the mobile library using gomobile") gomobileBuild(config) } + +// iosCdepsBuildMain builds C dependencies for ios. +func iosCdepsBuildMain(name string, deps buildtoolmodel.Dependencies) { + runtimex.Assert( + runtime.GOOS == "darwin" || runtime.GOOS == "linux", + "this command requires darwin or linux", + ) + archs := []string{"arm", "arm64", "386", "amd64"} + for _, arch := range archs { + iosCdepsBuildArch(deps, arch, name) + } +} + +// iosNewCBuildEnv creates a new [cBuildEnv] for the given ooniArch ("arm", "arm64", "386", "amd64"). +func iosNewCBuildEnv(ooniArch string) *cBuildEnv { + destdir := runtimex.Try1(filepath.Abs(filepath.Join( // must be absolute + "internal", "libtor", "ios", ooniArch, + ))) + // export CFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot $XCODE_ROOT/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${IPHONE_SDKVERSION}.sdk -mios-version-min=${IPHONE_SDKVERSION} -fembed-bitcode" + out := &cBuildEnv{ + ANDROID_HOME: "", + ANDROID_NDK_ROOT: "", + AS: "", // later + AR: "", + BINPATH: "", + CC: "clang", + CFLAGS: []string{}, + CONFIGURE_HOST: "", // later + DESTDIR: destdir, + CXX: "clang++", + CXXFLAGS: []string{}, + GOARCH: ooniArch, + GOARM: "", // maybe later + LD: "", + LDFLAGS: []string{}, // empty + OPENSSL_API_DEFINE: "", + OPENSSL_COMPILER: "", // later + RANLIB: "", + STRIP: "", + } + switch ooniArch { + case "arm": + /* + out.CC = filepath.Join(out.BINPATH, "armv7a-linux-androideabi21-clang") + out.CXX = filepath.Join(out.BINPATH, "armv7a-linux-androideabi21-clang++") + out.GOARM = "7" + out.CONFIGURE_HOST = "arm-linux-androideabi" + out.OPENSSL_COMPILER = "android-arm" + */ + case "arm64": + /* + out.CC = filepath.Join(out.BINPATH, "aarch64-linux-android21-clang") + out.CXX = filepath.Join(out.BINPATH, "aarch64-linux-android21-clang++") + out.CONFIGURE_HOST = "aarch64-linux-android" + out.OPENSSL_COMPILER = "android-arm64" + */ + case "386": + /* + out.CC = filepath.Join(out.BINPATH, "i686-linux-android21-clang") + out.CXX = filepath.Join(out.BINPATH, "i686-linux-android21-clang++") + out.CONFIGURE_HOST = "i686-linux-android" + out.OPENSSL_COMPILER = "android-x86" + */ + case "amd64": + /* + out.CC = filepath.Join(out.BINPATH, "x86_64-linux-android21-clang") + out.CXX = filepath.Join(out.BINPATH, "x86_64-linux-android21-clang++") + out.CONFIGURE_HOST = "x86_64-linux-android" + out.OPENSSL_COMPILER = "android-x86_64" + */ + default: + panic(errors.New("unsupported ooniArch")) + } + out.AS = out.CC + return out +} + +// iosCdepsBuildArch builds the given dependency for the given arch +func iosCdepsBuildArch(deps buildtoolmodel.Dependencies, arch string, name string) { + cdenv := iosNewCBuildEnv(arch) + switch name { + case "libevent": + cdepsLibeventBuildMain(cdenv, deps) + case "openssl": + cdepsOpenSSLBuildMain(cdenv, deps) + case "tor": + cdepsTorBuildMain(cdenv, deps) + case "zlib": + cdepsZlibBuildMain(cdenv, deps) + default: + panic(fmt.Errorf("unknown dependency: %s", name)) + } +} From 189be6542b42424caa9518376b0c58c2c65f3ce0 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 10 Oct 2023 15:06:44 +0200 Subject: [PATCH 2/8] x --- internal/cmd/buildtool/ios.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/cmd/buildtool/ios.go b/internal/cmd/buildtool/ios.go index 500b8d789d..9a61d5cffe 100644 --- a/internal/cmd/buildtool/ios.go +++ b/internal/cmd/buildtool/ios.go @@ -104,6 +104,10 @@ func iosNewCBuildEnv(ooniArch string) *cBuildEnv { } switch ooniArch { case "arm": + out.CFLAGS = []string{ + "-arch", "armv7", + "-isysroot", "/Library/Developer/CommandLineTools/" + } /* out.CC = filepath.Join(out.BINPATH, "armv7a-linux-androideabi21-clang") out.CXX = filepath.Join(out.BINPATH, "armv7a-linux-androideabi21-clang++") From 9513b30fca7b2d10c9c2c3a232927e2b815bf84d Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 09:18:07 +0200 Subject: [PATCH 3/8] feat: attempt to build tor for iOS Part of https://github.com/ooni/probe/issues/2564 --- go.mod | 5 +- go.sum | 14 +- internal/cmd/buildtool/android.go | 40 ++-- internal/cmd/buildtool/builddeps.go | 4 + internal/cmd/buildtool/cbuildenv.go | 45 ++-- internal/cmd/buildtool/cdepslibevent.go | 4 + internal/cmd/buildtool/cdepsopenssl.go | 8 +- internal/cmd/buildtool/cdepstor.go | 1 + .../internal/buildtoolmodel/buildtoolmodel.go | 8 +- .../internal/buildtooltest/buildtooltest.go | 5 + internal/cmd/buildtool/ios.go | 198 ++++++++++++------ internal/cmd/buildtool/linuxcdeps.go | 36 ++-- internal/libtor/enabled.go | 5 + internal/libtor/ios/amd64/.gitignore | 2 + internal/libtor/ios/arm64/.gitignore | 2 + internal/tunnel/tordesktop.go | 2 +- internal/tunnel/torembed.go | 2 +- internal/tunnel/tormobile.go | 35 ---- 18 files changed, 234 insertions(+), 182 deletions(-) create mode 100644 internal/libtor/ios/amd64/.gitignore create mode 100644 internal/libtor/ios/arm64/.gitignore delete mode 100644 internal/tunnel/tormobile.go diff --git a/go.mod b/go.mod index cb036df062..eeb76c6da5 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/miekg/dns v1.1.56 github.com/mitchellh/go-wordwrap v1.0.1 github.com/montanaflynn/stats v0.7.1 - github.com/ooni/go-libtor v1.1.8 github.com/ooni/netem v0.0.0-20230920215742-15f3ffec0107 github.com/ooni/oocrypto v0.5.5 github.com/ooni/oohttp v0.6.5 @@ -145,9 +144,9 @@ require ( github.com/xtaci/kcp-go/v5 v5.6.2 // indirect github.com/xtaci/smux v1.5.24 // indirect gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect - golang.org/x/mod v0.12.0 // indirect + golang.org/x/mod v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.13.0 // indirect + golang.org/x/tools v0.14.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index 0f3aaf7ff2..02f515d0ef 100644 --- a/go.sum +++ b/go.sum @@ -74,7 +74,6 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= -github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw= github.com/cretz/bine v0.2.0 h1:8GiDRGlTgz+o8H9DSnsl+5MeBK4HsExxgl6WgzOCuZo= github.com/cretz/bine v0.2.0/go.mod h1:WU4o9QR9wWp8AVKtTM1XD5vUHkEqnf2vVSo6dBqbetI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -322,8 +321,6 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/ooni/go-libtor v1.1.8 h1:Wo3V3DVTxl5vZdxtQakqYP+DAHx7pPtAFSl1bnAa08w= -github.com/ooni/go-libtor v1.1.8/go.mod h1:q1YyLwRD9GeMyeerVvwc0vJ2YgwDLTp2bdVcrh/JXyI= github.com/ooni/netem v0.0.0-20230920215742-15f3ffec0107 h1:PktaCPQ1NYZOaK+J8pQGYiPCYFkGR5H3ZURg9zPkQsI= github.com/ooni/netem v0.0.0-20230920215742-15f3ffec0107/go.mod h1:5X3Lk4+cnrwrQiYgRlCWXgV33IMDgLaO5s1x0DD/fO0= github.com/ooni/oocrypto v0.5.5 h1:x0wIgtBfghVu8Ok0tR/xVyfHlo646hN1LB/5bzuXcIg= @@ -550,7 +547,6 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -588,8 +584,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -626,7 +622,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -718,8 +714,8 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= +golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= +golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/cmd/buildtool/android.go b/internal/cmd/buildtool/android.go index 1068fd59a7..2527cc99b8 100644 --- a/internal/cmd/buildtool/android.go +++ b/internal/cmd/buildtool/android.go @@ -215,25 +215,27 @@ func androidNewCBuildEnv(androidHome, ndkDir, ooniArch string) *cBuildEnv { "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": diff --git a/internal/cmd/buildtool/builddeps.go b/internal/cmd/buildtool/builddeps.go index b499b45a48..32349f0089 100644 --- a/internal/cmd/buildtool/builddeps.go +++ b/internal/cmd/buildtool/builddeps.go @@ -82,3 +82,7 @@ func (*buildDeps) GOOS() string { func (*buildDeps) VerifySHA256(expectedSHA256 string, tarball string) { cdepsMustVerifySHA256(expectedSHA256, tarball) } + +func (*buildDeps) XCRun(args ...string) string { + return iosXCRun(args...) +} 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/cdepslibevent.go b/internal/cmd/buildtool/cdepslibevent.go index b2fd0a8d6c..f6b8504079 100644 --- a/internal/cmd/buildtool/cdepslibevent.go +++ b/internal/cmd/buildtool/cdepslibevent.go @@ -49,6 +49,10 @@ func cdepsLibeventBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependenci } envp := cBuildExportAutotools(cBuildMerge(globalEnv, localEnv)) + // On iOS, we need PKG_CONFIG_PATH to convince libevent to use the OpenSSL we built but] + // always letting libevent's configure be pkgconfig aware would probably be fine + envp.Append("PKG_CONFIG_PATH", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) + argv := runtimex.Try1(shellx.NewArgv("./configure")) if globalEnv.CONFIGURE_HOST != "" { argv.Append("--host=" + globalEnv.CONFIGURE_HOST) diff --git a/internal/cmd/buildtool/cdepsopenssl.go b/internal/cmd/buildtool/cdepsopenssl.go index dbecb9f624..9ad149860e 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)) @@ -84,5 +82,7 @@ func cdepsOpenSSLBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependencie )) must.Run(log.Log, "make", "DESTDIR="+globalEnv.DESTDIR, "install_dev") - must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) + + // FIXME: we need to explain this change + //must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) } diff --git a/internal/cmd/buildtool/cdepstor.go b/internal/cmd/buildtool/cdepstor.go index 0098b0ff03..2c47aa7a22 100644 --- a/internal/cmd/buildtool/cdepstor.go +++ b/internal/cmd/buildtool/cdepstor.go @@ -56,6 +56,7 @@ func cdepsTorBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependencies) { "--disable-tool-name-check", "--disable-systemd", "--prefix=/", + "--disable-unittests", ) 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..a15f3bc039 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 @@ -50,6 +53,7 @@ type Dependencies interface { // expected version of mingw-w64. WindowsMingwCheck() - // GOOS returns the current GOOS. - GOOS() string + // XCRun executes `xcrun [args]` and returns its output or + // invokes PANIC in case of failure. + XCRun(args ...string) string } diff --git a/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go b/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go index 17bffeeca3..6ef3d9e171 100644 --- a/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go +++ b/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go @@ -245,3 +245,8 @@ func (cc *DependenciesCallCounter) increment(name string) { } cc.Counter[name]++ } + +// XCRun implements buildtoolmodel.Dependencies. +func (*DependenciesCallCounter) XCRun(args ...string) string { + panic("unimplemented") // TODO(bassosimone): implement this function +} diff --git a/internal/cmd/buildtool/ios.go b/internal/cmd/buildtool/ios.go index 9a61d5cffe..e12b0a9532 100644 --- a/internal/cmd/buildtool/ios.go +++ b/internal/cmd/buildtool/ios.go @@ -12,6 +12,7 @@ import ( "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/cmd/buildtool/internal/buildtoolmodel" + "github.com/ooni/probe-cli/v3/internal/must" "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/shellx" "github.com/spf13/cobra" @@ -66,96 +67,157 @@ func iosBuildGomobile(deps buildtoolmodel.Dependencies) { // iosCdepsBuildMain builds C dependencies for ios. func iosCdepsBuildMain(name string, deps buildtoolmodel.Dependencies) { runtimex.Assert( - runtime.GOOS == "darwin" || runtime.GOOS == "linux", + runtime.GOOS == "darwin", "this command requires darwin or linux", ) - archs := []string{"arm", "arm64", "386", "amd64"} + + // The assembly of the arm version is broken for unknown reasons + //archs := []string{"arm", "arm64", "386", "amd64"} + // It seems there's no support for 386? + //archs := []string{"arm64", "386", "amd64"} + archs := []string{"arm64", "amd64"} for _, arch := range archs { iosCdepsBuildArch(deps, arch, name) } } +// iosPlatformForOONIArch maps the ooniArch to the iOS platform +var iosPlatformForOONIArch = map[string]string{ + "386": "iphonesimulator", + "amd64": "iphonesimulator", + "arm": "iphoneos", + "arm64": "iphoneos", +} + +// iosAppleArchForOONIArch maps the ooniArch to the corresponding apple arch +var iosAppleArchForOONIArch = map[string]string{ + "386": "i386", + "amd64": "x86_64", + "arm": "armv7s", + "arm64": "arm64", +} + +// iosMinVersionFlagForOONIArch maps the ooniArch to the corresponding compiler flag +// to set the minimum version of either iphoneos or iphonesimulator. +// +// TODO(bassosimone): the OpenSSL build sets -mios-version-min to a very low value +// and I *think* (but I don't *know* whether) these two flags are aliasing each other. +var iosMinVersionFlagForOONIArch = map[string]string{ + "386": "-mios-simulator-version-min=", + "amd64": "-mios-simulator-version-min=", + "arm": "-miphoneos-version-min=", + "arm64": "-miphoneos-version-min=", +} + +// iosCdepsBuildArch builds the given dependency for the given arch +func iosCdepsBuildArch(deps buildtoolmodel.Dependencies, ooniArch string, name string) { + cdenv := iosNewCBuildEnv(deps, ooniArch) + switch name { + case "libevent": + cdepsLibeventBuildMain(cdenv, deps) + case "openssl": + cdepsOpenSSLBuildMain(cdenv, deps) + case "tor": + cdepsTorBuildMain(cdenv, deps) + case "zlib": + cdepsZlibBuildMain(cdenv, deps) + default: + panic(fmt.Errorf("unknown dependency: %s", name)) + } +} + +// iosMinVersion is the minimum version that we support. +// +// Note: "iOS 10 is the maximum deployment target for 32-bit targets". +// +// See https://stackoverflow.com/questions/47772435. +const iosMinVersion = "10.0" + // iosNewCBuildEnv creates a new [cBuildEnv] for the given ooniArch ("arm", "arm64", "386", "amd64"). -func iosNewCBuildEnv(ooniArch string) *cBuildEnv { +func iosNewCBuildEnv(deps buildtoolmodel.Dependencies, ooniArch string) *cBuildEnv { destdir := runtimex.Try1(filepath.Abs(filepath.Join( // must be absolute "internal", "libtor", "ios", ooniArch, ))) - // export CFLAGS="-O3 -arch armv7 -arch armv7s -arch arm64 -isysroot $XCODE_ROOT/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${IPHONE_SDKVERSION}.sdk -mios-version-min=${IPHONE_SDKVERSION} -fembed-bitcode" + + var ( + appleArch = iosAppleArchForOONIArch[ooniArch] + minVersionFlag = iosMinVersionFlagForOONIArch[ooniArch] + platform = iosPlatformForOONIArch[ooniArch] + ) + runtimex.Assert(appleArch != "", "empty appleArch") + runtimex.Assert(minVersionFlag != "", "empty minVersionFlag") + runtimex.Assert(platform != "", "empty platform") + + isysroot := deps.XCRun("-sdk", platform, "--show-sdk-path") + out := &cBuildEnv{ - ANDROID_HOME: "", - ANDROID_NDK_ROOT: "", - AS: "", // later - AR: "", - BINPATH: "", - CC: "clang", - CFLAGS: []string{}, - CONFIGURE_HOST: "", // later - DESTDIR: destdir, - CXX: "clang++", - CXXFLAGS: []string{}, - GOARCH: ooniArch, - GOARM: "", // maybe later - LD: "", - LDFLAGS: []string{}, // empty - OPENSSL_API_DEFINE: "", - OPENSSL_COMPILER: "", // later - RANLIB: "", - STRIP: "", + ANDROID_HOME: "", // not needed + ANDROID_NDK_ROOT: "", // not needed + AS: deps.XCRun("-find", "-sdk", platform, "as"), + AR: deps.XCRun("-find", "-sdk", platform, "ar"), + BINPATH: "", // not needed + CC: deps.XCRun("-find", "-sdk", platform, "cc"), + CFLAGS: []string{ + "-isysroot", isysroot, + minVersionFlag + iosMinVersion, // tricky: they must be concatenated + "-O2", + "-arch", appleArch, + "-fembed-bitcode", + }, + CONFIGURE_HOST: "", // later + DESTDIR: destdir, + CXX: deps.XCRun("-find", "-sdk", platform, "c++"), + CXXFLAGS: []string{ + "-isysroot", isysroot, + minVersionFlag + iosMinVersion, // tricky: they must be concatenated + "-arch", appleArch, + "-fembed-bitcode", + "-O2", + }, + GOARCH: ooniArch, + GOARM: "", // maybe later + LD: deps.XCRun("-find", "-sdk", platform, "ld"), + LDFLAGS: []string{ + "-isysroot", isysroot, + minVersionFlag + iosMinVersion, // tricky: they must be concatenated + "-arch", appleArch, + "-fembed-bitcode", + }, + OPENSSL_COMPILER: "", // later + OPENSSL_POST_COMPILER_FLAGS: []string{ + minVersionFlag + iosMinVersion, // tricky: they must be concatenated + "-fembed-bitcode", + }, + RANLIB: deps.XCRun("-find", "-sdk", platform, "ranlib"), + STRIP: deps.XCRun("-find", "-sdk", platform, "strip"), } + switch ooniArch { case "arm": - out.CFLAGS = []string{ - "-arch", "armv7", - "-isysroot", "/Library/Developer/CommandLineTools/" - } - /* - out.CC = filepath.Join(out.BINPATH, "armv7a-linux-androideabi21-clang") - out.CXX = filepath.Join(out.BINPATH, "armv7a-linux-androideabi21-clang++") - out.GOARM = "7" - out.CONFIGURE_HOST = "arm-linux-androideabi" - out.OPENSSL_COMPILER = "android-arm" - */ + out.CONFIGURE_HOST = "arm-apple-darwin" + out.GOARM = "7" + out.OPENSSL_COMPILER = "ios-xcrun" case "arm64": - /* - out.CC = filepath.Join(out.BINPATH, "aarch64-linux-android21-clang") - out.CXX = filepath.Join(out.BINPATH, "aarch64-linux-android21-clang++") - out.CONFIGURE_HOST = "aarch64-linux-android" - out.OPENSSL_COMPILER = "android-arm64" - */ + out.CONFIGURE_HOST = "arm-apple-darwin" + out.GOARM = "" + out.OPENSSL_COMPILER = "ios64-xcrun" case "386": - /* - out.CC = filepath.Join(out.BINPATH, "i686-linux-android21-clang") - out.CXX = filepath.Join(out.BINPATH, "i686-linux-android21-clang++") - out.CONFIGURE_HOST = "i686-linux-android" - out.OPENSSL_COMPILER = "android-x86" - */ + out.CONFIGURE_HOST = "i386-apple-darwin" + out.GOARM = "" + out.OPENSSL_COMPILER = "iossimulator-i386-xcrun" case "amd64": - /* - out.CC = filepath.Join(out.BINPATH, "x86_64-linux-android21-clang") - out.CXX = filepath.Join(out.BINPATH, "x86_64-linux-android21-clang++") - out.CONFIGURE_HOST = "x86_64-linux-android" - out.OPENSSL_COMPILER = "android-x86_64" - */ + out.CONFIGURE_HOST = "x86_64-apple-darwin" + out.GOARM = "" + out.OPENSSL_COMPILER = "iossimulator-xcrun" default: panic(errors.New("unsupported ooniArch")) } - out.AS = out.CC + return out } -// iosCdepsBuildArch builds the given dependency for the given arch -func iosCdepsBuildArch(deps buildtoolmodel.Dependencies, arch string, name string) { - cdenv := iosNewCBuildEnv(arch) - switch name { - case "libevent": - cdepsLibeventBuildMain(cdenv, deps) - case "openssl": - cdepsOpenSSLBuildMain(cdenv, deps) - case "tor": - cdepsTorBuildMain(cdenv, deps) - case "zlib": - cdepsZlibBuildMain(cdenv, deps) - default: - panic(fmt.Errorf("unknown dependency: %s", name)) - } +// iosXCRun invokes `xcrun [args]` and returns its result of panics. This function +// is called indirectly by the iOS build through [buildtoolmodel.Dependencies]. +func iosXCRun(args ...string) string { + return string(must.FirstLineBytes(must.RunOutput(log.Log, "xcrun", args...))) } 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": diff --git a/internal/libtor/enabled.go b/internal/libtor/enabled.go index 64daa7ef44..f29619fd20 100644 --- a/internal/libtor/enabled.go +++ b/internal/libtor/enabled.go @@ -18,6 +18,11 @@ package libtor // #cgo android,amd64 CFLAGS: -I${SRCDIR}/android/amd64/include // #cgo android,amd64 LDFLAGS: -L${SRCDIR}/android/amd64/lib -ltor -levent -lssl -lcrypto -lz -lm // +// #cgo ios,arm64 CFLAGS: -I${SRCDIR}/ios/arm64/include +// #cgo ios,arm64 LDFLAGS: -L${SRCDIR}/ios/arm64/lib -ltor -levent -lssl -lcrypto -lz -lm +// #cgo ios,amd64 CFLAGS: -I${SRCDIR}/ios/amd64/include +// #cgo ios,amd64 LDFLAGS: -L${SRCDIR}/ios/amd64/lib -ltor -levent -lssl -lcrypto -lz -lm +// // #include // #include // #include diff --git a/internal/libtor/ios/amd64/.gitignore b/internal/libtor/ios/amd64/.gitignore new file mode 100644 index 0000000000..f32e7dc720 --- /dev/null +++ b/internal/libtor/ios/amd64/.gitignore @@ -0,0 +1,2 @@ +/include +/lib diff --git a/internal/libtor/ios/arm64/.gitignore b/internal/libtor/ios/arm64/.gitignore new file mode 100644 index 0000000000..f32e7dc720 --- /dev/null +++ b/internal/libtor/ios/arm64/.gitignore @@ -0,0 +1,2 @@ +/include +/lib diff --git a/internal/tunnel/tordesktop.go b/internal/tunnel/tordesktop.go index bda2bb74dc..c228b87298 100644 --- a/internal/tunnel/tordesktop.go +++ b/internal/tunnel/tordesktop.go @@ -1,4 +1,4 @@ -//go:build !android && !ios && !ooni_libtor +//go:build !ooni_libtor package tunnel diff --git a/internal/tunnel/torembed.go b/internal/tunnel/torembed.go index df7bf67991..f915ed385e 100644 --- a/internal/tunnel/torembed.go +++ b/internal/tunnel/torembed.go @@ -1,4 +1,4 @@ -//go:build ooni_libtor && android +//go:build ooni_libtor package tunnel diff --git a/internal/tunnel/tormobile.go b/internal/tunnel/tormobile.go deleted file mode 100644 index 651ed325d8..0000000000 --- a/internal/tunnel/tormobile.go +++ /dev/null @@ -1,35 +0,0 @@ -//go:build ios || (android && !ooni_libtor) - -package tunnel - -// -// This file implements our old strategy for running tor on mobile, which -// is based on integrating github.com/ooni/go-libtor. We currently only use -// this stategy on iOS. See https://github.com/ooni/probe/issues/2365. -// - -import ( - "strings" - - "github.com/cretz/bine/tor" - "github.com/ooni/go-libtor" -) - -// getTorStartConf in this configuration uses github.com/ooni/go-libtor. -func getTorStartConf(config *Config, dataDir string, extraArgs []string) (*tor.StartConf, error) { - config.logger().Infof("tunnel: tor: exec: %s %s", - dataDir, strings.Join(extraArgs, " ")) - return &tor.StartConf{ - // Implementation note: go-libtor leaks a file descriptor when you set - // UseEmbeddedControlConn, as documented by - // - // https://github.com/ooni/probe/issues/2405 - // - // This is why we're not using this field for now. The above mentioned - // issue also refers to what a possible fix would look like. - ProcessCreator: libtor.Creator, - DataDir: dataDir, - ExtraArgs: extraArgs, - NoHush: true, - }, nil -} From fd9dbcac2ccac8b61f78ab40d3c26da2f103a744 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 09:27:44 +0200 Subject: [PATCH 4/8] fix ci build (well, hopefully) --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index a1dcd72886..43ddb7b580 100644 --- a/Makefile +++ b/Makefile @@ -98,6 +98,7 @@ android: search/for/java #help: The `make MOBILE/ios` command builds the oonimkall library for iOS. .PHONY: MOBILE/ios MOBILE/ios: search/for/zip search/for/xcode + go run ./internal/cmd/buildtool ios cdeps zlib openssl libevent tor go run ./internal/cmd/buildtool ios gomobile ./MOBILE/ios/zipframework ./MOBILE/ios/createpodspec From 1b55ff35ac83fed07d6054b1d482097e3e20f2a5 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 09:47:06 +0200 Subject: [PATCH 5/8] fix ci build (well, hopefully) --- .github/workflows/ios.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index fbcffd885e..c3bf45a1cb 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -35,6 +35,8 @@ jobs: PSIPHON_CONFIG_KEY: ${{ secrets.PSIPHON_CONFIG_KEY }} PSIPHON_CONFIG_JSON_AGE_BASE64: ${{ secrets.PSIPHON_CONFIG_JSON_AGE_BASE64 }} + - run: brew install coreutils # we need sha256sum to verify tarballs + - run: make EXPECTED_XCODE_VERSION=14.2 MOBILE/ios - uses: actions/upload-artifact@v3 From 4f1bf9a3d282d326d2fec2e7263213ab981c9edb Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 09:57:47 +0200 Subject: [PATCH 6/8] fix ci build (well, hopefully) --- .github/workflows/ios.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index c3bf45a1cb..8a57a05ac8 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -35,7 +35,8 @@ jobs: PSIPHON_CONFIG_KEY: ${{ secrets.PSIPHON_CONFIG_KEY }} PSIPHON_CONFIG_JSON_AGE_BASE64: ${{ secrets.PSIPHON_CONFIG_JSON_AGE_BASE64 }} - - run: brew install coreutils # we need sha256sum to verify tarballs + # we need coreutils for sha256 plus a bunch of GNU build tools + - run: brew install autoconf automake coreutils libtool - run: make EXPECTED_XCODE_VERSION=14.2 MOBILE/ios From e69ae114be2aaa13185f9d4725f741d8a776e5ba Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 11:52:55 +0200 Subject: [PATCH 7/8] x --- .github/workflows/ios.yml | 3 - Makefile | 1 - go.mod | 5 +- go.sum | 14 +- internal/cmd/buildtool/builddeps.go | 4 - internal/cmd/buildtool/cdepslibevent.go | 4 - internal/cmd/buildtool/cdepsopenssl.go | 4 +- .../internal/buildtooltest/buildtooltest.go | 5 - internal/cmd/buildtool/ios.go | 177 ------------------ internal/libtor/enabled.go | 5 - internal/libtor/ios/amd64/.gitignore | 2 - internal/libtor/ios/arm64/.gitignore | 2 - internal/tunnel/tordesktop.go | 2 +- internal/tunnel/torembed.go | 2 +- internal/tunnel/tormobile.go | 35 ++++ 15 files changed, 50 insertions(+), 215 deletions(-) delete mode 100644 internal/libtor/ios/amd64/.gitignore delete mode 100644 internal/libtor/ios/arm64/.gitignore create mode 100644 internal/tunnel/tormobile.go diff --git a/.github/workflows/ios.yml b/.github/workflows/ios.yml index 8a57a05ac8..fbcffd885e 100644 --- a/.github/workflows/ios.yml +++ b/.github/workflows/ios.yml @@ -35,9 +35,6 @@ jobs: PSIPHON_CONFIG_KEY: ${{ secrets.PSIPHON_CONFIG_KEY }} PSIPHON_CONFIG_JSON_AGE_BASE64: ${{ secrets.PSIPHON_CONFIG_JSON_AGE_BASE64 }} - # we need coreutils for sha256 plus a bunch of GNU build tools - - run: brew install autoconf automake coreutils libtool - - run: make EXPECTED_XCODE_VERSION=14.2 MOBILE/ios - uses: actions/upload-artifact@v3 diff --git a/Makefile b/Makefile index 43ddb7b580..a1dcd72886 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,6 @@ android: search/for/java #help: The `make MOBILE/ios` command builds the oonimkall library for iOS. .PHONY: MOBILE/ios MOBILE/ios: search/for/zip search/for/xcode - go run ./internal/cmd/buildtool ios cdeps zlib openssl libevent tor go run ./internal/cmd/buildtool ios gomobile ./MOBILE/ios/zipframework ./MOBILE/ios/createpodspec diff --git a/go.mod b/go.mod index eeb76c6da5..cb036df062 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( github.com/miekg/dns v1.1.56 github.com/mitchellh/go-wordwrap v1.0.1 github.com/montanaflynn/stats v0.7.1 + github.com/ooni/go-libtor v1.1.8 github.com/ooni/netem v0.0.0-20230920215742-15f3ffec0107 github.com/ooni/oocrypto v0.5.5 github.com/ooni/oohttp v0.6.5 @@ -144,9 +145,9 @@ require ( github.com/xtaci/kcp-go/v5 v5.6.2 // indirect github.com/xtaci/smux v1.5.24 // indirect gitlab.com/yawning/bsaes.git v0.0.0-20190805113838-0a714cd429ec // indirect - golang.org/x/mod v0.13.0 // indirect + golang.org/x/mod v0.12.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.14.0 // indirect + golang.org/x/tools v0.13.0 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index 02f515d0ef..0f3aaf7ff2 100644 --- a/go.sum +++ b/go.sum @@ -74,6 +74,7 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.17 h1:QeVUsEDNrLBW4tMgZHvxy18sKtr6VI492kBhUfhDJNI= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw= github.com/cretz/bine v0.2.0 h1:8GiDRGlTgz+o8H9DSnsl+5MeBK4HsExxgl6WgzOCuZo= github.com/cretz/bine v0.2.0/go.mod h1:WU4o9QR9wWp8AVKtTM1XD5vUHkEqnf2vVSo6dBqbetI= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -321,6 +322,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/ooni/go-libtor v1.1.8 h1:Wo3V3DVTxl5vZdxtQakqYP+DAHx7pPtAFSl1bnAa08w= +github.com/ooni/go-libtor v1.1.8/go.mod h1:q1YyLwRD9GeMyeerVvwc0vJ2YgwDLTp2bdVcrh/JXyI= github.com/ooni/netem v0.0.0-20230920215742-15f3ffec0107 h1:PktaCPQ1NYZOaK+J8pQGYiPCYFkGR5H3ZURg9zPkQsI= github.com/ooni/netem v0.0.0-20230920215742-15f3ffec0107/go.mod h1:5X3Lk4+cnrwrQiYgRlCWXgV33IMDgLaO5s1x0DD/fO0= github.com/ooni/oocrypto v0.5.5 h1:x0wIgtBfghVu8Ok0tR/xVyfHlo646hN1LB/5bzuXcIg= @@ -547,6 +550,7 @@ go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -584,8 +588,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= -golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -622,7 +626,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -714,8 +718,8 @@ golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= -golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/internal/cmd/buildtool/builddeps.go b/internal/cmd/buildtool/builddeps.go index 32349f0089..b499b45a48 100644 --- a/internal/cmd/buildtool/builddeps.go +++ b/internal/cmd/buildtool/builddeps.go @@ -82,7 +82,3 @@ func (*buildDeps) GOOS() string { func (*buildDeps) VerifySHA256(expectedSHA256 string, tarball string) { cdepsMustVerifySHA256(expectedSHA256, tarball) } - -func (*buildDeps) XCRun(args ...string) string { - return iosXCRun(args...) -} diff --git a/internal/cmd/buildtool/cdepslibevent.go b/internal/cmd/buildtool/cdepslibevent.go index f6b8504079..b2fd0a8d6c 100644 --- a/internal/cmd/buildtool/cdepslibevent.go +++ b/internal/cmd/buildtool/cdepslibevent.go @@ -49,10 +49,6 @@ func cdepsLibeventBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependenci } envp := cBuildExportAutotools(cBuildMerge(globalEnv, localEnv)) - // On iOS, we need PKG_CONFIG_PATH to convince libevent to use the OpenSSL we built but] - // always letting libevent's configure be pkgconfig aware would probably be fine - envp.Append("PKG_CONFIG_PATH", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) - argv := runtimex.Try1(shellx.NewArgv("./configure")) if globalEnv.CONFIGURE_HOST != "" { argv.Append("--host=" + globalEnv.CONFIGURE_HOST) diff --git a/internal/cmd/buildtool/cdepsopenssl.go b/internal/cmd/buildtool/cdepsopenssl.go index 9ad149860e..9dad79eaba 100644 --- a/internal/cmd/buildtool/cdepsopenssl.go +++ b/internal/cmd/buildtool/cdepsopenssl.go @@ -82,7 +82,5 @@ func cdepsOpenSSLBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependencie )) must.Run(log.Log, "make", "DESTDIR="+globalEnv.DESTDIR, "install_dev") - - // FIXME: we need to explain this change - //must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) + must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) } diff --git a/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go b/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go index 6ef3d9e171..17bffeeca3 100644 --- a/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go +++ b/internal/cmd/buildtool/internal/buildtooltest/buildtooltest.go @@ -245,8 +245,3 @@ func (cc *DependenciesCallCounter) increment(name string) { } cc.Counter[name]++ } - -// XCRun implements buildtoolmodel.Dependencies. -func (*DependenciesCallCounter) XCRun(args ...string) string { - panic("unimplemented") // TODO(bassosimone): implement this function -} diff --git a/internal/cmd/buildtool/ios.go b/internal/cmd/buildtool/ios.go index e12b0a9532..9208b8c00d 100644 --- a/internal/cmd/buildtool/ios.go +++ b/internal/cmd/buildtool/ios.go @@ -5,15 +5,10 @@ package main // import ( - "errors" - "fmt" "path/filepath" - "runtime" "github.com/apex/log" "github.com/ooni/probe-cli/v3/internal/cmd/buildtool/internal/buildtoolmodel" - "github.com/ooni/probe-cli/v3/internal/must" - "github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/shellx" "github.com/spf13/cobra" ) @@ -24,7 +19,6 @@ func iosSubcommand() *cobra.Command { Use: "ios", Short: "Builds oonimkall and its dependencies for iOS", } - cmd.AddCommand(&cobra.Command{ Use: "gomobile", Short: "Builds oonimkall for iOS using gomobile", @@ -32,18 +26,6 @@ func iosSubcommand() *cobra.Command { iosBuildGomobile(&buildDeps{}) }, }) - - cmd.AddCommand(&cobra.Command{ - Use: "cdeps {zlib|openssl|libevent|tor} [zlib|openssl|libevent|tor...]", - Short: "Cross compiles C dependencies for iOS", - Run: func(cmd *cobra.Command, args []string) { - for _, arg := range args { - iosCdepsBuildMain(arg, &buildDeps{}) - } - }, - Args: cobra.MinimumNArgs(1), - }) - return cmd } @@ -59,165 +41,6 @@ func iosBuildGomobile(deps buildtoolmodel.Dependencies) { output: filepath.Join("MOBILE", "ios", "oonimkall.xcframework"), target: "ios", } - log.Info("building the mobile library using gomobile") gomobileBuild(config) } - -// iosCdepsBuildMain builds C dependencies for ios. -func iosCdepsBuildMain(name string, deps buildtoolmodel.Dependencies) { - runtimex.Assert( - runtime.GOOS == "darwin", - "this command requires darwin or linux", - ) - - // The assembly of the arm version is broken for unknown reasons - //archs := []string{"arm", "arm64", "386", "amd64"} - // It seems there's no support for 386? - //archs := []string{"arm64", "386", "amd64"} - archs := []string{"arm64", "amd64"} - for _, arch := range archs { - iosCdepsBuildArch(deps, arch, name) - } -} - -// iosPlatformForOONIArch maps the ooniArch to the iOS platform -var iosPlatformForOONIArch = map[string]string{ - "386": "iphonesimulator", - "amd64": "iphonesimulator", - "arm": "iphoneos", - "arm64": "iphoneos", -} - -// iosAppleArchForOONIArch maps the ooniArch to the corresponding apple arch -var iosAppleArchForOONIArch = map[string]string{ - "386": "i386", - "amd64": "x86_64", - "arm": "armv7s", - "arm64": "arm64", -} - -// iosMinVersionFlagForOONIArch maps the ooniArch to the corresponding compiler flag -// to set the minimum version of either iphoneos or iphonesimulator. -// -// TODO(bassosimone): the OpenSSL build sets -mios-version-min to a very low value -// and I *think* (but I don't *know* whether) these two flags are aliasing each other. -var iosMinVersionFlagForOONIArch = map[string]string{ - "386": "-mios-simulator-version-min=", - "amd64": "-mios-simulator-version-min=", - "arm": "-miphoneos-version-min=", - "arm64": "-miphoneos-version-min=", -} - -// iosCdepsBuildArch builds the given dependency for the given arch -func iosCdepsBuildArch(deps buildtoolmodel.Dependencies, ooniArch string, name string) { - cdenv := iosNewCBuildEnv(deps, ooniArch) - switch name { - case "libevent": - cdepsLibeventBuildMain(cdenv, deps) - case "openssl": - cdepsOpenSSLBuildMain(cdenv, deps) - case "tor": - cdepsTorBuildMain(cdenv, deps) - case "zlib": - cdepsZlibBuildMain(cdenv, deps) - default: - panic(fmt.Errorf("unknown dependency: %s", name)) - } -} - -// iosMinVersion is the minimum version that we support. -// -// Note: "iOS 10 is the maximum deployment target for 32-bit targets". -// -// See https://stackoverflow.com/questions/47772435. -const iosMinVersion = "10.0" - -// iosNewCBuildEnv creates a new [cBuildEnv] for the given ooniArch ("arm", "arm64", "386", "amd64"). -func iosNewCBuildEnv(deps buildtoolmodel.Dependencies, ooniArch string) *cBuildEnv { - destdir := runtimex.Try1(filepath.Abs(filepath.Join( // must be absolute - "internal", "libtor", "ios", ooniArch, - ))) - - var ( - appleArch = iosAppleArchForOONIArch[ooniArch] - minVersionFlag = iosMinVersionFlagForOONIArch[ooniArch] - platform = iosPlatformForOONIArch[ooniArch] - ) - runtimex.Assert(appleArch != "", "empty appleArch") - runtimex.Assert(minVersionFlag != "", "empty minVersionFlag") - runtimex.Assert(platform != "", "empty platform") - - isysroot := deps.XCRun("-sdk", platform, "--show-sdk-path") - - out := &cBuildEnv{ - ANDROID_HOME: "", // not needed - ANDROID_NDK_ROOT: "", // not needed - AS: deps.XCRun("-find", "-sdk", platform, "as"), - AR: deps.XCRun("-find", "-sdk", platform, "ar"), - BINPATH: "", // not needed - CC: deps.XCRun("-find", "-sdk", platform, "cc"), - CFLAGS: []string{ - "-isysroot", isysroot, - minVersionFlag + iosMinVersion, // tricky: they must be concatenated - "-O2", - "-arch", appleArch, - "-fembed-bitcode", - }, - CONFIGURE_HOST: "", // later - DESTDIR: destdir, - CXX: deps.XCRun("-find", "-sdk", platform, "c++"), - CXXFLAGS: []string{ - "-isysroot", isysroot, - minVersionFlag + iosMinVersion, // tricky: they must be concatenated - "-arch", appleArch, - "-fembed-bitcode", - "-O2", - }, - GOARCH: ooniArch, - GOARM: "", // maybe later - LD: deps.XCRun("-find", "-sdk", platform, "ld"), - LDFLAGS: []string{ - "-isysroot", isysroot, - minVersionFlag + iosMinVersion, // tricky: they must be concatenated - "-arch", appleArch, - "-fembed-bitcode", - }, - OPENSSL_COMPILER: "", // later - OPENSSL_POST_COMPILER_FLAGS: []string{ - minVersionFlag + iosMinVersion, // tricky: they must be concatenated - "-fembed-bitcode", - }, - RANLIB: deps.XCRun("-find", "-sdk", platform, "ranlib"), - STRIP: deps.XCRun("-find", "-sdk", platform, "strip"), - } - - switch ooniArch { - case "arm": - out.CONFIGURE_HOST = "arm-apple-darwin" - out.GOARM = "7" - out.OPENSSL_COMPILER = "ios-xcrun" - case "arm64": - out.CONFIGURE_HOST = "arm-apple-darwin" - out.GOARM = "" - out.OPENSSL_COMPILER = "ios64-xcrun" - case "386": - out.CONFIGURE_HOST = "i386-apple-darwin" - out.GOARM = "" - out.OPENSSL_COMPILER = "iossimulator-i386-xcrun" - case "amd64": - out.CONFIGURE_HOST = "x86_64-apple-darwin" - out.GOARM = "" - out.OPENSSL_COMPILER = "iossimulator-xcrun" - default: - panic(errors.New("unsupported ooniArch")) - } - - return out -} - -// iosXCRun invokes `xcrun [args]` and returns its result of panics. This function -// is called indirectly by the iOS build through [buildtoolmodel.Dependencies]. -func iosXCRun(args ...string) string { - return string(must.FirstLineBytes(must.RunOutput(log.Log, "xcrun", args...))) -} diff --git a/internal/libtor/enabled.go b/internal/libtor/enabled.go index f29619fd20..64daa7ef44 100644 --- a/internal/libtor/enabled.go +++ b/internal/libtor/enabled.go @@ -18,11 +18,6 @@ package libtor // #cgo android,amd64 CFLAGS: -I${SRCDIR}/android/amd64/include // #cgo android,amd64 LDFLAGS: -L${SRCDIR}/android/amd64/lib -ltor -levent -lssl -lcrypto -lz -lm // -// #cgo ios,arm64 CFLAGS: -I${SRCDIR}/ios/arm64/include -// #cgo ios,arm64 LDFLAGS: -L${SRCDIR}/ios/arm64/lib -ltor -levent -lssl -lcrypto -lz -lm -// #cgo ios,amd64 CFLAGS: -I${SRCDIR}/ios/amd64/include -// #cgo ios,amd64 LDFLAGS: -L${SRCDIR}/ios/amd64/lib -ltor -levent -lssl -lcrypto -lz -lm -// // #include // #include // #include diff --git a/internal/libtor/ios/amd64/.gitignore b/internal/libtor/ios/amd64/.gitignore deleted file mode 100644 index f32e7dc720..0000000000 --- a/internal/libtor/ios/amd64/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/include -/lib diff --git a/internal/libtor/ios/arm64/.gitignore b/internal/libtor/ios/arm64/.gitignore deleted file mode 100644 index f32e7dc720..0000000000 --- a/internal/libtor/ios/arm64/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/include -/lib diff --git a/internal/tunnel/tordesktop.go b/internal/tunnel/tordesktop.go index c228b87298..bda2bb74dc 100644 --- a/internal/tunnel/tordesktop.go +++ b/internal/tunnel/tordesktop.go @@ -1,4 +1,4 @@ -//go:build !ooni_libtor +//go:build !android && !ios && !ooni_libtor package tunnel diff --git a/internal/tunnel/torembed.go b/internal/tunnel/torembed.go index f915ed385e..df7bf67991 100644 --- a/internal/tunnel/torembed.go +++ b/internal/tunnel/torembed.go @@ -1,4 +1,4 @@ -//go:build ooni_libtor +//go:build ooni_libtor && android package tunnel diff --git a/internal/tunnel/tormobile.go b/internal/tunnel/tormobile.go new file mode 100644 index 0000000000..651ed325d8 --- /dev/null +++ b/internal/tunnel/tormobile.go @@ -0,0 +1,35 @@ +//go:build ios || (android && !ooni_libtor) + +package tunnel + +// +// This file implements our old strategy for running tor on mobile, which +// is based on integrating github.com/ooni/go-libtor. We currently only use +// this stategy on iOS. See https://github.com/ooni/probe/issues/2365. +// + +import ( + "strings" + + "github.com/cretz/bine/tor" + "github.com/ooni/go-libtor" +) + +// getTorStartConf in this configuration uses github.com/ooni/go-libtor. +func getTorStartConf(config *Config, dataDir string, extraArgs []string) (*tor.StartConf, error) { + config.logger().Infof("tunnel: tor: exec: %s %s", + dataDir, strings.Join(extraArgs, " ")) + return &tor.StartConf{ + // Implementation note: go-libtor leaks a file descriptor when you set + // UseEmbeddedControlConn, as documented by + // + // https://github.com/ooni/probe/issues/2405 + // + // This is why we're not using this field for now. The above mentioned + // issue also refers to what a possible fix would look like. + ProcessCreator: libtor.Creator, + DataDir: dataDir, + ExtraArgs: extraArgs, + NoHush: true, + }, nil +} From f3a2a823a661eb838de05b524b8f20112c3f11a2 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 11:56:11 +0200 Subject: [PATCH 8/8] x --- internal/cmd/buildtool/android_test.go | 4 ++++ internal/cmd/buildtool/linuxcdeps_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/internal/cmd/buildtool/android_test.go b/internal/cmd/buildtool/android_test.go index 416a857d2d..7daa564dfb 100644 --- a/internal/cmd/buildtool/android_test.go +++ b/internal/cmd/buildtool/android_test.go @@ -1701,6 +1701,7 @@ func TestAndroidBuildCdepsTor(t *testing.T) { "--disable-tool-name-check", "--disable-systemd", "--prefix=/", + "--disable-unittests", }, }, { Env: []string{}, @@ -1777,6 +1778,7 @@ func TestAndroidBuildCdepsTor(t *testing.T) { "--disable-tool-name-check", "--disable-systemd", "--prefix=/", + "--disable-unittests", }, }, { Env: []string{}, @@ -1853,6 +1855,7 @@ func TestAndroidBuildCdepsTor(t *testing.T) { "--disable-tool-name-check", "--disable-systemd", "--prefix=/", + "--disable-unittests", }, }, { Env: []string{}, @@ -1929,6 +1932,7 @@ func TestAndroidBuildCdepsTor(t *testing.T) { "--disable-tool-name-check", "--disable-systemd", "--prefix=/", + "--disable-unittests", }, }, { Env: []string{}, diff --git a/internal/cmd/buildtool/linuxcdeps_test.go b/internal/cmd/buildtool/linuxcdeps_test.go index 87a5f6cbeb..85ca172934 100644 --- a/internal/cmd/buildtool/linuxcdeps_test.go +++ b/internal/cmd/buildtool/linuxcdeps_test.go @@ -346,6 +346,7 @@ func TestLinuxCdepsBuildMain(t *testing.T) { "--disable-tool-name-check", "--disable-systemd", "--prefix=/", + "--disable-unittests", }, }, { Env: []string{},