From 08285b284b4f06da2f5c677175e6fbb1dc138205 Mon Sep 17 00:00:00 2001 From: "kayos@tcp.direct" Date: Tue, 18 Jun 2024 05:18:54 -0700 Subject: [PATCH 1/3] Fix: enable go module by renaming git openssl submodule These days we can't operate out of `$GOPATH`, as this package used to require to some degree. Fix this by adding an underscore in the front of the `openssl` git submodule. Ref: https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns --- .gitmodules | 2 +- openssl => _openssl | 0 build.go | 30 ++++++++++++++++-------------- go.mod | 11 +++++++++++ go.sum | 24 ++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 15 deletions(-) rename openssl => _openssl (100%) create mode 100644 go.mod create mode 100644 go.sum diff --git a/.gitmodules b/.gitmodules index 2035a5ea..ab518a8e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "openssl"] - path = openssl + path = _openssl url = https://github.com/openssl/openssl.git [submodule "libevent"] path = libevent diff --git a/openssl b/_openssl similarity index 100% rename from openssl rename to _openssl diff --git a/build.go b/build.go index 1805d48b..eb834a0a 100644 --- a/build.go +++ b/build.go @@ -19,12 +19,14 @@ import ( "strings" ) -var verbose bool -var host string -var autopointPath string -var folders = []string{"openssl", "libevent", "zlib", "xz", "tor"} -var absCurrDir = getAbsCurrDir() -var numJobs = fmt.Sprintf("-j%d", runtime.NumCPU()) +var ( + verbose bool + host string + autopointPath string + folders = []string{"_openssl", "libevent", "zlib", "xz", "tor"} + absCurrDir = getAbsCurrDir() + numJobs = fmt.Sprintf("-j%d", runtime.NumCPU()) +) func main() { flag.BoolVar(&verbose, "verbose", false, "Whether to show command output") @@ -109,7 +111,7 @@ func build(folder string) error { } } return nil - case "openssl": + case "_openssl": prefix := pwd + "/dist" cmds := [][]string{ {"sh", "./config", "--prefix=" + prefix, "--openssldir=" + prefix, "no-shared", "no-dso", "no-zlib"}, @@ -158,7 +160,7 @@ func build(folder string) error { {"sh", "-l", "./autogen.sh"}, {"sh", "./configure", "--prefix=" + pwd + "/dist", "--disable-shared", "--enable-static", "--with-pic", "--disable-samples", "--disable-libevent-regress", - "CPPFLAGS=-I../openssl/dist/include", "LDFLAGS=-L../openssl/dist/lib"}, + "CPPFLAGS=-I../_openssl/dist/include", "LDFLAGS=-L../_openssl/dist/lib"}, {"make", numJobs}, {"make", "install"}, } @@ -206,7 +208,7 @@ func build(folder string) error { torConf = []string{"sh", "./configure", "--prefix=" + pwd + "/dist", "--disable-gcc-hardening", "--disable-system-torrc", "--disable-asciidoc", "--enable-static-libevent", "--with-libevent-dir=" + pwd + "/../libevent/dist", - "--enable-static-openssl", "--with-openssl-dir=" + pwd + "/../openssl/dist", + "--enable-static-openssl", "--with-openssl-dir=" + pwd + "/../_openssl/dist", "--enable-static-zlib", "--with-zlib-dir=" + pwd + "/../zlib/dist", "--disable-systemd", "--disable-lzma", "--disable-seccomp"} @@ -235,7 +237,7 @@ func build(folder string) error { {"make", "install"}, }) default: - return fmt.Errorf("Unrecognized folder: %v", folder) + return fmt.Errorf("unrecognized folder: %v", folder) } } @@ -255,9 +257,9 @@ func clean(folder string) (err error) { makefile := "Makefile" switch folder { // OpenSSL needs to have the dist folder removed first - case "openssl": - if err := os.RemoveAll("openssl/dist/lib"); err != nil { - return fmt.Errorf("Unable to remove openssl/dist/lib: %v", err) + case "_openssl": + if err := os.RemoveAll("_openssl/dist/lib"); err != nil { + return fmt.Errorf("unable to remove _openssl/dist/lib: %v", err) } // Zlib needs to have a prefix and needs a special windows makefile case "zlib": @@ -334,7 +336,7 @@ func getLibSets() ([]*libSet, error) { &libSet{"libevent/dist/lib", []string{"event"}}, &libSet{"xz/dist/lib", []string{"lzma"}}, &libSet{"zlib/dist/lib", []string{"z"}}, - &libSet{"openssl/dist/lib", []string{"ssl", "crypto"}}, + &libSet{"_openssl/dist/lib", []string{"ssl", "crypto"}}, ) return libSets, nil } diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..ada3da65 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/cretz/tor-static + +go 1.22.4 + +require github.com/cretz/bine v0.2.0 + +require ( + golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect + golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect + golang.org/x/sys v0.0.0-20210423082822-04245dca01da // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..5b169c32 --- /dev/null +++ b/go.sum @@ -0,0 +1,24 @@ +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 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From 187c19cd692952a7c76e0be8390556c8865b10a1 Mon Sep 17 00:00:00 2001 From: "kayos@tcp.direct" Date: Tue, 18 Jun 2024 05:19:01 -0700 Subject: [PATCH 2/3] Fix: disable building docs to reduce dependency footprint --- build.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.go b/build.go index eb834a0a..d9f1ae9a 100644 --- a/build.go +++ b/build.go @@ -188,7 +188,7 @@ func build(folder string) error { env = []string{"PATH=" + autopointPath + ":" + os.Getenv("PATH")} } cmds := [][]string{ - {"sh", "-l", "./autogen.sh"}, + {"sh", "-l", "./autogen.sh", "--no-po4a"}, {"sh", "./configure", "--prefix=" + pwd + "/dist", "--disable-shared", "--enable-static", "--disable-doc", "--disable-scripts", "--disable-xz", "--disable-xzdec", "--disable-lzmadec", "--disable-lzmainfo", "--disable-lzma-links"}, @@ -210,7 +210,8 @@ func build(folder string) error { "--enable-static-libevent", "--with-libevent-dir=" + pwd + "/../libevent/dist", "--enable-static-openssl", "--with-openssl-dir=" + pwd + "/../_openssl/dist", "--enable-static-zlib", "--with-zlib-dir=" + pwd + "/../zlib/dist", - "--disable-systemd", "--disable-lzma", "--disable-seccomp"} + "--disable-systemd", "--disable-lzma", "--disable-seccomp", + "--disable-html-manual", "--disable-manpage"} if host != "" { torConf = append(torConf, "--host="+host) From 8e873b54595324812e891b657a6bede43d39840f Mon Sep 17 00:00:00 2001 From: "kayos@tcp.direct" Date: Tue, 18 Jun 2024 05:46:33 -0700 Subject: [PATCH 3/3] Feat: Add `-j` flag to control build concurrency Hilariously enough on my overclocked i9 if I try to build tor with the previously hardcoded `fmt.Sprintf("-j%d", runtime.NumCPU())` - I get sporadic internal gcc errors. This allows passing `-j 16`, which in my case permits me to build tor. --- build.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build.go b/build.go index d9f1ae9a..553a286d 100644 --- a/build.go +++ b/build.go @@ -25,14 +25,17 @@ var ( autopointPath string folders = []string{"_openssl", "libevent", "zlib", "xz", "tor"} absCurrDir = getAbsCurrDir() - numJobs = fmt.Sprintf("-j%d", runtime.NumCPU()) + numJobsInt = runtime.NumCPU() + numJobs = "" ) func main() { flag.BoolVar(&verbose, "verbose", false, "Whether to show command output") flag.StringVar(&host, "host", "", "Host option, useful for cross-compilation") flag.StringVar(&autopointPath, "autopoint-path", "/usr/local/opt/gettext/bin", "OSX: Directory that contains autopoint binary") + flag.IntVar(&numJobsInt, "j", runtime.NumCPU(), "Number of jobs to run in parallel") flag.Parse() + numJobs = fmt.Sprintf("-j%d", numJobsInt) if len(flag.Args()) != 1 { log.Fatal("Missing command. Can be build-all, build-, clean-all, clean-, show-libs, or package-libs") }