Repository navigation
Conversation
|
Exciting feature! I got an error during follow the example: |
|
@wingyplus At which step did this happen? During the |
|
@eunomie i found it during the |
|
🤔 So if you run this command on the branch $ ./hack/dev dagger init --sdk=../../sdk/java modules/my-self-moduleI tried again and everything went fine.
I can see the file in the branch. I don't understand why that doesn't work. But maybe there's something wrong that only works on my machine (like a file not properly added). That sounds strange but could be the case. |
| func (sdk *runtimeModule) HasModuleTypeDefs() bool { | ||
| _, ok := sdk.mod.funcs["moduleTypeDefs"] | ||
| return ok | ||
| } |
There was a problem hiding this comment.
You could just hide that in the TypeDefs function instead of having this checker function.
We want to keep the SDK interface and its components as close as the one implemented by users.
There was a problem hiding this comment.
Currently not. Doesn't mean it can't, I'll have a second look at it.
The TydeDefs method itself is doing the check, and if the moduleTypeDefs doesn't exist it silently redirects to moduleRuntime. But it's also used outside of the call to moduleTypeDefs, to know if we must add the types to the list of dependencies.
I'll see what other solution I can find.
|
Love the TypeDefs split! @jedevc presented this idea last year and I love that it allows registering functions directly from the SDK module instead of having to, for example, build a Go app and run it in a container in order to register type defs. This simplifies a Docker SDK for example, but I also want to build a new SDK in a different language where the code introspection is read from a json file. In this case I want to build a simple container that’s different from what the One thing I would add is that in case you still want to report the type defs from the same code base/runtime that invokes the functions (like Python) I’d rather have |
I share a trace that produced from init call here.
I also see it at |
|
I updated the readme with the Go implementation |
d9f0438 to
1e3a971
Compare
Signed-off-by: Yves Brissaud <[email protected]>
This is an optional new entry point on the module SDK. It's designed to perform the type definition from the module like the actual moduleRuntime when an empty string is passed as argument. If the function doesn't exist, the moduleRuntime is used instead. But this allows to decouple both of them so we can registry types of a module without the runnable module itself because to build it needs the types defined by the module Signed-off-by: Yves Brissaud <[email protected]>
Use `moduleTypeDefs` instead of `moduleRuntime` if available. Cache the runtime as expected if `moduleTypeDefs` has been called. Signed-off-by: Yves Brissaud <[email protected]>
This allows to add the module types as dependencies and thus generate bindings for the module itself. Signed-off-by: Yves Brissaud <[email protected]>
Generate register function for typedefs in a dedicated class so it can be used independently. Signed-off-by: Yves Brissaud <[email protected]>
As the module user code might contain references to the module self types, this allows to generate the typedefs in a project not depending on the current module. It means the typedefs can be generated even if the code cannot compile because it requires the typedefs. Signed-off-by: Yves Brissaud <[email protected]>
Temporary fix to have self module working Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Yves Brissaud <[email protected]>
|
@wingyplus after some time, I finally hit your issue 😅 I'm fixing it |
|
I'm closing this one, splitting the changes in smaller PRs. First part is #10584 |

Note
This is the first part of #10336 and #8030
TypeDefs split
To be able to generate types of the module itself, this means it requires to generate and expose (register to the engine) the types and functions exposed by the module even if the module can't be compiled. If the module is referencing its own types, there's a moment they don't exist.
This circular dependency is cut by allowing module SDKs to expose a new function
moduleTypeDefs. If this function exists, it will be called to register the types instead of calling themoduleRuntime.Previously,
moduleRuntimsis called in two different ways:Instead of this split in the module runtime code, this is now outside:
moduleTypeDefsis called in cases we would have callmoduleRuntimewith empty values (registering typedefs)moduleRuntimein all other cases: function invocationsTip
This is backward compatible, if
moduleTypeDefsis not defined,moduleRuntimewill be called in both cases.In Java this is done by splitting the previous entry point:
io.dagger.gen.entrypoint.Entrypointonly contains methods invocationio.dagger.gen.entrypoint.TypeDefsonly contains types definitionA second java project is created to handle this new
TypeDefs, with its ownpom.xml, a different jar is created and executed when the engine is calling for types.In Go, the register part of the
invokemethod has been extracted, to roughly do the same behaviour as explained for java.Tech details
Under the hood, when we are looking for the module dependencies, the module itself is loaded as a module so the types are made available. Then the flow continues as before.
Flow looks like:
dagger developmoduleTypeDefsdefinedasModule(introspection file used is without the module itself)And while calling a function
moduleSourceAsModulerunModuleDefInSDKto get the types exposed by the modulemoduleTypeDefs, call it, else callmoduleRuntimemoduleTypeDefs, append types to the dependenciesmoduleRuntimeOne temporary trick is it allows types to be installed two times. It's something that needs to be fixed, but I haven't yet figured out where is the problem.
Current limitations
The code is only defined for the Java SDK as this was easier for me to work on it.This needs to be extended to other SDKs.This is working for Java and Go SDKs.
The module is loaded two times, one to get the types, one to call the functions. This makes things slower and needs to be improved.
Environment/LLM types are prefixed like any dependency, no special case done here. This is something that could be improved.
Example
Once
daggeris built from the branch:Generate a new Java module
$ dagger init --sdk=../../sdk/java modules/my-moduleor
$ dagger init --sdk=go my-moduleAdd a new
echofunction to the createdMyModuleclass/struct (undersrc/main/java/io/dagger/modules/mymodule/MyModule.javain java)If you have an IDE with code completion, you should see the code completion for
myModule/MyModule, meaning the types have been generated.Call it
$ dagger -c 'echo "self invocation" | stdout'You can see the expected output. This means the
echofunction have call the module through the engine and not directly thecontainerEchofrom the local code.In the traces we can see the module (in the screenshot

myGoModule) calling the module itself then creating the container and running the command: