I was trying to use google's media pipe but this Bazel build has no srcs only deps. What is supposed to be the main program in this build?
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
cc_binary(
name = "hand_tracking_tflite",
deps = [
"//mediapipe/examples/desktop:simple_run_graph_main",
"//mediapipe/graphs/hand_tracking:desktop_tflite_calculators",
],
)
cc_binary(
name = "hand_tracking_cpu",
deps = [
"//mediapipe/examples/desktop:demo_run_graph_main",
"//mediapipe/graphs/hand_tracking:desktop_tflite_calculators",
],
)
# Linux only
cc_binary(
name = "hand_tracking_gpu",
deps = [
"//mediapipe/examples/desktop:demo_run_graph_main_gpu",
"//mediapipe/graphs/hand_tracking:mobile_calculators",
],
)
As stated in cc_binary docs deps defines list of libraries linked to this binary target. First dependency of each rule defines a library with the main function. You can see this looking at first dependency definition:
mediapipe/examples/desktop/BUILD:
cc_library(
name = "simple_run_graph_main",
srcs = ["simple_run_graph_main.cc"],
deps = [
#... removed for clarity.
],
)
Therefore main is defined in mediapipe/examples/desktop/demo_run_graph_main.cc
Hope it helps ;)
Related
I am trying to use Bazel to create distributable framework and I have BUILD file like this:
ios_dynamic_framework(
name = "TheFramework",
bundle_name = "TheFramework",
...
deps = [
"TheFrameworkLib",
]
)
swift_library(
name = "TheFrameworkLib",
module_name: "TheFramework"
srcs = [
# publicly available
],
deps = [
":InternalLib"
],
)
swift_library(
name = "InternalLib",
srcs = [
# internal files
],
)
It builds successfully, and I can see by the size of the framework that InternalLib is also included in the binary. However, when I import this TheFramework.framework in the new iOS project (without Bazel), I am getting error: Missing required module "InternalLib". Any ideas how this can work? I guess I am missing some flags?
I am attempting to create a py_binary in bazel and then copy that to a remote machine. At the moment I was doing a dummy app to make sure the pipeline would work. I cannot use a docker image as I need lower level control of the hardware than docker can provide.
My goal is to do the following:
build the software with bazel
create a tar package that contains the py_binary
copy and run that binary on another computer not connected to bazel
To do this I made a simple binary(that for context just makes some RPC calls to a server I am working on as a side project) and the build files is as follows:
py_binary(
name="rosecore_cli",
srcs=glob([
"src/*.py"
]),
deps = [
"//rosecore/proto:project_py_pb2_grpc",
"//rosecore/proto:project_py_pb2"
]
)
pkg_files(
name = "binary",
srcs = [
":rosecore_cli",
],
prefix = "/usr/share/rosecore/bin",
)
pkg_filegroup(
name = "arch",
srcs = [
":binary",
],
visibility = ["//visibility:public"],
)
pkg_tar(
name = "rosecore_tar",
srcs = [
":arch"
],
include_runfiles=True
)
When I build, copy the tar file and extract it I get the following error:
AssertionError: Cannot find .runfiles directory for ./usr/share/rosecore/bin/rosecore_cli
Any help would be appreciated :)
I am trying to get a rules docker nodejs_image to run using bazel.
My command is
bazel run :image.binary
Here is my rule:
load("#npm//#bazel/typescript:index.bzl", "ts_project")
load("#io_bazel_rules_docker//nodejs:image.bzl", "nodejs_image")
ts_project(
name = "typescript_build",
srcs = glob([
"src/**/*",
]),
allow_js = True,
out_dir = "build",
deps = ["#npm//:node_modules"],
)
nodejs_image(
name = "image",
data = [
":package.json",
":typescript_build",
"#npm//:node_modules",
],
entry_point = "build/app.js",
)
Basically, I need the package.json file because it includes some important configuration information when Node executes. If I call bazel build :image and then grab/run that image, everything works fine. But if I call bazel run :image it will basically work except that it can't find the package.json.
When I check the bazel-bin/ folder, I've noticed that the package.json isn't included, but the built typescript and node_modules are. I'm guessing because I'm not running any prior rules on the package.json, it doesn't get added to the bin, but I really don't know how to work around this.
So, basically, it seems that if you just use a rule like copy_to_bin or js_library, I think their purpose is to help put static files into your bazel-bin.
https://bazelbuild.github.io/rules_nodejs/Built-ins.html#copy_to_bin
ts_project(
name = "typescript_build",
srcs = glob([
"src/**/*",
]),
allow_js = True,
out_dir = "build",
deps = ["#npm//:node_modules"],
)
js_library(
name = "library",
srcs = ["package.json"],
deps = [":typescript_build"],
)
nodejs_image(
name = "image",
data = [
":library",
"#npm//:node_modules",
],
entry_point = "build/app.js",
)
I am trying to build OpenCV with external modules, but haven't been able to come up with a clean solution.
I have successfully built OpenCV using CMake (rules_foreign_cc). But to be able to build with external modules I need to download a separate repo (opencv_contrib) and then build using the path to the second repo as a build argument.
Is there a way I can do this without having to create a git repo of my own that combines these two git repos?
# WORKSPACE file
http_archive(
name = "rules_foreign_cc",
strip_prefix = "rules_foreign_cc-4010620160e0df4d894b61496d3d3b6fc8323212",
sha256 = "07e3414cc841b1f4d16e5231eb818e5c5e03e2045827f5306a55709e5045c7fd",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/4010620160e0df4d894b61496d3d3b6fc8323212.zip",
)
load("#rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
http_archive(
name = "opencv_contrib",
build_file="//:opencv_contrib.BUILD",
sha256 = "9f52fd3114ac464cb4c9a2a6a485c729a223afb57b9c24848484e55cef0b5c2a",
urls = ["https://github.com/opencv/opencv_contrib/archive/refs/tags/4.5.2.tar.gz"],
strip_prefix = "opencv_contrib-4.5.2",
)
http_archive(
name = "opencv",
sha256="ae258ed50aa039279c3d36afdea5c6ecf762515836b27871a8957c610d0424f8",
build_file="//:opencv.BUILD",
urls = ["https://github.com/opencv/opencv/archive/refs/tags/4.5.2.tar.gz"],
strip_prefix = "opencv-4.5.2",
)
# opencv_contrib.BUILD file
filegroup(
name = "modules",
srcs = glob(["modules/**"]),
visibility = ["//visibility:public"],
)
# opencv.BUILD file
load("#rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
cmake(
name = "opencv",
generate_args = ["-GNinja"],
additional_inputs=["#opencv_contrib//:modules"],
cache_entries = {
"BUILD_SHARED_LIBS": "OFF",
"BUILD_opencv_world": "ON",
"OPENCV_EXTRA_MODULES_PATH": "$$EXT_BUILD_ROOT$$/external/opencv_contrib/modules",
},
lib_source = ":srcs",
out_static_libs = ["libopencv_world.a"],
)
You can use git_repository rule in your WORKSPACE file to have bazel automatically clone a git repo before building.
Once you add it to the WORKSPACE file, then you can reference build targets of the remote repo inside your own repo.
Check this repo for an example.
I am trying to use Bazel for java tests. And need to access data files under resources. My project has standard Maven structure. I am using filegroup for the resources and have it as dependency in java_test.
The issue is when i try to run the test, it fails with following error java.lang.RuntimeException: org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: file:/private/var/tmp/_bazel_username/2c26269e9af968f4ce3e88b22720114e/execroot/myproject/bazel-out/darwin-fastbuild/bin/hadoop/com_company_hadoop_search_join_TermTest.jar!/com/company/hadoop/search/join/names.txt
I have following in my src/test/resources/BUILD:
filegroup(
name = "resources",
testonly = 1,
srcs = glob(["**/*.txt"]),
visibility = ["//visibility:public"],
)
And the following in my hadoop/BUILD:
java_test(
srcs =
["src/test/java/com/company/hadoop/search/join/TermTest.java"],
resources = ["//hadoop/src/test/resources:resources"],
deps = [
"//src/main/java/com/path/to/my/code",
"//:junit_junit",
],
)
I verified the test jar contents and text file does exist as expected.
I believed your test "resources" are not java resources but data files.
Use the data attribute:
java_test(
srcs = [
"src/test/java/com/company/TermTest.java",
],
data = [
"//hadoop/src/test/resources:resources",
],
deps = [
"//src/main/java/com/path/to/my/code"
],
)