Skip to content

Add support for toolchain java 15 #12168

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

Closed
wants to merge 1 commit into from
Closed

Conversation

Jonpez2
Copy link
Contributor

@Jonpez2 Jonpez2 commented Sep 24, 2020

Closes #11871

I modelled this on @davido's addition of a java 14 toolchain, here:https://github.com/bazelbuild/bazel/pull/11514.

The test plan has the same form:

Create java_tools from this commit:
$ bazel build src:java_tools_java11.zip

Switch to using the java_tools from the above step in WORKSPACE file:

  load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
  http_archive(
    name = "remote_java_tools_linux",
    urls = [
        "file:///<path to the java_tools_java11.zip>",
    ],
  )

Add Zulu OpenJDK15 to use as javabase in WORKSPACE file:

  http_archive(
    name = "openjdk15_linux_archive",
    build_file_content = """
java_runtime(name = 'runtime', srcs =  glob(['**']), visibility = ['//visibility:public'])
exports_files(["WORKSPACE"], visibility = ["//visibility:public"])
""",
    strip_prefix = "zulu15.27.17-ca-jdk15.0.0-linux_x64",
    urls = ["https://cdn.azul.com/zulu/bin/zulu15.27.17-ca-jdk15.0.0-linux_x64.tar.gz"],
  )

Activate custom java toolchain and javabase in .bazelrc file:

  build --java_toolchain=@remote_java_tools_linux//:toolchain_jdk_15
  build --host_java_toolchain=@remote_java_tools_linux//:toolchain_jdk_15
  build --javabase=@openjdk15_linux_archive//:runtime
  build --host_javabase=@openjdk15_linux_archive//:runtime

Create Java 15 example class file:

public class Javac15Example {
  static String textBlock = """
              Hello,
              World
              """;
  public static void main(String[] args) {
    System.out.println(textBlock);
  }
}

Add Bazel file to build Java 15 syntax class:

  java_binary(
    name = "Javac15Example",
    srcs = ["Javac15Example.java"],
    main_class = "Javac15Example",
  )

Test that it works as expected:

  $ bazel run java:Javac15Example
INFO: Analyzed target //java:Javac15Example (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
INFO: From Building java/Javac15Example.jar (1 source file):
Target //java:Javac15Example up-to-date:
  bazel-bin/java/Javac15Example.jar
  bazel-bin/java/Javac15Example
INFO: Elapsed time: 1.502s, Critical Path: 1.30s
INFO: 1 process: 1 worker.
INFO: Build completed successfully, 2 total actions
INFO: Build completed successfully, 2 total actions
Hello,
World

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@Jonpez2
Copy link
Contributor Author

Jonpez2 commented Sep 24, 2020

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Contributor

@davido davido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Can you check why CI is failing: [1]? The error is:

(09:53:10) ERROR: /workdir/src/BUILD:744:10: no such package '@remote_java_tools_javac15_test_windows//': The repository '@remote_java_tools_javac15_test_windows' could not be resolved and referenced by '//src:test_repos'.

https://buildkite.com/bazel/bazel-bazel-github-presubmit/builds/7032#fa4a0465-296c-4186-a234-6a72643b54d1

WORKSPACE Outdated
@@ -81,7 +81,7 @@ list_source_repository(name = "local_bazel_source_list")
# android_sdk_repository(name = "androidsdk")
# android_ndk_repository(name = "androidndk")

# In order to run //src/test/shell/bazel:maven_skylark_test, follow the
# In order to run //src/test/shell/bazel:maven_starlark_test, follow the
Copy link
Contributor

@davido davido Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see some unrelated white space changes. I would rather revert them all, and only include additions related to java_toolchain_jdk15. Clean up changes should be done in their own PR. Just guessing: you have run buildifier on this files, that also changed the white spaces and shuffled around the attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@davido
Copy link
Contributor

davido commented Sep 24, 2020

@Jonpez2 Thanks for the PR.

Could you please reference this #11871 in the commit message?

//Cc @lberki @comius @philwo @meteorcloudy

Before this PR is merged we should upload Zulu JDK15 archives to bazel mirror.

@Jonpez2
Copy link
Contributor Author

Jonpez2 commented Sep 24, 2020

I fixed the specific error you highlighted, @davido , but I'm quite lost on the current set - I can reproduce the failure locally but the error message gives me no hints...

Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Jonpez2 for your effort! It seems that for one time we will catch up with Java releases.

@comius
Copy link
Contributor

comius commented Oct 2, 2020

I uploaded zulu15 to bazel mirror.

@Jonpez2 Jonpez2 force-pushed the master branch 3 times, most recently from 771d953 to 44b806a Compare October 2, 2020 09:45
@Jonpez2 Jonpez2 force-pushed the master branch 2 times, most recently from 40708bd to e8e4925 Compare October 2, 2020 12:08
Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this fix all the tests should pass.

# --java_toolchain and --host_java_toolchain values
"@local_java_tools//:toolchain_jdk_15",
# java_tools zip to test
"src/java_tools_java15.zip",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/java_tools_java11.zip here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thank you, done.

}),
data = [
":test-deps",
"//src:java_tools_java15_zip",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and "//src:java_tools_java11_zip" here...

tools 11 will have java 14 and java 15

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice thank you, done.

Copy link
Contributor

@comius comius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bazel-io bazel-io closed this in 9450552 Oct 7, 2020
bazel-io pushed a commit that referenced this pull request Oct 19, 2020
archives were added in #12168

Closes #12295.

PiperOrigin-RevId: 337822060
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Java 15 toolchain support
4 participants