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
diff --git a/src/BUILD b/src/BUILD
index b1434fe..bd277c8 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -8,7 +8,7 @@
     srcs = select({
         ":darwin": ["//src/main/native:libunix.dylib"],
         ":darwin_x86_64": ["//src/main/native:libunix.dylib"],
-        ":windows": [],
+        ":windows": ["//src/main/native:windows_jni.dll"],
         "//conditions:default": ["//src/main/native:libunix.so"],
     }),
     visibility = [
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index b92df36..ab08d72 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(
+    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 0000000..ca62fe9
--- /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 0000000..f23508d
--- /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 a38a4fc..5f6bdbf 100644
--- a/src/main/native/BUILD
+++ b/src/main/native/BUILD
@@ -63,6 +63,15 @@
     ],
 )
 
+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 0000000..62534f2
--- /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;
+}