From 12a61a21e9925ea8ffa1d3743d6c6294690d511e Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Tue, 10 Oct 2023 15:06:26 +0200 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 c4acb74697399b4cd327f9cec47cff42dc802d05 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 14:58:35 +0200 Subject: [PATCH 07/12] x --- .github/workflows/ios.yml | 3 - Makefile | 1 - go.mod | 5 +- go.sum | 14 +- internal/cmd/buildtool/builddeps.go | 4 - internal/cmd/buildtool/cdepsopenssl.go | 3 +- .../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 ++++ 14 files changed, 51 insertions(+), 209 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/cdepsopenssl.go b/internal/cmd/buildtool/cdepsopenssl.go index 9ad149860e..d9ffa46e74 100644 --- a/internal/cmd/buildtool/cdepsopenssl.go +++ b/internal/cmd/buildtool/cdepsopenssl.go @@ -83,6 +83,7 @@ func cdepsOpenSSLBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependencie must.Run(log.Log, "make", "DESTDIR="+globalEnv.DESTDIR, "install_dev") - // FIXME: we need to explain this change + // We used to delete the pkgconfig but it turns out this is import for iOS builds, which + // means now we need to keep it. See https://github.com/ooni/probe-cli/pull/1366 for details. //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 245842a3f43f39089c4bafb5f8755cdfa925aa51 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 15:23:23 +0200 Subject: [PATCH 08/12] x --- go.mod | 4 ++-- go.sum | 10 ++++---- internal/cmd/buildtool/android_test.go | 28 ++++------------------- internal/cmd/buildtool/linuxcdeps_test.go | 7 +----- 4 files changed, 12 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index cb036df062..d7f6a5eafc 100644 --- a/go.mod +++ b/go.mod @@ -145,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.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..a47a76309a 100644 --- a/go.sum +++ b/go.sum @@ -588,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.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 +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.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 +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.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_test.go b/internal/cmd/buildtool/android_test.go index 7daa564dfb..b5f9ffc762 100644 --- a/internal/cmd/buildtool/android_test.go +++ b/internal/cmd/buildtool/android_test.go @@ -754,12 +754,6 @@ func TestAndroidBuildCdepsOpenSSL(t *testing.T) { "DESTDIR=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm", "install_dev", }, - }, { - Env: []string{}, - Argv: []string{ - "rm", "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig", - }, }, { Env: []string{}, Argv: []string{ @@ -815,12 +809,6 @@ func TestAndroidBuildCdepsOpenSSL(t *testing.T) { "DESTDIR=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64", "install_dev", }, - }, { - Env: []string{}, - Argv: []string{ - "rm", "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig", - }, }, { Env: []string{}, Argv: []string{ @@ -876,12 +864,6 @@ func TestAndroidBuildCdepsOpenSSL(t *testing.T) { "DESTDIR=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386", "install_dev", }, - }, { - Env: []string{}, - Argv: []string{ - "rm", "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig", - }, }, { Env: []string{}, Argv: []string{ @@ -937,12 +919,6 @@ func TestAndroidBuildCdepsOpenSSL(t *testing.T) { "DESTDIR=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64", "install_dev", }, - }, { - Env: []string{}, - Argv: []string{ - "rm", "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig", - }, }}, }} @@ -1045,6 +1021,7 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { "CXXFLAGS=-fdata-sections -ffunction-sections -fstack-protector-strong -funwind-tables -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -fpic -mthumb -Oz -DANDROID", "-I"+faketopdir+"/internal/cmd/buildtool/internal/libtor/android/arm/include", ), + "PKG_CONFIG_PATH=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig", }, Argv: []string{ "./configure", @@ -1195,6 +1172,7 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { "CXXFLAGS=-fdata-sections -ffunction-sections -fstack-protector-strong -funwind-tables -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -fpic -O2 -DANDROID", "-I"+faketopdir+"/internal/cmd/buildtool/internal/libtor/android/arm64/include", ), + "PKG_CONFIG_PATH=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig", }, Argv: []string{ "./configure", @@ -1345,6 +1323,7 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { "CXXFLAGS=-fdata-sections -ffunction-sections -fstack-protector-strong -funwind-tables -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -fPIC -O2 -DANDROID -mstackrealign", "-I"+faketopdir+"/internal/cmd/buildtool/internal/libtor/android/386/include", ), + "PKG_CONFIG_PATH=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig", }, Argv: []string{ "./configure", @@ -1495,6 +1474,7 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { "CXXFLAGS=-fdata-sections -ffunction-sections -fstack-protector-strong -funwind-tables -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -fPIC -O2 -DANDROID", "-I"+faketopdir+"/internal/cmd/buildtool/internal/libtor/android/amd64/include", ), + "PKG_CONFIG_PATH=" + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig", }, Argv: []string{ "./configure", diff --git a/internal/cmd/buildtool/linuxcdeps_test.go b/internal/cmd/buildtool/linuxcdeps_test.go index 85ca172934..549bb79ac3 100644 --- a/internal/cmd/buildtool/linuxcdeps_test.go +++ b/internal/cmd/buildtool/linuxcdeps_test.go @@ -136,12 +136,6 @@ func TestLinuxCdepsBuildMain(t *testing.T) { "DESTDIR=" + faketopdir + "/" + sysDepDestDir, "install_dev", }, - }, { - Env: []string{}, - Argv: []string{ - "rm", "-rf", - faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig", - }, }}, }, { name: "we can build libevent", @@ -195,6 +189,7 @@ func TestLinuxCdepsBuildMain(t *testing.T) { faketopdir, sysDepDestDir, ), + "PKG_CONFIG_PATH=" + faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig", }, Argv: []string{ "./configure", From b7b95dd2f161de9f68f6022724a4114710242932 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 15:36:51 +0200 Subject: [PATCH 09/12] preserve openssl.pc --- internal/cmd/buildtool/android_test.go | 128 ++++++++++++++++++++-- internal/cmd/buildtool/cdepslibevent.go | 12 +- internal/cmd/buildtool/linuxcdeps_test.go | 32 +++++- 3 files changed, 161 insertions(+), 11 deletions(-) diff --git a/internal/cmd/buildtool/android_test.go b/internal/cmd/buildtool/android_test.go index b5f9ffc762..30169927bf 100644 --- a/internal/cmd/buildtool/android_test.go +++ b/internal/cmd/buildtool/android_test.go @@ -1054,8 +1054,36 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { Env: []string{}, Argv: []string{ "rm", - "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig/libevent.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig/libevent_core.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig/libevent_extra.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig/libevent_openssl.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm/lib/pkgconfig/libevent_pthreads.pc", }, }, { Env: []string{}, @@ -1205,8 +1233,36 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { Env: []string{}, Argv: []string{ "rm", - "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig/libevent.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig/libevent_core.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig/libevent_extra.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig/libevent_openssl.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/arm64/lib/pkgconfig/libevent_pthreads.pc", }, }, { Env: []string{}, @@ -1356,8 +1412,36 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { Env: []string{}, Argv: []string{ "rm", - "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig/libevent.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig/libevent_core.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig/libevent_extra.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig/libevent_openssl.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/386/lib/pkgconfig/libevent_pthreads.pc", }, }, { Env: []string{}, @@ -1507,8 +1591,36 @@ func TestAndroidBuildCdepsLibevent(t *testing.T) { Env: []string{}, Argv: []string{ "rm", - "-rf", - faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig/libevent.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig/libevent_core.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig/libevent_extra.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig/libevent_openssl.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/internal/cmd/buildtool/internal/libtor/android/amd64/lib/pkgconfig/libevent_pthreads.pc", }, }, { Env: []string{}, diff --git a/internal/cmd/buildtool/cdepslibevent.go b/internal/cmd/buildtool/cdepslibevent.go index f6b8504079..f9c6f6128d 100644 --- a/internal/cmd/buildtool/cdepslibevent.go +++ b/internal/cmd/buildtool/cdepslibevent.go @@ -63,7 +63,17 @@ func cdepsLibeventBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependenci must.Run(log.Log, "make", "V=1", "-j", strconv.Itoa(runtime.NumCPU())) must.Run(log.Log, "make", "DESTDIR="+globalEnv.DESTDIR, "install") must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "bin")) - must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) + + // We used to delete the whole pkgconfig directory but libevent's build needs OpenSSL's + // pkgconfig, so removing the whole directory means rebuilding libevent requires building + // OpenSSL because its pkgconfig is also removed. We discovered this need when working + // on the https://github.com/ooni/probe-cli/pull/1366 MVP. To keep the build idempotent, + // let's be more gentle and just remove libevent's pkgconfig files instead. + must.Run(log.Log, "rm", "-f", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig", "libevent.pc")) + must.Run(log.Log, "rm", "-f", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig", "libevent_core.pc")) + must.Run(log.Log, "rm", "-f", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig", "libevent_extra.pc")) + must.Run(log.Log, "rm", "-f", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig", "libevent_openssl.pc")) + must.Run(log.Log, "rm", "-f", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig", "libevent_pthreads.pc")) // we just need libevent.a must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "libevent.la")) diff --git a/internal/cmd/buildtool/linuxcdeps_test.go b/internal/cmd/buildtool/linuxcdeps_test.go index 549bb79ac3..40d4b5817e 100644 --- a/internal/cmd/buildtool/linuxcdeps_test.go +++ b/internal/cmd/buildtool/linuxcdeps_test.go @@ -221,8 +221,36 @@ func TestLinuxCdepsBuildMain(t *testing.T) { Env: []string{}, Argv: []string{ "rm", - "-rf", - faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig", + "-f", + faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig/libevent.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig/libevent_core.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig/libevent_extra.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig/libevent_openssl.pc", + }, + }, { + Env: []string{}, + Argv: []string{ + "rm", + "-f", + faketopdir + "/" + sysDepDestDir + "/lib/pkgconfig/libevent_pthreads.pc", }, }, { Env: []string{}, From a98541ea700eae17edf46e7f83a37eccc8d8e75a Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 15:38:19 +0200 Subject: [PATCH 10/12] [ci skip] Apply suggestions from code review --- internal/cmd/buildtool/cdepslibevent.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/buildtool/cdepslibevent.go b/internal/cmd/buildtool/cdepslibevent.go index f9c6f6128d..925fb4d4e6 100644 --- a/internal/cmd/buildtool/cdepslibevent.go +++ b/internal/cmd/buildtool/cdepslibevent.go @@ -49,8 +49,8 @@ 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 + // On iOS, we need PKG_CONFIG_PATH to convince libevent to use the OpenSSL we built and + // always letting libevent's configure use pkgconfig is actually fine. envp.Append("PKG_CONFIG_PATH", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) argv := runtimex.Try1(shellx.NewArgv("./configure")) From 62f5a63583e7c56fa2e2c18239211214ee155f4a Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 15:39:40 +0200 Subject: [PATCH 11/12] [ci skip] Update internal/cmd/buildtool/cdepsopenssl.go --- internal/cmd/buildtool/cdepsopenssl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/buildtool/cdepsopenssl.go b/internal/cmd/buildtool/cdepsopenssl.go index d9ffa46e74..55435934b3 100644 --- a/internal/cmd/buildtool/cdepsopenssl.go +++ b/internal/cmd/buildtool/cdepsopenssl.go @@ -83,7 +83,7 @@ func cdepsOpenSSLBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependencie must.Run(log.Log, "make", "DESTDIR="+globalEnv.DESTDIR, "install_dev") - // We used to delete the pkgconfig but it turns out this is import for iOS builds, which + // We used to delete the pkgconfig but it turns out this is important for libevent iOS builds, which // means now we need to keep it. See https://github.com/ooni/probe-cli/pull/1366 for details. //must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) } From 2078d6d3c913323fd1f0ec3f8658112c14615585 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 12 Oct 2023 15:41:16 +0200 Subject: [PATCH 12/12] [ci skip] Apply suggestions from code review --- internal/cmd/buildtool/cdepsopenssl.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/cmd/buildtool/cdepsopenssl.go b/internal/cmd/buildtool/cdepsopenssl.go index 55435934b3..fba0eb6535 100644 --- a/internal/cmd/buildtool/cdepsopenssl.go +++ b/internal/cmd/buildtool/cdepsopenssl.go @@ -84,6 +84,6 @@ func cdepsOpenSSLBuildMain(globalEnv *cBuildEnv, deps buildtoolmodel.Dependencie must.Run(log.Log, "make", "DESTDIR="+globalEnv.DESTDIR, "install_dev") // We used to delete the pkgconfig but it turns out this is important for libevent iOS builds, which - // means now we need to keep it. See https://github.com/ooni/probe-cli/pull/1366 for details. + // means now we need to keep it. See https://github.com/ooni/probe-cli/pull/1369 for details. //must.Run(log.Log, "rm", "-rf", filepath.Join(globalEnv.DESTDIR, "lib", "pkgconfig")) }