Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OLD PoC] Source generators #3035

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MaciejG604
Copy link
Contributor

@MaciejG604 MaciejG604 commented Jul 17, 2024

This is an old PoC for implementing source generators that was supposed to use Bloops capability to run an arbitrary command that would generate the sources.

Bloop.Project.sourceGenerators accepts a list of objects of this shape:
SourceGenerator(sourcesGlobs: List[SourcesGlobs], outputDirectory: PlatformFiles.Path, command: List[String])

By quickly looking at Bloop's code the command gets created like this:
(command :+ outputDirectory.syntax) ++ inputs.keys.map(_.syntax), where the inputs are the results of applying sourceGlobs

So trying to work with this, I wanted to run scala-cli command on a small app that uses dep "com.thesamet.scalapb::scalapbc:0.11.13", which would generate the sources before Bloop's compilation would run.
Unfortunately this didn't work, I recall that the command never managed to generate sources even though Bloop would run it (I think). Probably there was a problem with the command also calling Bloop.

I thought about a while ago and IMO for it to work we would need to first build the generator app (potentially without Bloop) and pass the run command to Bloop (sth like java --cp jar1:jar2:scalapbc-jar MainClass outputDir sourceArg1 sourceArg2 ...
We already do similar stuff in our Run command.

Off the top of my head this generator app could also be released to maven, but I don't see any problems in hardcoding it in our sources.

Additionally I think the easiest way would be to rework the Bloop API to allow more flexibility e.g. for calling ScalaPBC's main without the generator-app from gen.scala as it effectively just shuffles arguments around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant