From 394211bf88b88c25036429e99894fa7c60eaaace Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Fri, 15 Sep 2017 15:59:14 +0200 Subject: Bazel now can build dynamic library from cc_library Working towards: https://github.com/bazelbuild/bazel/issues/3311 When building dynamic library on Windows, Bazel builds an import library and a DLL. Bazel provides a feature called windows_export_all_symbols, if this feature is enabled(and no_windows_export_all_symbols is not) for a cc_library, then Bazel parses object files of that cc_library to generate a DEF file that will be used during linking time to export symbols from DLL. This feature can be specified at crosstool, package, target and command line level. A few differences from Unix platforms: 1. We don't build the shared library on Windows by default, users have to specifiy --output_groups=dynamic_library for building dynamic libraries. This output group is also available on other platforms. 2. By default, cc_test is dynamically linked on Unix, but it will be statically linked on Windows by default. (meaning the default value of linkstatic in cc_test is 1 on Windows, and 0 on other platforms) 3. For global data symbols, __declspec(dllimport) must still be used in source files. Remaining issues: 1. Extensions for import library and DLL are not correct yet. 2. DLLs are not guaranteed to be available during runtime yet. 3. Diamond problem If a cc_library A is specified as linkstatic=0, then no dynamic library will be built for it, so if another cc_library B depends on it, A will be statically linked into B, and if a cc_binary C depends on B, A will also be statically linked into C and B will be dynamically linked to C. This is wrong because A is duplicated in both B and C. It is essentially a diamond problem describled in C++ Transitive Library. (https://docs.google.com/document/d/1-tv0_79zGyBoDmaP_pYWaBVUwHUteLpAs90_rUl-VY8/edit?usp=sharing) Hopefully, we can avoid this by using cc_shared_library rule in future. Change-Id: I23640d4caf8afe65d60b1522af6368536d7a8408 PiperOrigin-RevId: 168829958 --- tools/def_parser/BUILD | 18 ++++++++++++++++++ tools/def_parser/BUILD.tools | 13 +++++++++++++ tools/def_parser/no_op.bat | 17 +++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 tools/def_parser/BUILD create mode 100644 tools/def_parser/BUILD.tools create mode 100644 tools/def_parser/no_op.bat (limited to 'tools/def_parser') diff --git a/tools/def_parser/BUILD b/tools/def_parser/BUILD new file mode 100644 index 0000000000..7070bebf00 --- /dev/null +++ b/tools/def_parser/BUILD @@ -0,0 +1,18 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "srcs", + srcs = glob(["**"]), +) + +# cc_toolchain now implicitly depends on @bazel_tools//tools/def_parser:def_parser +# We need to make sure @bazel_tools//tools/def_parser:def_parser is not +# a cc_binary, because otherwise, we'll introduce a cycle in dependency graph: +# .-> @bazel_tools//tools/def_parser:def_parser (cc_binary) +# | cc_toolchain +# `-- @bazel_tools//tools/def_parser:def_parser (cc_binary) + +filegroup( + name = "def_parser", + srcs = ["no_op.bat"], +) diff --git a/tools/def_parser/BUILD.tools b/tools/def_parser/BUILD.tools new file mode 100644 index 0000000000..bd1b891fa8 --- /dev/null +++ b/tools/def_parser/BUILD.tools @@ -0,0 +1,13 @@ +package(default_visibility = ["//visibility:public"]) + +filegroup( + name = "def_parser", + srcs = select({ + "//src:host_windows": ["def_parser.exe"], + "//src:host_windows_msvc": ["def_parser.exe"], + "//src:host_windows_msys": ["def_parser.exe"], + "//conditions:default": [ + "no_op.bat", + ], + }), +) diff --git a/tools/def_parser/no_op.bat b/tools/def_parser/no_op.bat new file mode 100644 index 0000000000..b422585831 --- /dev/null +++ b/tools/def_parser/no_op.bat @@ -0,0 +1,17 @@ +:: 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. + +:: Invoke the python script under pydir with the same basename +@echo OFF +echo IGNORING: %0 %* -- cgit v1.2.3