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

Add bazel build for JNI code #3918

Merged
merged 8 commits into from
Feb 4, 2019
Merged

Conversation

guoyuhong
Copy link
Contributor

What do these changes do?

This PR adds the bazel code to build the Java Raylet Client JNI code. From current cmake process, the output lib name differs in MacOS than in Linux.

Currently, I copy this file to folder $(location ray_pkg)/src/ray/raylet/ corresponding to build/src/ray/raylet of cmake. I think the final path should be determine in #3898 .

Now I can use find bazel-genfiles/ -name *libraylet_library_java.* to find the dynamic lib.

Related issue number

@guoyuhong guoyuhong requested a review from pcmoritz January 31, 2019 16:02
@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11356/
Test PASSed.

@guoyuhong guoyuhong changed the title Add bazel build for JNI code [WIP] Add bazel build for JNI code Feb 1, 2019
@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11396/
Test PASSed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11399/
Test FAILed.

@raulchen raulchen self-requested a review February 2, 2019 09:52
@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11445/
Test PASSed.

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11448/
Test FAILed.

@guoyuhong guoyuhong changed the title [WIP] Add bazel build for JNI code Add bazel build for JNI code Feb 2, 2019
BUILD.bazel Outdated
""",
mv python $(location ray_pkg) &&
mkdir -p $(location ray_pkg)/src/ray/raylet &&
for f in $(locations //:raylet_library_java); do if [[ $$f == *".so"* ]]; then cp $$f $(location ray_pkg)/src/ray/raylet/"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is $$?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When put command in """ string, $$variable is like $variable in shell.

Copy link
Contributor

@raulchen raulchen left a comment

Choose a reason for hiding this comment

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

The code doesn't seem to be well formatted. You can format it with yapf -i as the syntax is compatible with Python.

BUILD.bazel Outdated
"@bazel_tools//src/conditions:windows": "libraylet_library_java.dll",
"@bazel_tools//src/conditions:darwin": "libraylet_library_java.dylib",
"//conditions:default": "libraylet_library_java.so"})
+ "; fi done &&" +
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the default output file is always suffixed by .so, and you want to rename it with different suffixes based on the OS?
It's weird that why it doesn't generate different suffixes in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to do that at the beginning, but failed... I used this as a workaround.

@guoyuhong
Copy link
Contributor Author

@raulchen I tried yapf -i and there are too many changed lines, which may cause a lot of conflict with @pcmoritz 's PR. I will left it unchanged until the Bazel scripts are ready.

In this PR, I only wanted to add the JNI for raylet client at the beginning. Then, I found there are many missing pieces for enabling Java. I added the JNI for Plasma Client and Arrow Java library and Raylet Java library. For the 2 java libraries, currently, it is very simple building script as a mark to remind us which is missing. We may later consider how to use it correctly. For example, the binary paths in RayConfig.java should be changed accordingly. ray.default.conf’s name should also be changed because Bazel does not allow *.conf file to be included in the jar file. However, we may put that to later PRs.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11475/
Test PASSed.

BUILD.bazel Outdated
name="ray_java_pkg",
srcs=glob([
"java/*.java",
"java/*.properties",
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried this, the generated jar file doesn't capture anything.
I think this should be java/**/*.java, right?
Also, we need to add the external dependencies.


A few more comments:

  1. instead of defining single big java library, we should probably define each module (api, runtime, test, etc) as a library.
  2. We should probably follow this tutorial to properly set up the java libraries.
  3. It seems that you want to set up java libraries later. If so, we should probably remove this ray_java_pkg from this PR, because it doesn't actually do anything.

@raulchen
Copy link
Contributor

raulchen commented Feb 3, 2019

@raulchen I tried yapf -i and there are too many changed lines, which may cause a lot of conflict with @pcmoritz 's PR. I will left it unchanged until the Bazel scripts are ready.

In this PR, I only wanted to add the JNI for raylet client at the beginning. Then, I found there are many missing pieces for enabling Java. I added the JNI for Plasma Client and Arrow Java library and Raylet Java library. For the 2 java libraries, currently, it is very simple building script as a mark to remind us which is missing. We may later consider how to use it correctly. For example, the binary paths in RayConfig.java should be changed accordingly. ray.default.conf’s name should also be changed because Bazel does not allow *.conf file to be included in the jar file. However, we may put that to later PRs.

Regarding the format, I can later open a PR to add linter in CI. But I think we can do that before bazel is completely ready.

Regarding java libraries, I left some comments in line.

@guoyuhong
Copy link
Contributor Author

@pcmoritz I have two questions about this PR.

  1. In bazel/BUILD.plasma, I need to use ../../external/local_jdk/include to include the JNI headers, which is different than the one in BUILD.bazel. Is there a way to unify them?
  2. I cannot specify the cc_library to output .dylib directly. I choose to rename it during copying process. Is there a way to specify it during the building process?

@AmplabJenkins
Copy link

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11481/
Test FAILed.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11483/
Test PASSed.

@raulchen
Copy link
Contributor

raulchen commented Feb 4, 2019

  1. I cannot specify the cc_library to output .dylib directly. I choose to rename it during copying process. Is there a way to specify it during the building process?

@guoyuhong Bazel doesn't seem to support this at this moment. Tensorflow uses a genrule (see https://github.com/tensorflow/tensorflow/blob/53bd138262df6e141c0e196a262f4ae760c2cf5f/tensorflow/java/BUILD#L418-L427) to do renaming.

@guoyuhong
Copy link
Contributor Author

@raulchen Thanks! I have updated the bazel script using the genrule.
I also found that if BUILD.plasma is not at the root dir, we need to add ../../ as a workaround to find jni.h, which is discussed in this page.

@AmplabJenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/11529/
Test PASSed.

Copy link
Contributor

@pcmoritz pcmoritz left a comment

Choose a reason for hiding this comment

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

This looks good to me!

@pcmoritz pcmoritz merged commit add8ae7 into ray-project:master Feb 4, 2019
@guoyuhong guoyuhong mentioned this pull request Feb 8, 2019
@guoyuhong guoyuhong deleted the JniBazel branch February 13, 2019 10:23
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

Successfully merging this pull request may close these issues.

5 participants