Is there a way to pass information between compila...
# compiler
g
Is there a way to pass information between compilations of source sets of the same module? Specifically, between IR runs. Or is there a way to get all classes marked with some annotation in the module? I would like to implement an IR extension that finds all classes marked with some specific annotation to call their methods from a single function that is generated for some targets. For example, if I have a classes
FooCommon
,
FooJvm
, and
FooJs
in common, JVM, and JS source sets correspondingly, then I would like to generate function
barJs
in JS source set that accesses
FooCommon
and
FooJs
. (In case of more targets, I would like to generate
barPlatform
for all platforms except for JVM.) I guess, I can determine when the extension is called for some specific target (not for a group of targets or even for common sources) via
pluginContext.platform
. But I don't understand how I can find all classes of the module (available for specific target).
y
I think you can technically use global state to share such data (but I might be wrong), but this won't work under
separateCompilation
IIUC What you should do is generate metadata-visible declarations in a known package, and then read it in your IR plugin. Metro might be good to look at here, since it does this across projects too (i.e. Metro generates some metadata in one project, and reads it in consuming projects). I believe it does so for
@ContributesBinding
g
Got it, thanks. I'll try looking into Metro then.
d
Is there a way to pass information between compilations of source sets of the same module?
You can't control which compilation would be actually executed by user and in which order, so IMO it's kinda pointless (imagine CI job, which runs only apple compilations).
y
@dmitriy.novozhilov I believe in this case they want the compilations of the relevant source sets, so for JS they want info from
commonMain
,
webMain
, etc. I agree that getting info from
jvmMain
when you're on
jsMain
would be a very bad idea