Frege / frege-gradle-plugin

Gradle plugin for compiling Frege projects
BSD 3-Clause "New" or "Revised" License
25 stars 10 forks source link

compileJava followed by compileFrege causing Java calls to Frege not compilable #25

Closed erykciepiela closed 12 months ago

erykciepiela commented 9 years ago

In single polyglot project (Frege plus Java calling Frege) compilation won't work as compileFrege follows compileJava. Do you address such scenario now or in the future? Is there any recommended workaround at the moment?

mperry commented 9 years ago

At the moment calls from Java to Frege have to be handled by having multiple modules. The Frege compiler does not support joint compilation and so a decision was made to compile the Java source and then the Frege source. I think the Groovy plugin does joint compilation of the groovy source directory, but the java source directory does not see the Groovy source code.

See the Github project https://github.com/mperry/frege-gradle-example for how to make a multiple module build work with these kind of dependencies.

Ingo60 commented 9 years ago

@erykciepiela if the Java code is not too much or is specifically there to make some Frege code implement an interface/extend a class, you may possibly use the experimental feature that lets you do that by writing the code "inline". See here

@mperry the question could be raised whether this is a happy state of affairs. It is certainly most often the case that the things the Frege code depends on exists in an already compiled form in some JAR that is listed in the dependencies.

In any case, I could envision the following possibilities to make the "Frege needs Java" scenario work out of fregec:

If I don't overlook something, all the user had to do would be to include the appropriate directories in the source path to make this scenario work. The build tools, including gradle plugin, could then play out their powers to support the "Java calls Frege" scenario in addition.

What do you think?

mperry commented 9 years ago

@Ingo60 I think you misunderstood the question. This is about Java calling Frege, not Frege calling Java.

Ingo60 commented 9 years ago

Yes, @mperry I did understand the question, and hopefully your response, whcih says that gradle currently supports the "Frege calling Java" scenario. Hence my response, whose second part is not an answer to the original question, indeed, but rather an idea for the future.

erykciepiela commented 9 years ago

Thank you for rapid answers and undertaking the problem. I'm happy to see the Frege community so active.

@Ingo60 Thanks for looking for potential solutions. Forgive my ignorance in regards to fregec but I was wondering if it's possible to have fregec compiling Frege source to only Java source as a first phase and then javac compiling Java source (generated from Frege plus any other Java sources) to java bytecode as a second phase?

Ingo60 commented 9 years ago

The Frege compiler compiles only fr files at present. However, once it is done the class files and java files are in the target directory. So it should be possible to compile some java that uses that by giving the appropriate classpath.

breskeby commented 9 years ago

The only option I see here at the moment is to do the frege compilation in two steps

  1. generate java code from frege code
  2. compile generated java code + existing java code in frege source directory (e.g. src/main/frege) folder using JavaCompile task
erykciepiela commented 9 years ago

@breskeby This is what I was wondering about. Could this approach be implemented in the plugin?

mperry commented 9 years ago

The compiler manpage has an option to not compile the generated java code ("-j"), see https://github.com/Frege/frege/wiki/Compiler-Manpage.

Ingo60 commented 6 years ago

The latest compiler will infer the native dependencies of a module and take care to compile the corresponding java file (which must be in the source path), in -make mode. For example:

module my.Main

data X = native com.frobnicate.Foo where
     ...

... more code ....

will look for com/frobnicate/Foo.java in the source path and compile it before the Frege code such that, when the Frege compiler sees the native declaration, the com.frobnicate.Foo class will already exist.

Bottom line is: do Frege compilation first, and Java compilation afterwards, and you should be good.