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?
Related
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",
)
Is there a way to do this? I'm trying to build parts of the AWS SDK (s3 and rds) to use in my Bazel project. I've heard that rules_foreign_cc can be used to integrate CMake projects with Bazel.
tensorflow-io contains bazel build files here:
WORKSPACE
BUILD file
Might be slightly cleaner to adopt these vs using rules_foreign_cc. Note that above links refer to a specific hash in the repo - the files might have changed upstream.
load("#rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()
AWS_BUILD = """\
filegroup(
name = "sdk",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""
new_git_repository(
name = "aws_sdk",
build_file_content = _ALL_CONTENT,
commit = "2550901e1011e0ee1dc1bae44b42e1a2c6947c24",
recursive_init_submodules = True,
remote = "https://github.com/aws/aws-sdk-cpp",
shallow_since = "1628277923 +0000",
)
Then you can reference the binaries from within the BUILD file. Just build the aws-sdk using cmake.
load("#rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
cmake(
name = "aws_sdk",
cache_entries = {
"CMAKE_BUILD_TYPE": "Release",
"BUILD_ONLY": "s3",
"BUILD_SHARED_LIBS": "ON",
"ENABLE_TESTING": "OFF",
},
install = True,
lib_source = "#aws_sdk//:sdk",
out_shared_libs = [
"libaws-cpp-sdk-core.so",
"libaws-cpp-sdk-s3.so",
]
)
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"
],
)