Closed nikolaydubina closed 10 months ago
faced same issue
Maybe I found the cause, it seems that this library is not compatible with go 1.20. When I tried to run it with go 1.19, it worked
confirmed, it seems imports are broken when gomacro is compiled with go >= 1.20 ouch.
[UPDATE] I checked this bug by compiling and running gomacro with various Go toolchains. The results are:
[OK] Go 1.19.12 from go.dev/dl/
[BUG] Go 1.20.7 from go.dev/dl/
[BUG] Go 1.21rc4 from go.dev/dl/
[OK] Go 1.19.12 from Debian package golang-1.19:amd64
[OK] Go 1.20.7 from Debian package golang-1.20:amd64
[OK] Go 1.21rc3 from Debian package golang-1.21:amd64
So Debian is actively applying a patch that fixes this issue. Now I need to find such patch and check why it was not merged into the upstream Go toolchain at go.dev/dl/
@cosmos72 I just built go from http://deb.debian.org/debian/pool/main/g/golang-1.20/golang-1.20_1.20.7.orig.tar.gz without applying any of the debian patches (and then reinstalled gomacro
using go install ...
), and it seems to work:
$ gomacro
gomacro> import "context"
gomacro> import "github.com/docker/docker/client"
[...]
// debug: compiling plugin "/home/lars/go/src/gomacro.imports/gomacro_pid_460679/import_1" ...
gomacro> import "github.com/docker/docker/api/types"
// debug: running "go get github.com/docker/docker/api/types" ...
[...]
// debug: compiling plugin "/home/lars/go/src/gomacro.imports/gomacro_pid_460679/import_2" ...
gomacro> dc, _ := client.NewClientWithOpts(client.FromEnv)
gomacro> dc.ContainerList(context.Background(), types.ContainerListOptions{})
[...list of containers here...]
<nil> // error
The patches included in the package in any case don't sound relevant:
0001-Disable-test-for-UserHomeDir.patch
0002-Fix-Lintian-warnings-about-wrong-interpreter-path.patch
0003-cmd-dist-increase-default-timeout-scale-for-arm.patch
0004-skip-userns-test-in-schroot-as-well.patch
I see the same behavior if I rebuild go from https://go.dev/dl/go1.20.7.src.tar.gz and then re-install gomacro.
Thanks for the cross checks! Do I understand correctly that as last check you downloaded Go toolchain sources from https://go.dev/dl/go1.20.7.src.tar.gz, you compiled them (with some other Go toolchain), and using it to compile and run gomacro this bug disappeared?
I think so. I'm trying to retest while being sure to explicitly clear the build cache each time because I'm having some reproducibility issues.
The problem appears to be independent of the version of Go used to build gomacro
; what matters is the version of Go in $PATH
at runtime.
I built and installed gomacro
using Go versions 1.19.4, 1.20, and 1.20.7 (installed from upstream release binaries from https://go.dev/dl/), and then tried a third party import
with different versions of Go in $PATH
.
Here's the test script:
#!/bin/sh
set -e
topdir=$PWD
for buildversion in 1.19.4 1.20 1.20.7; do
(
PATH=/usr/local/pkg/go-$buildversion/bin:$PATH
{
go env GOCACHE
go env GOMODCACHE
go env GOPATH
} | sudo xargs rm -rf
echo "installing gomacro with Go $(go version)"
go install github.com/cosmos72/gomacro@latest
GOMACRO="$(go env GOPATH)/bin/gomacro"
for goversion in 1.19.4 1.20 1.20.7; do
workdir=$(mktemp -d "$PWD/gotestXXXXXX")
(
cd "$workdir"
GOCACHE=$workdir/go/cache
GOMODCACHE=$workdir/go/mod
export GOCACHE GOMODCACHE
PATH=/usr/local/pkg/go-$goversion/bin:$PATH
$GOMACRO <<-EOF > test.out 2> test.err
import "github.com/docker/docker/client"
EOF
{
if grep -q "exports zero constants" test.out; then
echo "build: $(go version $GOMACRO) runtime: $goversion status: FAILED"
else
echo "build: $(go version $GOMACRO) runtime: $goversion status: SUCCESS"
fi
} | tee -a $topdir/results.txt
)
sudo rm -rf "$workdir"
done
)
done
And the results:
build: /home/lars/go/bin/gomacro: go1.19.4 runtime: 1.19.4 status: SUCCESS
build: /home/lars/go/bin/gomacro: go1.19.4 runtime: 1.20 status: SUCCESS
build: /home/lars/go/bin/gomacro: go1.19.4 runtime: 1.20.7 status: SUCCESS
build: /home/lars/go/bin/gomacro: go1.20 runtime: 1.19.4 status: SUCCESS
build: /home/lars/go/bin/gomacro: go1.20 runtime: 1.20 status: FAILED
build: /home/lars/go/bin/gomacro: go1.20 runtime: 1.20.7 status: SUCCESS
build: /home/lars/go/bin/gomacro: go1.20.7 runtime: 1.19.4 status: SUCCESS
build: /home/lars/go/bin/gomacro: go1.20.7 runtime: 1.20 status: SUCCESS
build: /home/lars/go/bin/gomacro: go1.20.7 runtime: 1.20.7 status: FAILED
Which are...weird. For anything more recent than 1.19.4, the import
fails when the runtime version matches the build version.
Thanks a lot for the extensive tests!
Wow, thats's even weirder than I thought, especially if you consider that gomacro tries to find and use the Go toolchain it was compiled with, befofe falling back to the one in $PATH
On the bright side, that means that I now have a functioning gomacro
, which I really appreciate as a way of running quick tests. Thanks for your work!
Commit 0c584cc732cfc29d8df0ffbb63a1190ec690abc6 updates the dependencies to newest golang.org/x/tools
At least for me, it fixes this bug and I can now import third-party packages even when gomacro is compiled with Go toolchain >= 1.20.0
Hopefully, it will work for everybody else too :)
Please try it and report the outcome
commit 3dc08f5f8feafb4e7b2f7b7c360ab6811010801a adds checks while importing third-party packages, in order to skip importing generic types and generic functions, which are not supported yet
No further feedback received, closing after timeout as it's supposedly fixed.
The bug is still on my go1.23.0 windows/amd64:
Hello @Cactusinhand, importing third-party packages is not well supported on Windows:
the procedure is cumbersome and requires recompiling gomacro after adding the package you want to import. For details, see https://github.com/cosmos72/gomacro/?tab=readme-ov-file#other-systems
You may have an easier time by running gomacro or gophernotes inside Docker or a Linux virtual machine. Maybe running them inside WSL may work too.
go env