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

Document how to transpile with CLI #147

Open
dsyer opened this issue Jun 7, 2022 · 6 comments
Open

Document how to transpile with CLI #147

dsyer opened this issue Jun 7, 2022 · 6 comments

Comments

@dsyer
Copy link
Contributor

dsyer commented Jun 7, 2022

Related to #146. I assume it is somehow possible to ask the web server in the sample apps to bind to a different address (host and port), but I can't see how to do it. Some documentation might help? Or maybe it's actually a missing feature in the j2cl_application.bzl?

@gkdn
Copy link
Member

gkdn commented Jun 7, 2022

The web server we use on samples are coming from https://github.com/bazelbuild/rules_closure/blob/master/closure/webfiles/web_library.bzl

I don't recall it providing a mechanism to customize address but you can dig into there and see if there is already a way, or propose change to expose it.

If this is only about ipv6 issue, I can change the default one and see if it works in all test environments.

(BTW, pls note that the web server there is quite bit hacky, unsafe and definitely not intended for complex usages even for development)

@dsyer
Copy link
Contributor Author

dsyer commented Jun 8, 2022

I want to be able to change the port as well, so I guess I'll have a look at that web_library definition. TBH I'd rather not use Bazel at all just for building sample apps. Is there an alternative? Like a CLI that I can use to compile the WASM and other generated code?

@niloc132
Copy link
Contributor

niloc132 commented Jun 8, 2022

Bazel can produce a J2clTranspiler binary that you can run outside of bazel as a command line tool.

Running bazel build //transpiler/java/com/google/j2cl/transpiler:J2clCommandLineRunner will produce a script bazel-bin/transpiler/java/com/google/j2cl/transpiler/J2clCommandLineRunner which can be run from the command line

Also, running bazel build //transpiler/java/com/google/j2cl/transpiler:J2clCommandLineRunner_deploy.jar will produce a jar bazel-bin/transpiler/java/com/google/j2cl/transpiler/J2clCommandLineRunner_deploy.jar that can be run as java -jar J2clCommandLineRunner_deploy.jar.

The j2cl-maven-plugin will work most of the details that were covered by j2cl_library, j2cl_application, j2cl_test and then some (tests work properly, dev mode output with BUNDLE supports sourcemaps, etc), but doesn't presently have wasm support hooked up, mostly due to our lack of familiarity with wasm.

@gkdn
Copy link
Member

gkdn commented Jun 8, 2022

Yes, you can use the Bazel generated compiler binary; and unlike J2CL, it is currently modeled as a monolithic compiler so you need to collect and supply all the java sources in single shot (vs. compiling independently and providing deps etc.).

Being said that; we supplied the open-source WASM samples for WASM & VM researchers. It is very experimental; the way compiler work and even the bazel rules doesn't reflect our long term design around it; and it is mostly hacked up together.

@dsyer
Copy link
Contributor Author

dsyer commented Jun 9, 2022

Great. That could work. You might have to help a bit to get over the initial humps:

$ bazel-bin/transpiler/java/com/google/j2cl/transpiler/J2clCommandLineRunner -classpath bazel-j2cl/bazel-out/k8-fastbuild/bin/jre/java/libjre_bootclasspath-j2wasm.jar -d tmp -backend WASM samples/wasm/src/main/java/com/google/j2cl/samples/wasm/HelloWorld.java 
Exception in thread "main" java.lang.NullPointerException
        at com.google.j2cl.transpiler.ast.TypeDescriptors$SingletonBuilder.addReferenceType(TypeDescriptors.java:506)
        at com.google.j2cl.transpiler.frontend.jdt.JdtUtils.initWellKnownTypes(JdtUtils.java:948)
        at com.google.j2cl.transpiler.frontend.jdt.CompilationUnitBuilder$ASTConverter.convert(CompilationUnitBuilder.java:142)
...

@dsyer dsyer changed the title Document how to run samples with different IP binding Document how to transpile with CLI Jun 9, 2022
@gkdn
Copy link
Member

gkdn commented Jun 10, 2022

You can pass "-s" to bazel to see the command generated by j2wasm_application target which should be close to what you will need for J2clCommandLineRunner as well.

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

3 participants