[
https://issues.apache.org/jira/browse/THRIFT-3581?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15832854#comment-15832854
]
Benjamin Gould commented on THRIFT-3581:
----------------------------------------
It is not a separate compiler... it is, in a sense, a cross-compile of the
unmodified C++ source. NestedVM has 3 main pieces - a slightly modified GCC
toolchain that creates MIPS binaries, a translator that converts the MIPS
binary to Java bytecode, and a Java runtime library that implements the
functionality normally provided by an OS kernel. In other words, it can
compile large amounts of unmodified C/C++ so that it can run on the JVM. The
{{Makefile}} that I made basically just wraps {{./configure --disable-libs &&
make}} with some extra flags for cross compiling, as well as some steps for
packaging the JAR, including -sources and -javadocs suitable for upload to a
Maven repo.
That is the long way of saying that it is not really a separate compiler, just
a different platform for the existing one. It is slower than the native
executable, but not much slower, and IMO certainly acceptable given how the
Thrift compiler is used.
To really split hairs, it also technically wraps the C++ compiler... if you are
trying to call the Thrift compiler from a Java application (as you might do in
Ant, Maven, Gradle, etc) the JAR provides a single abstraction for calling a
native Thrift executable and the NestedVM version, which can be configured at
runtime via configuration properties:
https://github.com/bgould/thrift/blob/nestedvm/contrib/nestedvm/src/main/java/org/apache/thrift/compiler/ThriftCompiler.java
https://github.com/bgould/thrift/blob/nestedvm/contrib/nestedvm/src/main/java/org/apache/thrift/compiler/NativeThriftCompiler.java
https://github.com/bgould/thrift/blob/nestedvm/contrib/nestedvm/src/main/java/org/apache/thrift/compiler/NestedVmThriftCompiler.java
> Pure Java build of the Thrift compiler using NestedVM [WIP]
> -----------------------------------------------------------
>
> Key: THRIFT-3581
> URL: https://issues.apache.org/jira/browse/THRIFT-3581
> Project: Thrift
> Issue Type: New Feature
> Components: Compiler (General)
> Reporter: Benjamin Gould
> Assignee: Benjamin Gould
> Priority: Minor
> Attachments: thrift-compiler-0.9.4-SNAPSHOT.jar,
> thrift-compiler-0.9.4-SNAPSHOT-sources.jar
>
>
> I've developed a build process for building the Thrift compiler as a JAR file
> that can be run on a JVM and requires no dependencies by cross-compiling the
> executable with NestedVM.
> I think this could be use for the following, among other things:
> 1) Building Thrift plugins for IDEs written in Java
> 2) Integration into Java build tools like Ant and Maven
> 3) Calling the compiler from a Java program when the host platform is unknown
> Also, I see this as providing a way to potentially allow people to create
> third party "plugins" for the compiler... Java and the plethora of JVM
> language available might make creating new generators much more approachable
> for people not comfortable with C++... and also in Java it is not complicated
> to load code dynamically based on a class name as long as it is on the
> classpath.
> In any case, I have a working prototype, but it is far from battle tested.
> For the inpatient, I'm attaching a snapshot build to this ticket, but you can
> also find the source and build instructions here:
> https://github.com/bgould/thrift/tree/nestedvm/contrib/nestedvm
> Will open a pull request when I feel all of the wrinkles have been ironed out
> (it is close, and quite usuable already) to see if it might be appropriate to
> bring this into the contrib/ folder, or even include as an artifact in the
> Maven repos for a future release.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)