Repository navigation
Description
Writing up a brain dump, so might be a bit messy.
Currently the go version used by the Go SDK is 1.21.3. However, a user module can set a custom go version (using go.mod/go.work) to a higher version, like 1.22.0.
Now, this can cause fun issues it seems? I'm not quite sure what happens, but essentially in
dagger/cmd/codegen/generator/go/generator.go
Lines 292 to 302 in b2450fc
| pkgs, err := packages.Load(&packages.Config{ | |
| Context: ctx, | |
| Dir: dir, | |
| Tests: false, | |
| Fset: fset, | |
| Mode: packages.NeedName | | |
| packages.NeedTypes | | |
| packages.NeedSyntax | | |
| packages.NeedTypesInfo | | |
| packages.NeedModule, | |
| }, ".") |
We can get a package returned that:
{
"ID": "foobar",
"Name": "main",
"PkgPath": "foobar",
}for a go.mod that looks like this:
module foobar
go 1.22.0This silent failure is caused by https://github.com/golang/tools/blob/a821e617f30094a078bfdc1d63623b93365b3130/go/packages/packages.go#L1039 - Checker.Files *can` return an error if we try and type-check for a go version that is greater than the currently installed version.
This behavior makes sense (though the silent failure really doesn't). Note: GOTOOLCHAIN=auto (as added in #6652 doesn't help for this, it only helps for compiling, not parsing+processing the package).
However, this leaves us with the problem of how to manage this from the point-of-view of the Go SDK (cc @vito @sipsma). A few options:
- We simply explicitly ban doing this - if the go version bundled into the Go SDK tarball is X, then we don't allow >X with a nice error message.
- Note, we could potentially decouple the codegen go version from the engine go version to be higher with very little risk.
- However, since the Go SDK is built into the engine, we'd have to re-release every time we want to bump go version, which is a pain (but not unavoidable at our pace of releases).
- We rework package loading significantly, instead somehow custom compiling a binary at runtime to do this (with the right go-version), then serializing + deserializing this into the codegen binary.
- This would go poorly if the types structure changes, not sure if the go compatibility requirement allows this.
- Also, complexity 😭
- Or (as a variation) recompile the
codegenbinary itself if it asks for a different go version. - Just attempt to parse it as best we can, by explicitly overriding the go version for typechecking - if we fail, append a warning about the upgrade, but otherwise continue on!
- This could just work, there are really minor type differences between versions anyways.
- Not quite sure how we implement this though, hopefully we don't need to mess around with any
x/toolsinternals.
Open to other suggestions 🎉
Activity
jedevc commentedon Feb 21, 2024
Also gonna milestone this one, because this is a supreme pain (I spent a whole day tracking out what was really going on), at the very least we should have a nice error message for this.
sipsma commentedon Feb 22, 2024
What's the failure? That
Nameismainrather thanfoobar? Just double checking.In terms of handling this better, the fact that the go sdk is builtin to the engine is indeed a pretty big wrench here. We do that to avoid hard deps on the internet and to avoid problems in corp envs around need to use registry proxies. I can see some routes to do something like:
Which, if I understand the issue correctly, would probably be one possible reasonable next step. And in the long term I have some ideas on making it easier for users to customize what specifically gets builtin to the engine (or equivalent).
This coincidentally overlaps quite a bit with what I was doing in #6714 today, I will think a bit more tomorrow and see what can be done for v0.10.
jedevc commentedon Feb 22, 2024
Ahh, sorry, such a brain dump I didn't bother to write down the actual error.
We get
cannot find default codegen DaggerObject interfacebecause no type-checking is done so no types can be found (but instead of erroring, we get back an invalid package struct).chore: error out with too new go tooling
chore: error out with too new go tooling (#6737)