aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/native
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-07-31 13:51:57 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-07-31 16:32:17 +0200
commitc28e2e0e0433f03cab8dcac964436ba6617be54a (patch)
tree399a425e0131c041023a9c01bb0ef7f49cb77d9b /src/main/native
parentf29907ab9e2bd4915b20d25cb206b94ac08a99e7 (diff)
Using cc_binary to build windows_jni.dll
Get rid of build_windows_jni.sh and the corresponding genrule. Change-Id: I89a199b61109f5687f8b500b60d284cae97f6457 PiperOrigin-RevId: 163679307
Diffstat (limited to 'src/main/native')
-rw-r--r--src/main/native/BUILD4
-rw-r--r--src/main/native/windows/BUILD13
-rwxr-xr-xsrc/main/native/windows/build_windows_jni.sh100
-rw-r--r--src/main/native/windows/file-jni.cc2
-rw-r--r--src/main/native/windows/jni-util.h4
-rw-r--r--src/main/native/windows/processes-jni.cc2
6 files changed, 15 insertions, 110 deletions
diff --git a/src/main/native/BUILD b/src/main/native/BUILD
index c4b0d2ee3b..ad60099671 100644
--- a/src/main/native/BUILD
+++ b/src/main/native/BUILD
@@ -4,10 +4,13 @@ genrule(
"//src:darwin": ["//tools/jdk:jni_md_header-darwin"],
"//src:darwin_x86_64": ["//tools/jdk:jni_md_header-darwin"],
"//src:freebsd": ["//tools/jdk:jni_md_header-freebsd"],
+ "//src:windows": ["//tools/jdk:jni_md_header-windows"],
+ "//src:windows_msvc": ["//tools/jdk:jni_md_header-windows"],
"//conditions:default": ["//tools/jdk:jni_md_header-linux"],
}),
outs = ["jni_md.h"],
cmd = "cp -f $< $@",
+ visibility = ["//src/main/native:__subpackages__"],
)
genrule(
@@ -15,6 +18,7 @@ genrule(
srcs = ["//tools/jdk:jni_header"],
outs = ["jni.h"],
cmd = "cp -f $< $@",
+ visibility = ["//src/main/native:__subpackages__"],
)
filegroup(
diff --git a/src/main/native/windows/BUILD b/src/main/native/windows/BUILD
index f0674c6ea5..8236a301d2 100644
--- a/src/main/native/windows/BUILD
+++ b/src/main/native/windows/BUILD
@@ -38,15 +38,16 @@ cc_library(
hdrs = ["util.h"],
)
-genrule(
- name = "windows_jni",
+cc_binary(
+ name = "windows_jni.dll",
srcs = glob([
"*.cc",
"*.h",
- ]),
- outs = ["windows_jni.dll"],
- cmd = "$(location build_windows_jni.sh) $@ $(SRCS)",
- tools = ["build_windows_jni.sh"],
+ ]) + [
+ "//src/main/native:jni.h",
+ "//src/main/native:jni_md.h",
+ ],
+ linkshared = 1,
visibility = [
"//src:__pkg__",
"//src/test/java/com/google/devtools/build/lib:__subpackages__",
diff --git a/src/main/native/windows/build_windows_jni.sh b/src/main/native/windows/build_windows_jni.sh
deleted file mode 100755
index a66267814a..0000000000
--- a/src/main/native/windows/build_windows_jni.sh
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/bin/bash -eu
-
-# 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.
-
-# It's not a good idea to link an MSYS dynamic library into a native Windows
-# JVM, so we need to build it with Visual Studio. However, Bazel doesn't
-# support multiple compilers in the same build yet, so we need to hack around
-# this limitation using a genrule.
-
-DLL="$1"
-shift 1
-
-function fail() {
- echo >&2 "ERROR: $@"
- exit 1
-}
-
-# Ensure the PATH is set up correctly.
-if ! which which >&/dev/null ; then
- PATH="/bin:/usr/bin:$PATH"
- which which >&/dev/null \
- || fail "System PATH is not set up correctly, cannot run GNU bintools"
-fi
-
-# Create a temp directory. It will used for the batch file we generate soon and
-# as the temp directory for CL.EXE .
-VSTEMP=$(mktemp -d)
-trap "rm -fr \"$VSTEMP\"" EXIT
-
-# Find Visual Studio. We don't have any regular environment variables available
-# so this is the best we can do.
-if [ -z "${BAZEL_VS+set}" ]; then
- VSVERSION="$(ls "C:/Program Files (x86)" \
- | grep -E "Microsoft Visual Studio [0-9]+" \
- | sort --version-sort \
- | tail -n 1)"
- [[ -n "$VSVERSION" ]] || fail "Visual Studio not found"
- BAZEL_VS="C:/Program Files (x86)/$VSVERSION"
-fi
-VSVARS="${BAZEL_VS}/VC/VCVARSALL.BAT"
-
-# Check if Visual Studio 2017 is installed. Look for it at the default
-# locations.
-if [ ! -f "${VSVARS}" ]; then
- VSVARS="C:/Program Files (x86)/Microsoft Visual Studio/2017/"
- VSEDITION="BuildTools"
- if [ -d "${VSVARS}Enterprise" ]; then
- VSEDITION="Enterprise"
- elif [ -d "${VSVARS}Professional" ]; then
- VSEDITION="Professional"
- elif [ -d "${VSVARS}Community" ]; then
- VSEDITION="Community"
- fi
- VSVARS+="$VSEDITION/VC/Auxiliary/Build/VCVARSALL.BAT"
-fi
-
-if [ ! -f "${VSVARS}" ]; then
- fail "VCVARSALL.bat not found, check your Visual Studio installation"
-fi
-
-# Find Java. $(JAVA) in the BUILD file points to external/local_jdk/..., which
-# is not very useful for anything not MSYS-based.
-JAVA=$(ls "C:/Program Files/java" | grep -E "^jdk" | sort | tail -n 1)
-[[ -n "$JAVA" ]] || fail "JDK not found"
-JAVAINCLUDES="C:/Program Files/java/$JAVA/include"
-
-# Convert all compilation units to Windows paths.
-WINDOWS_SOURCES=()
-for i in $*; do
- if [[ "$i" =~ ^.*\.cc$ ]]; then
- WINDOWS_SOURCES+=("\"$(cygpath -a -w $i)\"")
- fi
-done
-
-# CL.EXE needs a bunch of environment variables whose official location is a
-# batch file. We can't make that have an effect on a bash instance, so
-# generate a batch file that invokes it.
-cat > "${VSTEMP}/windows_jni.bat" <<EOF
-@echo OFF
-@call "${VSVARS}" amd64
-@cd $(cygpath -a -w "${PWD}")
-@set TMP=$(cygpath -a -w "${VSTEMP}")
-@CL /O2 /EHsc /LD /Fe:"$(cygpath -a -w ${DLL})" /I "${JAVAINCLUDES}" /I "${JAVAINCLUDES}/win32" /I . ${WINDOWS_SOURCES[*]}
-EOF
-
-# Invoke the file and hopefully generate the .DLL .
-chmod +x "${VSTEMP}/windows_jni.bat"
-exec "${VSTEMP}/windows_jni.bat"
diff --git a/src/main/native/windows/file-jni.cc b/src/main/native/windows/file-jni.cc
index 78b31224f2..fb33ec686e 100644
--- a/src/main/native/windows/file-jni.cc
+++ b/src/main/native/windows/file-jni.cc
@@ -16,12 +16,12 @@
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
-#include <jni.h>
#include <windows.h>
#include <memory>
#include <string>
+#include "src/main/native/jni.h"
#include "src/main/native/windows/file.h"
#include "src/main/native/windows/jni-util.h"
#include "src/main/native/windows/util.h"
diff --git a/src/main/native/windows/jni-util.h b/src/main/native/windows/jni-util.h
index c3632fd1bc..269ce389e9 100644
--- a/src/main/native/windows/jni-util.h
+++ b/src/main/native/windows/jni-util.h
@@ -14,10 +14,10 @@
#ifndef BAZEL_SRC_MAIN_NATIVE_WINDOWS_JNI_UTIL_H_
#define BAZEL_SRC_MAIN_NATIVE_WINDOWS_JNI_UTIL_H_
-#include <jni.h>
-
#include <string>
+#include "src/main/native/jni.h"
+
namespace bazel {
namespace windows {
diff --git a/src/main/native/windows/processes-jni.cc b/src/main/native/windows/processes-jni.cc
index dd3e62c067..5b0aed4582 100644
--- a/src/main/native/windows/processes-jni.cc
+++ b/src/main/native/windows/processes-jni.cc
@@ -16,13 +16,13 @@
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
-#include <jni.h>
#include <windows.h>
#include <atomic>
#include <memory>
#include <string>
+#include "src/main/native/jni.h"
#include "src/main/native/windows/jni-util.h"
#include "src/main/native/windows/util.h"