facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.33k stars 194 forks source link

buck2 : Is java supported as a part of buck2 #610

Open nagwww opened 1 month ago

nagwww commented 1 month ago

Hi, We want to utilize Buck2 to construct our Java apps. we are having trouble coming up with a "Hello world" for Java.

Could you kindly assist us in the appropriate route for bootstrapping a Java application in Buck2?

Thanks, Nag

nagwww commented 1 month ago

This is the config I tried for creating a hello world application in Java

 java_binary(
    name = "main",
    main_class = "Main",
    deps = [":print"],
)

java_library(
    name = "print",
    srcs = ["Main.java"],
) 

Using the latest version of buck2 ( Downloaded from https://github.com/facebook/buck2/releases/tag/latest ) This was updated like 14 hours back.

$ ./buck2-x86_64-apple-darwin build //:main

Getting the following error

buck2-x86_64-apple-darwin build //:main
File changed: prelude//toolchains/demo.bzl
Build ID: e40e9b95-b558-4faf-a75d-00db9f8cc0ab
Jobs completed: 4. Time elapsed: 0.1s.
BUILD FAILED
Error running analysis for `root//:main (prelude//platforms:default#f6691640831d48dd)`

Caused by:
    0: Error looking up configured node root//:main (prelude//platforms:default#f6691640831d48dd)
    1: Error looking up configured node toolchains//:java (prelude//platforms:default#f6691640831d48dd) (prelude//platforms:default#f6691640831d48dd)
    2: looking up unconfigured target node `toolchains//:java`
    3: Unknown target `java` from package `toolchains//`.
       Did you mean one of the 9 targets in toolchains//:BUCK?
       Maybe you meant one of these similar targets?
         toolchains//:cxx
         toolchains//:go
         toolchains//:ocaml
         toolchains//:rust

I was trying to look at the examples provided for cxx and implement the same for java. cxx works great for the example provided here https://github.com/facebook/buck2/blob/main/examples/hello_world/BUCK

It looks like it has rules in prelude folder, but no toolchain wrapper for java.

Was really hoping to get some guidance / pointer to create a wrapper for java. Hoping to send out a PR to buck2 so this would help out the buck2 community.

Thanks and looking forward to get some guidance on creating a toolchain/wrapper for java.

Kind regards, Nag

ndmitchell commented 1 month ago

CC @IanChilds @cjhopman who work on our Java version internally. My latest understanding is that we don't have things working externally with Java, as the toolchain requires pieces of Buck1 that, while open sourced, are basically impossible to use open source since they require careful compilation.

I wonder if we can possibly provide a binary of the Java pieces on the toolchain in the meantime to get people to experiment with open source?