Commit Graph

71 Commits

Author SHA1 Message Date
Xùdōng Yáng
11de748d66
Use repo-relative labels wherever possible (#9187)
* Use repo-relative labels wherever possible

The label `@com_google_protobuf//:foo` within the protobuf repo is often synonymous with just `//:foo`. We should prefer the latter as it allows us to use a shorter name for the module in the Bazel Central Registry (so just "protobuf" instead of "com_google_protobuf").

Note that the semantics can be subtle: in a macro, plain strings are anchored to the *calling* repo, so if we just use `//:foo` as the default value of a macro argument, it will be resolved to `@myrepo//:foo` if the macro is called from the repo `@myrepo`. In this case, it's necessary to directly call the `Label()` constructor to anchor the string label to the repo where the .bzl file lives.

See https://github.com/bazelbuild/bazel-central-registry/pull/28#issuecomment-954741081 for a bit more context.

* fix protobuf_deps.bzl
2021-11-04 07:56:32 -07:00
Charles Mita
f1fe79dd12
Use cfg="exec" instead of cfg="host" in internal rules. (#8626)
Bazel has switched its protobuf rules to make them use the proto
compiler in the exec configuration instead of the host configuration.

However, if rules in protobuf still use the host configuration then
multiple copies of the compiler can end up being built.

cfg="host" is deprecated in any case and being replaced with cfg="exec"
where possible.
https://docs.bazel.build/versions/master/skylark/rules.html#configurations
2021-05-19 11:11:13 -07:00
Derek Perez
bc45f92262
Bazel powered Java testing (#8506)
* Protobuf Java/Core Tests running w/ Bazel.

Also integrates rules_jvm_external and migrates existing maven deps
in place.

* Add test_suite target that maps to rule name.

* Lite tests passing in Bazel

* util tests passing with Bazel.

* Add conformance and build testing to //java:core

* Cleanup bzl style and lock down access to failure lists.

* Adding Java Lite conformance tests.

* rm newline

* parameterize conformance_test

This makes usage of failure lists more explicit.

* restrict visibility more for newly added libs and fix formatting.

* fix formatting and visibility.

* move testing.bzl to an internal package.

* fix file formatting.

* moving conformance_test to internal.bzl
2021-04-20 11:36:32 -07:00
Adam Yi
88f3ef7d1d [bazel] Add default shell env to gen_well_known_protos_java
We may need the shell environment (potentially augmented with
`--action_env`) to invoke protoc on Windows. If protoc was built with
mingw, it probably needs .dll files in non-default locations that must be
in PATH. Previously with `--compiler=mingw-gcc`,
`bazel build //:gen_well_known_protos_java` would fail on Windows. This
CL fixes the issue.

Also we have `default_shell_env` set to True for `ProtoCompile`, this makes
the behavior consistent.

See #2933, and
585a27ad0a/proto/compiler.bzl (L130)
2020-08-19 17:01:40 -07:00
Harvey Tuch
e492e5a4ef Fix depset/list confusion in #7458.
See
https://github.com/protocolbuffers/protobuf/pull/7458#issuecomment-633147682.

release notes: no

Signed-off-by: Harvey Tuch <htuch@google.com>
2020-05-29 13:05:58 -07:00
Harvey Tuch
9482bfd22b Fix depset/list confusion for ctx.attr.deps.
Signed-off-by: Harvey Tuch <htuch@google.com>
2020-05-14 07:45:57 -07:00
Harvey Tuch
7cf3f7a649 Fix CLI "too long" issues in py_proto_library.
Envoy was experiencing failed builds due to lots of duplicate -I in the
CLI. The solution is to generally use depset() as per Starlark best
practice for this sort of thing.

Might fix other issues beyond py_proto_library, anything that depends on
proto_gen.

release notes: no

Signed-off-by: Harvey Tuch <htuch@google.com>
2020-05-14 07:45:57 -07:00
Leo
12236c6977 Fix typo on py_proto_library 2020-05-08 09:34:26 -07:00
Yannic Bonenberger
723a85f797 [bazel] Remove bootstrap hack from cc_proto_library and add interop with proto_library
Bazel had a native `cc_proto_library` for more than 2 years now.
This is the first step towards removing that rule from the Protobuf
repo.
2020-03-04 09:25:41 -08:00
Yannic
f0cb9cdb95
[bazel] Move Java runtime/toolchains into //java (#7190)
* [bazel] Move Java runtime/toolchains into //java

This change moves `java_library` targets from the top-level BUILD file
into `//java/{core,lite,util}` and declares `alias` targets to point to
their new locations (hence, this is not a breaking change).

This will allow users that don't use Java to stop depending on
`@rules_java` (e.g. as requested in
https://github.com/bazelbuild/rules_scala/pull/989#issuecomment-583405161).

Note that there is no intention to deprecate + remove the top-level
targets in the foreseeable future.

* Add BUILD files in //java to java_EXTRA_DIST
2020-02-13 13:04:14 -08:00
Brian Wignall
a104dffcb6 Fix typos (#7050)
Uses https://en.wikipedia.org/wiki/Wikipedia:Lists_of_common_misspellings/For_machines to find likely typos, with https://github.com/bwignall/typochecker to help automate the checking.
2020-01-08 10:18:20 -08:00
Yannic Bonenberger
d2d6ff51a8 [bazel] Load python rules from @rules_python 2019-08-06 16:50:32 -07:00
Yannic Bonenberger
bf0c69e130 [bazel] Add fixes for --incompatible_load_{cc,java,proto}_rules_from_bzl (Part 2)
This change adds the required loads to examples and zlib.
For full compatibility with --incompatible_load_{cc,java,proto}_rules_from_bzl,
we will need to roll gtest to a newer version.
2019-07-29 14:14:04 -07:00
Benjamin Peterson
6153f80876 Treat plugins as host tools.
As a followup to ca3ead7745, treat plugin executables as well as protoc as host tools.
2019-06-06 12:48:55 -07:00
Keith Smiley
ca3ead7745 Move tool out of inputs in bazel config
This fixes compatibility with bazel when passing `--incompatible_no_support_tools_in_action_inputs` which will be flipped in an upcoming release.
2019-05-28 10:46:14 -07:00
Paul Yang
cecba296b8
Down-integrate internal changes (#5467)
* Down-integrate internal changes

* Update generated code for php, objc and csharp.

* Add missing dependency in conformance_php
2018-12-14 16:05:03 -08:00
Jon Brandvein
7b28271a61 Migrate to new ctx.actions API (#5367)
* Migrate to new `ctx.actions` API

This allows building with --incompatible_new_actions_api.

* Fix typo
2018-11-15 18:19:06 -08:00
Roger Chen
7492b56812 Import versions from @bazel_skylib//lib:versions.bzl
@bazel_skylib//:lib is supposedly deprecated. The 'versions' struct in lib.bzl was committed to bazel-skylib at the same time as //lib:versions.bzl, so there should be no backward incompatibility.
2018-11-02 23:13:17 -07:00
James Judd
d5f0dac497 Change deprecated Bazel single file attr param
This removes the need for --incompatible_disable_deprecated_attr_params
when using Protobuf
2018-08-14 21:55:35 -06:00
Adam Cozzette
2c30fa71e7
Merge pull request #3981 from fahhem/patch-3
Handle srcs in generated files by cd'ing in and out
2018-07-02 15:08:12 -07:00
Feng Xiao
91707246eb
Merge pull request #4168 from jin/master
Use versions module from Skylib for version checking
2018-06-22 17:47:17 -07:00
Ittai Zeidman
4fcb36c51c remove PACKAGE_NAME and REPOSITORY_NAME deprecated usage (#4650) 2018-05-21 13:48:10 -07:00
Fahrzin Hemmati
2cfa7612b2 Fix moving generated files onto themselves 2018-05-07 15:40:31 -07:00
Fahrzin Hemmati
d1403e58d8 Only use realpath when in gendir, and use the original ctx.action if not in gendir 2018-05-07 15:40:31 -07:00
Fahrzin Hemmati
ae638966e5 Track outputs correctly 2018-05-07 15:40:31 -07:00
Fahrzin Hemmati
b3c2ec7073 Handle multiple outs per input (for plugins) 2018-05-07 15:40:31 -07:00
Fahrzin Hemmati
a6501e4a2b Strip trailing / from path 2018-05-07 15:40:31 -07:00
Fahrzin Hemmati
800f8d66bf Handle srcs in generated files by cd'ing in and out 2018-05-07 15:40:31 -07:00
Mateusz Matejczyk
294b5758c3
Output *_pb2_grpc.py when use_grpc_plugin=True
Start outputting missing *_pb2_grpc.py files when  use_grpc_plugin is set to True for py_proto_library.
2018-03-11 17:48:10 -04:00
James O'Kane
950f5e4205 Replace //:protoc and similar default macro arguments with
@com_google_protobuf prefixed versions. This allows them to work in 3rd party
repositories.

Fix a bad visibility rule. :hidden does not exist, but :private does.
2018-03-08 22:30:44 -08:00
Jingwen Chen
b2a190832c Use versions module from Skylib for version checking 2018-01-12 18:42:22 -05:00
Fahrzin Hemmati
35119e39a0 Add a check_protobuf_required_bazel_version() for use in WORKSPACEs 2017-12-04 15:12:08 -08:00
Vladimir Moskva
4fc93044a5 Make .bzl files compatible with future versions of Bazel 2017-08-07 13:33:03 +02:00
Marco A. Harrendorf
dd04ffb923 Adding default shell env
I am adding default shell environment, so that protobuf compilation makes use of set
LD_LIBRARY_PATH and so on.
In this way, also non-default gcc installations (e.g. not in /usr/lib) can be used to compile protobuf.
This would fix the following issue:
https://github.com/bazelbuild/bazel/issues/2515
2017-04-03 17:01:36 +02:00
cgrushko
6fffd4adb4 Bazel can build protobuf when it's not in the root
That is, Bazel can now build protobuf when the latter resides in a subdirectory of a project.
2017-02-08 12:19:40 -05:00
Kristina Chodorow
4e7ecde15c Update genfiles paths to work with a different execroot arrangement
Bazel is changing the way the execution root is organized (see https://github.com/bazelbuild/bazel/issues/1681
for details) and this updates the protobuf path logic to work with both old
and new versions of Bazel.
2017-01-25 14:10:56 -05:00
Adam Cozzette
39f9b43219 Merge pull request #2403 from google/down-integrate-with-msvc-fix
Integrated internal changes from Google
2016-11-23 11:26:31 -08:00
Wiktor Tomczak
0fa31b2bfa Support grpc plugin in py_proto_library 2016-11-22 20:21:10 +01:00
Adam Cozzette
5d63097fc2 Merge branch 'master' into down-integrate-with-msvc-fix 2016-11-17 17:04:30 -08:00
Adam Cozzette
5a76e633ea Integrated internal changes from Google 2016-11-17 16:59:59 -08:00
Feng Xiao
993d604030 Merge pull request #1959 from abergmeier-dsfishlabs/feature/cpp
Need to expose generated protobuf C++ headers
2016-10-13 15:31:18 -07:00
Florian Weikert
c2b3e70efd Declare all inputs of protoc action
ctx.executable.plugin must be in the inputs of protoc's action when using a plugin, otherwise the action will fail.

This bug has been hidden by a bug in Bazel: for every ctx.action, Bazel used to automatically add the runfiles of all executable inputs of the RULE instead of using the inputs of the specific ACTION. Consequently, we could get away with underspecifying the inputs of the action.
2016-10-12 14:03:07 +02:00
Vladimir Moskva
5caf516976 Resolved a conflict 2016-09-12 11:27:28 +02:00
Vladimir Moskva
a86e6d8db2 Compatibility with the new version of Bazel.
Global variable HOST_CFG is deprecated and will not be supported soon.
2016-09-09 13:21:35 +02:00
Andreas Bergmeier
bbeb983bac Need to expose generated protobuf C++ headers so they can actually be accessed from other libraries. 2016-08-15 16:57:30 +02:00
Yuki Yugui Sonoda
5977fb0a05 Generalize plugin support in Bazel Skylark rule
It helps users to support their own plugins in a manner consistent to
cc_proto_library and py_proto_libary in their skylark rules
2016-06-01 16:23:15 +09:00
David Z. Chen
02cd45ca35 Bazel build: Keep generated sources and Python runtime in the same directory.
Users often encounter a Python import error when trying to build Python
protos if protobuf is installed locally on the machine. In this case,
Python ends up looking in the wrong directory when importing files (see
bazelbuild/bazel#1209 and tensorflow/tensorflow#2021). It seems that the
problem is caused by Python getting confused when there are Python
source files that are meant to be part of the same package but are
in separate directories.

Prior to #1233, the Bazel build setup would copy the Python
runtime sources and all generated sources for the builtin protos into
the root directory (assuming that the protobuf tree is vendored in a
google/protobuf directory).

With #1233, the two sets of sources are kept in their respective
directories but both `src/` and `python/` are added to the `PYTHONPATH`
using the new `imports` attribute of the Bazel Python rules. However,
both the runtime sources and the generated sources are under the same
package: `google.protobuf`, causing Python to become confused when
trying to import modules that are in the other directory.

This patch adds a workaround to the Bazel build to add a modified
version of the original `internal_copied_filegroup` macro to copy the
`.proto` files under `src/` to `python/` before building the
`py_proto_library` targets for the builtin protos. This ensures that the
generated sources for the builtin protos will be in the same directory
as the corresponding runtime sources.

This patch was tested with the following:
* All Python tests in protobuf
* All Python tests in tensorflow
* All tests in [Skydoc](https://github.com/bazelbuild/skydoc)
* Importing protobuf as `//google/protobuf`
* Importing and binding targets under `//external`
* Importing protobuf as `//third_party/protobuf`
2016-05-25 18:02:09 -07:00
Steven Parkes
ea1886661e pass correct args to protoc for java wellknown protos when used as an external repository 2016-03-10 15:04:46 -08:00
David Z. Chen
985c968443 Remove hack for building Python support with Bazel.
This change makes use of new imports attribute for Bazel's Python rules, which
enable adding directories to the PYTHONPATH. This allows us to remove
the hack for building protobuf's Python support with Bazel and now
allows projects to include protobuf using a Bazel external repository
rather than requiring it to be imported directly into the source tree as
//google/protobuf.

This change also updates the protobuf BUILD file to use a named
repository, @python//, for including Python headers rather than
//util/python. This allows projects to specify their own package for
Python headers when including protobuf with an external repository.

Fixes #1230
2016-02-25 12:52:21 -08:00
Manjunath Kudlur
f5c736352e Fixed grpc C++ plugin support.
grpc C++ plugin generates additional files, namely .grpc.pb.cc and
.grpc.pb.h. Adding these files to the outs of the _proto_gen rule, so
dependents don't complain about undeclared inclusions. Also, compiling
the .grpc.pb.cc requires additional header files from the grpc library,
so added //external:grpc_lib to the deps of the
cc_library. Clients are expected to declare that in their bazel
WORKSPACE, pointing it to @grpc//:grpc++{_unsecure}.
2016-02-25 08:50:50 -08:00