From a9ddbafbe9018631230eb57e58ec3d378b835f3b Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 1 Jul 2024 15:01:34 -0700 Subject: [PATCH 1/4] Pull log 1.14.0 with it's no_net (no_http) --- ca_bundle.go | 4 ++-- go.mod | 4 ++-- go.sum | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ca_bundle.go b/ca_bundle.go index 7fa2aee..e6942e4 100644 --- a/ca_bundle.go +++ b/ca_bundle.go @@ -3,8 +3,8 @@ // (c) 2024 Fortio Authors // See LICENSE -//go:build !no_tls_fallback -// +build !no_tls_fallback +//go:build !no_tls_fallback && !no_net +// +build !no_tls_fallback,!no_net package cli // import "fortio.org/cli" diff --git a/go.mod b/go.mod index 5505fa6..8746901 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,9 @@ module fortio.org/cli go 1.18 require ( - fortio.org/log v1.12.2 + fortio.org/log v1.14.0 fortio.org/version v1.0.4 golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8 ) -require fortio.org/struct2env v0.4.0 // indirect +require fortio.org/struct2env v0.4.1 // indirect diff --git a/go.sum b/go.sum index 34a05a5..517ff28 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ -fortio.org/log v1.12.2 h1:JwLDFvEUKGfqA09fcf+mOn8kxsvwhjXV92xghxNnnwA= -fortio.org/log v1.12.2/go.mod h1:1tMBG/Elr6YqjmJCWiejJp2FPvXg7/9UAN0Rfpkyt1o= -fortio.org/struct2env v0.4.0 h1:k5alSOTf3YHiB3MuacjDHQ3YhVWvNZ95ZP/a6MqvyLo= -fortio.org/struct2env v0.4.0/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410= +fortio.org/log v1.14.0 h1:ZkIc3Qqwfs9Dd931k07YzoC+bqCpJKEjVlZwxgXW3Nw= +fortio.org/log v1.14.0/go.mod h1:1tnXMqd5rZAgvSeHJkD2xXpyXRBzdeXtKLZuzNLIwtA= +fortio.org/struct2env v0.4.1 h1:rJludAMO5eBvpWplWEQNqoVDFZr4RWMQX7RUapgZyc0= +fortio.org/struct2env v0.4.1/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410= fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U= fortio.org/version v1.0.4/go.mod h1:2JQp9Ax+tm6QKiGuzR5nJY63kFeANcgrZ0osoQFDVm0= golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8 h1:+kWDWI3Eb5cPIOr4cP+R2RLDwK3/dXppL+7XmSOh2LA= From 22342d1a8896fa7b3432ee5090495b4e1a799a7b Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 1 Jul 2024 15:23:08 -0700 Subject: [PATCH 2/4] Add tag info in readme --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 6c20344..ddb6787 100644 --- a/README.md +++ b/README.md @@ -142,3 +142,11 @@ It does this by defaulting to the bundle provided by `golang.org/x/crypto/x509ro See https://github.com/fortio/multicurl for a good example. If you do not want this behavior, build using `-tags no_tls_fallback`. + +### Small binaries + +If you application doesn't do http request/response logging at all, use `-tags no_http` or `-tags no_net` (that one will also imply `no_tls_fallback`) and save 1.1 Mbyte in your binary's size (because the linker isn't smart enough to see net/http isn't actually used) + +And, if you don't need any of the advanced JSON logging (which is quite likely with a cli), use `-tags no_json` the logger will still produce json structured logging just not as advanced if what you log are deep structures - this saves another 130k or so. + +These tags from from [fortio.org/log](https://github.com/fortio/log) v1.14 and later From 4678a365f37cf33508648d6530a2ebffb851445f Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 1 Jul 2024 15:45:25 -0700 Subject: [PATCH 3/4] Add build command example, also update fallback while at it - strangely dependabot doesn't do it automatically --- README.md | 7 ++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ddb6787..953e315 100644 --- a/README.md +++ b/README.md @@ -149,4 +149,9 @@ If you application doesn't do http request/response logging at all, use `-tags n And, if you don't need any of the advanced JSON logging (which is quite likely with a cli), use `-tags no_json` the logger will still produce json structured logging just not as advanced if what you log are deep structures - this saves another 130k or so. -These tags from from [fortio.org/log](https://github.com/fortio/log) v1.14 and later +These tags are from [fortio.org/log](https://github.com/fortio/log) v1.14 and later + +In summary: for smallest pure local cli binaries using this package: +``` +CGO_ENABLE=0 go build -trimpath -ldflags="-w -s" -tags no_net,no_json . +``` diff --git a/go.mod b/go.mod index 8746901..7f19e7a 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( fortio.org/log v1.14.0 fortio.org/version v1.0.4 - golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8 + golang.org/x/crypto/x509roots/fallback v0.0.0-20240626151235-a6a393ffd658 ) require fortio.org/struct2env v0.4.1 // indirect diff --git a/go.sum b/go.sum index 517ff28..36dc097 100644 --- a/go.sum +++ b/go.sum @@ -4,5 +4,5 @@ fortio.org/struct2env v0.4.1 h1:rJludAMO5eBvpWplWEQNqoVDFZr4RWMQX7RUapgZyc0= fortio.org/struct2env v0.4.1/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410= fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U= fortio.org/version v1.0.4/go.mod h1:2JQp9Ax+tm6QKiGuzR5nJY63kFeANcgrZ0osoQFDVm0= -golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8 h1:+kWDWI3Eb5cPIOr4cP+R2RLDwK3/dXppL+7XmSOh2LA= -golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8/go.mod h1:kNa9WdvYnzFwC79zRpLRMJbdEFlhyM5RPFBBZp/wWH8= +golang.org/x/crypto/x509roots/fallback v0.0.0-20240626151235-a6a393ffd658 h1:i7K6wQLN/0oxF7FT3tKkfMCstxoT4VGG36YIB9ZKLzI= +golang.org/x/crypto/x509roots/fallback v0.0.0-20240626151235-a6a393ffd658/go.mod h1:kNa9WdvYnzFwC79zRpLRMJbdEFlhyM5RPFBBZp/wWH8= From fb5c0e999c8a46f60a9b8c64c70bbfe8053c95bf Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 1 Jul 2024 16:00:37 -0700 Subject: [PATCH 4/4] add more data about sizes --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 953e315..c2fddce 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ If you do not want this behavior, build using `-tags no_tls_fallback`. ### Small binaries -If you application doesn't do http request/response logging at all, use `-tags no_http` or `-tags no_net` (that one will also imply `no_tls_fallback`) and save 1.1 Mbyte in your binary's size (because the linker isn't smart enough to see net/http isn't actually used) +If you application doesn't do http request/response logging at all, use `-tags no_http` or `-tags no_net` (that one will also imply `no_tls_fallback`) and save 1.6 Mbytes in your binary's size (because the linker isn't smart enough to see net/http isn't actually used) (1.1Mbytes for log's no_http and 530k from the no_tls_fallback) And, if you don't need any of the advanced JSON logging (which is quite likely with a cli), use `-tags no_json` the logger will still produce json structured logging just not as advanced if what you log are deep structures - this saves another 130k or so. @@ -155,3 +155,4 @@ In summary: for smallest pure local cli binaries using this package: ``` CGO_ENABLE=0 go build -trimpath -ldflags="-w -s" -tags no_net,no_json . ``` +saves ~1.7Mbytes in total (a basic cli dependending on this package will then only be about 300k more as an hello world yet include color help, buildinfo, version, logging etc)