bazel pypi macro self-edge - pypi

I'm stumbling around trying to get bazel working with pypi dependencies.
./pypi.bzl:
def _impl(ctx):
ctx.actions.run_shell(
command = "pip download %s" % ctx.package
)
_pypi_package = rule(
implementation=_impl,
attrs={"package": attr.label(mandatory=True)},
)
def pypi_package(package):
_pypi_package(name = package, package = package)
./BUILD:
py_binary(
name = "app",
srcs = ["app.py"],
deps = [":python-dateutil"]
)
load("//:pypi.bzl", "pypi_package")
pypi_package(
package="python-dateutil",
)
Trying to build:
$ bazel build app
ERROR: /path/to/cwd/BUILD:9:1: in _pypi_package rule //:python-dateutil: cycle in dependency graph:
//:app
.-> //:python-dateutil [self-edge]
`--
This cycle occurred because of a configuration option.
ERROR: Analysis of target '//:app' failed; build aborted.
INFO: Elapsed time: 0.219s
No idea if this is even the right approach for working with external dependencies, but ignoring that, I don't understand where the self-dep here is coming from. In fact, I don't see that I'm declaring any deps for the pypi_package rule at all. What's going on?

The issue was attr.label: "label" here means BUILD label. I should have been using attr.string.

Related

Bazel use tensorflow ( or only use tbb) as a external dependency has a "Make" Variables not defined error

I have a c++ project that use bazel as build tools and use tensorflow as a external dependency, bazel version is 0.24.1 and tensorflow version is 1.14.0, it works fine (In my project I use tbb in the tensorflow as a deps in bazel's rule).
But when I update bazel to 3.1.0 and update tensorflow to 2.3.0, I have the error:
ERROR: external/tbb/BUILD.bazel:11:1: in cmd attribute of genrule rule #tbb//:build_tbb: $(AR) not defined
My WOKSPACE file:
http_archive(
name = "org_tensorflow",
strip_prefix = "tensorflow-2.3.0",
sha256 = "2595a5c401521f20a2734c4e5d54120996f8391f00bb62a57267d930bce95350",
urls = ["https://github.com/tensorflow/tensorflow/archive/tensorflow-2.3.0.tar.gz"]
)
My BUILD file:
cc_library(
name = "tf_utils",
srcs = ["tf_utils.cpp"],
hdrs = ["tf_utils.h"],
deps = ["#org_tensorflow//tensorflow/cc/saved_model:loader", "utils"],
visibility = ["//visibility:public"]
)
cc_library(
name = "utils",
hdrs = ["utils.h"],
srcs = ["utils.cpp"],
deps = ["#boost//:filesystem",
"#eigen_archive//:eigen",
"#tbb//:tbb",], # I use the tbb in the tensorflow
visibility = ["//visibility:public"]
)
Firts, I test tbb in the tensorflow project itself, it has the same error.
The way of my test is, write the follow c++ rule in the tensorflow/BUILD:
cc_library(
name = "test-tbb",
srcs = ["test.cpp"],
deps = ["#ngraph_tf//:ngraph_tf"] # ngraph_tf's deps has tbb
)
and then excute bazel build //tensorflow:test-tbb, it has the same error:
#tbb//:build_tbb: $(AR) not defined
second, I think the problem may be in tbb. I test tbb in two ways:
I download tbb sources, and in the root dir of the tbb, make a WORKSPACE(empty) and a BUILD (only rename tbb.BUILD to BUILD), then excute bazel build //:build_tbb, when bazel version is 0.24.1, all is right, but has the above error when change bazel version to 3.1.0.
I only use tbb as a external dependency in a miniproject, which WORKSPACE has a http_archive named tbb, and it's build_file point to a tbb.BUILD. I write a cc_library in BUILD flie and it's deps = ["#tbb:build_tbb"], the test result is the same as 1), when bazel version is 0.24.1 is ok, 3.1.0 is broken.
tbb.BUILD I used: https://github.com/tensorflow/tensorflow/blob/r2.3/third_party/ngraph/tbb.BUILD
Third, I follow the document of bazel (https://docs.bazel.build/versions/master/be/make-variables.html#custom_variables), sets toolchains = ["#bazel_tools//tools/cpp:current_cc_toolchain"] in the rule "build_tbb" in tbb.BUILD, than the error message is "in cmd attribute of genrule rule //:build_tbb: $(CC_FLAGS) not defined".
Fourth, I follow the solution of the issue:https://github.com/rnburn/satyr/issues/2, update the tbb.BUILD file, than retry and the error message is "in cmd attribute of genrule rule #tbb//:build_tbb: $(C_COMPILER) not defined".
I just want use use tensorflow as an external dependency and use the bazel target "tbb" statement in tensorflow (Since it is in tensorflow, I don’t want to recompile multiple times)
Does anyone know how to correctly use tensorflow and tbb as an external dependency that use bazel 3.0.0+? Thanks!

Unable to build bazel project: no such package '#io_bazel_rules_kotlin//kotlin'

OS:
daz#daz:/rom/aosp-mirror/android-test$ uname -ar
Linux daz 5.4.0-28-generic #32-Ubuntu SMP Wed Apr 22 17:40:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Building with bazel-2.2.0 with the target in the code below:
daz#daz:/rom/aosp-mirror/android-test$ bazel-2.2.0 build :axt_m2repository
I am trying to build the android-test repo here:
https://github.com/android/android-test
The definition for these rules appears to be this:
# Kotlin toolchains
rules_kotlin_version = "4c71740a1b63b785fc90afd8d4d4d5bfda527107"
http_archive(
name = "io_bazel_rules_kotlin",
sha256 = "c0ca7b66d9f466067635482592634703bf0a648d51ec958f41796d43ca8256b3",
strip_prefix = "rules_kotlin-%s" % rules_kotlin_version,
type = "zip",
urls = ["https://github.com/bazelbuild/rules_kotlin/archive/%s.zip" % rules_kotlin_version],
)
load("#io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories()
kt_register_toolchains()
But I get the following exception when trying to build:
ERROR: error loading package '': Encountered error while reading extension file 'kotlin/kotlin.bzl': no such package '#io_bazel_rules_kotlin//kotlin': error loading package 'external': Could not load //external package
The full output is here:
ERROR: /home/daz/.cache/bazel/_bazel_daz/ff62db25b941d7730a4c94ee1d6f2c41/external/robolectric/bazel/robolectric.bzl:2:5: Traceback (most recent call last):
File "/rom/aosp-mirror/android-test/WORKSPACE", line 130
robolectric_repositories()
File "/home/daz/.cache/bazel/_bazel_daz/ff62db25b941d7730a4c94ee1d6f2c41/external/robolectric/bazel/robolectric.bzl", line 381, in robolectric_repositories
android_all_jars()
File "/home/daz/.cache/bazel/_bazel_daz/ff62db25b941d7730a4c94ee1d6f2c41/external/robolectric/bazel/robolectric.bzl", line 2, in android_all_jars
native.maven_jar
no native function or rule 'maven_jar'
Available attributes: aar_import, action_listener, alias, android_binary, android_device, android_device_script_fixture, android_host_service_fixture, android_instrumentation_test, android_library, android_local_test, android_ndk_repository, android_sdk, android_sdk_repository, android_tools_defaults_jar, apple_binary, apple_cc_toolchain, apple_static_library, available_xcodes, bazel_version, bind, cc_binary, cc_host_toolchain_alias, cc_import, cc_libc_top_alias, cc_library, cc_proto_library, cc_test, cc_toolchain, cc_toolchain_alias, cc_toolchain_suite, config_feature_flag, config_setting, constraint_setting, constraint_value, environment, existing_rule, existing_rules, exports_files, extra_action, fdo_prefetch_hints, fdo_profile, filegroup, genquery, genrule, glob, j2objc_library, java_binary, java_import, java_library, java_lite_proto_library, java_package_configuration, java_plugin, java_proto_library, java_runtime, java_runtime_alias, java_test, java_toolchain, java_toolchain_alias, label_flag, label_setting, local_config_platform, local_repository, new_local_repository, ninja_build, ninja_graph, objc_import, objc_library, package_group, package_name, platform, proto_lang_toolchain, proto_library, py_binary, py_library, py_runtime, py_test, register_execution_platforms, register_toolchains, repository_name, sh_binary, sh_library, sh_test, test_suite, toolchain, toolchain_type, xcode_config, xcode_config_alias, xcode_version
ERROR: error loading package '': Encountered error while reading extension file 'kotlin/kotlin.bzl': no such package '#io_bazel_rules_kotlin//kotlin': error loading package 'external': Could not load //external package
INFO: Elapsed time: 0.061s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
WORKAROUND
Build branch:
androidx-test-1.3.0-beta01
Use bazel-2.2.0
bazel-2.2.0 build :axt_m2repository
This is the related issue in the android-test github issue tracker:
https://github.com/android/android-test/issues/626
Make sure that you're using the latest version of Bazel and the android-test repo.
The maven_jar native rule was removed in Bazel 2.0 (Bazel tracking ticket). Have you tried building with a Bazel version < 2.0 (e.g. 1.2.1)?

"Genrules without outputs don't make sense" - Bazel Windows 10 build

I've been trying to compile tensorflow 1.1 inception with bazel 0.4.2 on windows 10 using CUDA 8.0.
I haven't been able to find a corresponding error online.
C:\Users\me\Anaconda3\envs\tensorflow_gpu\tensorflow>bazel build --config=opt tensorflow/examples/image_retraining:retrain
ERROR: C:/users/me/appdata/local/temp/_bazel_simon/qco1pmlq/external/local_config_cuda/cuda/BUILD:172:12: in outs attribute of genrule rule #local_config_cuda//cuda:cuda-include: Genrules without outputs don't make sense.
After digging into the Build file specified in the error message I have these genrules which are missing inputs:
genrule(
name = "cuda-include",
outs = [
],
cmd = """
""",
)
genrule(
name = "cuda-nvvm",
outs = [
],
cmd = """
""",
)
genrule(
name = "cuda-extras",
outs = [
],
cmd = """
""",
)
I am assuming these should have been generated? I do have an example of other rules that follow that format but unsure which files and if that is the correct way to go. Any help would be greatly appreciated.
Tensorflow GPU Build with Bazel on Windows is not very stable. Currently it's broken from both sides.
This change was just sent to fix problems in Bazel.
And this PR will make Cuda configuration work on Windows again.
You can first build Bazel from HEAD. And after the PR is merged, use your custom Bazel to build TensorFlow from HEAD.
The correct command on Windows would be:
bazel build -c opt --config=win-cuda --cpu=x64_windows_msvc --host_cpu=x64_windows_msvc --copt=-w --host_copt=-w tensorflow/tools/pip_package:build_pip_package
FYI, there is a script for building TensorFlow on Windows:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/ci_build/windows/gpu/pip/build_tf_windows.sh

bazel - Error building TensorFlow with local LLVM repository

Essentially, I want to run TensorFlow with a custom LLVM repository and not the llvm-mirror that bazel pulls from.
I made the following changes:
Changed the temp_workaround_http_archive rule in //tensorflow/workspace.bzl to:
native.local_repository (
name = "llvm",
path = "/git/llvm/",
)
In /git/llvm I added the file WORKSPACE containing:
workspace( name = "llvm" )
However, I know that an llvm.build file is required, but since I am new to bazel, I am not sure where it should be located.
I am getting the following error log:
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
ERROR: /git/tensorflow/tensorflow/tools/pip_package/BUILD:81:1: no such package '#llvm//': BUILD file not found on package path and referenced by '//tensorflow/tools/pip_package:licenses'.
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted.
INFO: Elapsed time: 0.219s
I installed TensorFlow from source. Here is the version info:
$ git rev-parse HEAD
4c3bb1aeb7bb46bea35036433742a720f39ce348
$ bazel version
Build label: 0.4.5
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Mar 16 12:19:38 2017 (1489666778)
Build timestamp: 1489666778
Build timestamp as int: 1489666778
Thanks in advance for the help!
Found the fix. Quite simple actually.
The local_repository rule in bazel is for external bazel repositories only. To use a non-bazel external repository, we need to use new_local_repository which takes build_file as an argument.
You can use the http server function of python to build a local file server, like:
python3 -m http.server
Then edit the file "tensorflow/workspace.bzl"
tf_http_archive(
name = "llvm",
urls = [
"https://mirror.bazel.build/**/195a164675af86f390f9816e53291013d1b551d7.tar.gz",
"http://localhost:8000/195a164675af86f390f9816e53291013d1b551d7.tar.gz",
"https://github.com/**/195a164675af86f390f9816e53291013d1b551d7.tar.gz",
],
sha256 = "57a8333f8e6095d49f1e597ca18e591aba8a89d417f4b58bceffc5fe1ffcc02b",
strip_prefix = "llvm-195a164675af86f390f9816e53291013d1b551d7",
build_file = str(Label("//third_party/llvm:llvm.BUILD")),
)
Add one local file path in the middle line of urls, and then rebuild it again.

Build chromium for raspberrypi2 on wayland with yocto project brings error related to egl.pc and wayland-egl.pc

I have completed building qt5 on raspberrypi2 by following the instruction here: http://www.embarcados.com.br/raspberry-pi-2-qt5-yocto-parte-1/
My next goal is to build chromium with wayland and egl. I have added one more layer from "https://github.com/OSSystems/meta-browser".
Actually, I could successfully build chromium with x11 but still failing with wayland. The things I did for wayland is to add "wayland" with DISTRO_FEATURES_append = " wayland" and remove x11 with DISTRO_FEATURES_remove = " x11".
However, this yields errors and the error messages mentions that missing "egl.pc" and "wayland-egl.pc". Should I add some more components in "DEPENDS" section which will be pre built and create those two package config files in addition to those components in chromium.inc? The build configurations and error messages shown are below.
Build Configuration:
BB_VERSION = "1.26.0"
BUILD_SYS = "x86_64-linux"
NATIVELSBSTRING = "Ubuntu-14.04"
TARGET_SYS = "arm-poky-linux-gnueabi"
MACHINE = "raspberrypi2"
DISTRO = "poky"
DISTRO_VERSION = "1.8"
TUNE_FEATURES = "arm armv7a vfp thumb neon callconvention-hard vfpv4 cortexa7"
TARGET_FPU = "vfp-vfpv4-neon"
meta-embarcados
meta-rpi = "fido:dfb2e27bf26b109fc6ccb3bc91924fb3bb24f655"
meta-qt5 = "fido:fc026381545650e10fdd488d5b2a3b2d78f87793"
meta-raspberrypi = "fido:b896a7da70dd7a16ba7ffd664f7747cb37e1d142"
meta-oe
meta-ruby
meta-gnome = "fido:10d3c8f85280a0bf867a8e4f84bcda81c290d28e"
meta
meta-yocto = "fido:cd2c9acdbd75c83790e8144d2a834f5b5de35df0"
meta-browser = "master:ca96f4326345dcd779fc539877a04f069f431749"
NOTE: Preparing RunQueue
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: Function failed: do_configure (log file is located at /home/paul/yocto/build-browser-fido/tmp/work/cortexa7hf-vfp-vfpv4-neon-poky-linux-gnueabi/chromium/40.0.2214.91-r0/temp/log.do_configure.13805)
ERROR: Logfile of failure stored in: /home/paul/yocto/build-browser-fido/tmp/work/cortexa7hf-vfp-vfpv4-neon-poky-linux-gnueabi/chromium/40.0.2214.91-r0/temp/log.do_configure.13805
Updating projects from gyp files...
Package xcb-shm was not found in the pkg-config search path.
Perhaps you should add the directory containing xcb-shm.pc'
to the PKG_CONFIG_PATH environment variable
Package 'xcb-shm', required by 'cairo', not found
gyp: Call to 'pkg-config --cflags pangocairo pangoft2' returned exit status 1.
Requested 'egl >= 9.1.3' but version of egl is 0.0
Package wayland-egl was not found in the pkg-config search path.
Perhaps you should add the directory containingwayland-egl.pc'
to the PKG_CONFIG_PATH environment variable
No package 'wayland-egl' found
gyp: Call to 'pkg-config --cflags "egl >= 9.1.3" "wayland-client >= 1.4.0" >>
Thank you very much for your help.
I found that I should have not done DISTRO_FEATURES_remove = " x11". However, I`m still attempting to launch chromium based on wayland compositor.