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

Adding additional output formats to compiler-jx? #240

Open
Fancy2209 opened this issue Jan 10, 2025 · 1 comment
Open

Adding additional output formats to compiler-jx? #240

Fancy2209 opened this issue Jan 10, 2025 · 1 comment

Comments

@Fancy2209
Copy link

Hello,
I'm interested in a possibility of attempting to add a native target to the compiler, and I saw that the [docs] https://apache.github.io/royale-docs/compiler) mention that:

It is relatively straightforward to add additional output formats to the compiler.

Is there any rundown of what is needed to add an additional output format, or just any more info about this in general?

@Fancy2209 Fancy2209 changed the title What's needed to add an additional output format to compiler-jx? Adding additional output formats to compiler-jx? Jan 10, 2025
@joshtynjala
Copy link
Member

The word "relatively" is probably doing a lot of work in that sentence. 😆

MXMLJSC is the main entry point of the app compiler:

https://github.com/apache/royale-compiler/blob/develop/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSC.java

In the _mainNoExit method, it loops through the targets compiler option and runs a separate implementation of the JSCompilerEntryPoint interface for each target.

It also defines an enum called JSTargetType which includes all of the supported targets. That name is probably not ideal, because it also includes SWF, and presumably, any other new non-JS target that you'd wish to add. Regardless, if you want a new output format, you'd need a new entry in that enum for it.

(There's also COMPJSC for building SWC libraries, which is set up similarly: https://github.com/apache/royale-compiler/blob/develop/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java)

MXMLJSCRoyale is the implementation of the JSCompilerEntryPoint for the "JSRoyale" target.

https://github.com/apache/royale-compiler/blob/develop/compiler-jx/src/main/java/org/apache/royale/compiler/clients/MXMLJSCRoyale.java

In the constructor, it creates a "backend". In this case MXMLRoyaleBackend, which extends from MXMLBackend and JSBackend.

https://github.com/apache/royale-compiler/blob/develop/compiler-jx/src/main/java/org/apache/royale/compiler/internal/driver/mxml/royale/MXMLRoyaleBackend.java

The backend is a kind of factory for a number of things involved in the compilation. The most relevant ones are:

  • Emitters: Generates the code for the new target. For a native target, these might generate the contents of .c or .cpp files.
  • Writers: Takes the code generated by the emitters, and writes them to output streams (generally, to the file system, but I recall that creating SWCs involves different types of streams because it eventually all gets zipped up in the SWC).
  • Publisher: Everything else that might need to be done after the target's code has been generated. For JS targets, this includes bundling the separate .js files into a single file for release builds, generating HTML files, and copying assets. For a native target, this could potentially involve running a C compiler to produce an executable.

There are also "Targets", "Walkers", and some other things. I don't have time to explain more right now, but this might be enough to give you a starting point for diving into the codebase.

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

No branches or pull requests

2 participants