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 :)
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 have a Bazel executable target (of type fsharp_binary, but I don't think it should matter) that I can run using bazel run.
bazel run //my_app.exe
I would like to use this executable as a test, so that when I call bazel test it gets built and executed, and a non-zero exit code is considered a test failure.
bazel test //...
What I am looking for is something like this:
test_of_executable(
name = "my_test",
executable = "//my_app.exe",
success_codes = [ 0 ],
)
Then:
bazel test //:my_test
How can I achieve this in Bazel?
Just wrap your app as a sh_test. See for example https://github.com/bazelbuild/bazel/issues/1969.
What I use in my codebase is:
BUILD.bazel:
sh_test(
name = "test",
srcs = ["test.sh"],
data = [
"//:some_binary",
],
)
test.sh
some_project/some_subdir/some_binary
See here for an real example.
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 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 ;)
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"
],
)