diff options
author | 2016-06-27 14:55:17 +0000 | |
---|---|---|
committer | 2016-06-27 15:00:51 +0000 | |
commit | d8d7d2385a3b0fe0f976ac99954b1f079e07f6f4 (patch) | |
tree | 0184c2f2a2292284545ad8a448d252bb20c79a4e /src/main | |
parent | 2fc015791cd4e6394b17c2867877d8c168abae9b (diff) |
Add skeleton code for a JNI .DLL on Windows.
Tested by hacking in a call to a JNI method into BatchMain.java .
--
Change-Id: I77b0731fa6b81f8cbc80cf2a31d427764fad6ad1
Reviewed-on: https://bazel-review.googlesource.com/#/c/3908/
MOS_MIGRATED_REVID=125955521
Diffstat (limited to 'src/main')
5 files changed, 88 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index b92df36247..ab08d72355 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -70,6 +70,11 @@ java_library( ], ) +java_library( + name = "windows", + srcs = glob(["windows/*.java"]), +) + # Library of concurrency utilities. java_library( name = "concurrent", diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsJniLoader.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsJniLoader.java new file mode 100644 index 0000000000..ca62fe9052 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsJniLoader.java @@ -0,0 +1,24 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.windows; + +/** + * Loads native code under Windows. + */ +public class WindowsJniLoader { + public static void loadJni() { + System.loadLibrary("windows_jni"); + } +} diff --git a/src/main/java/com/google/devtools/build/lib/windows/WindowsProcesses.java b/src/main/java/com/google/devtools/build/lib/windows/WindowsProcesses.java new file mode 100644 index 0000000000..f23508da0b --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/windows/WindowsProcesses.java @@ -0,0 +1,22 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.devtools.build.lib.windows; + +/** + * Process management on Windows. + */ +public class WindowsProcesses { + public static native String helloWorld(int arg, String fruit); +} diff --git a/src/main/native/BUILD b/src/main/native/BUILD index a38a4fc045..5f6bdbf92c 100644 --- a/src/main/native/BUILD +++ b/src/main/native/BUILD @@ -63,6 +63,15 @@ cc_binary( ], ) +genrule( + name = "windows_jni", + srcs = ["windows_processes.cc"], + outs = ["windows_jni.dll"], + cmd = "$(location build_windows_jni.sh) $@ $(SRCS)", + tools = ["build_windows_jni.sh"], + visibility = ["//src:__subpackages__"], +) + # TODO(bazel-team): Come up with a way to support platform-specific dynamic # library extensions. This is issue #914. genrule( diff --git a/src/main/native/windows_processes.cc b/src/main/native/windows_processes.cc new file mode 100644 index 0000000000..62534f2d0e --- /dev/null +++ b/src/main/native/windows_processes.cc @@ -0,0 +1,28 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include <jni.h> +#include <stdio.h> +#include <string.h> + +extern "C" JNIEXPORT jstring JNICALL +Java_com_google_devtools_build_lib_windows_WindowsProcesses_helloWorld( + JNIEnv* env, jclass clazz, jint arg, jstring fruit) { + char buf[512]; + const char* utf_fruit = env->GetStringUTFChars(fruit, NULL); + snprintf(buf, sizeof(buf), "I have %d delicious %s fruits", arg, utf_fruit); + jstring result = env->NewStringUTF(buf); + env->ReleaseStringUTFChars(fruit, utf_fruit); + return result; +} |