Here's my workspace;
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
RULES_JVM_EXTERNAL_TAG = "4.0"
RULES_JVM_EXTERNAL_SHA = "31701ad93dbfe544d597dbe62c9a1fdd76d81d8a9150c2bf1ecf928ecdf97169"
http_archive(
name = "maven",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)
load("#maven//:defs.bzl", "maven_install")
maven_install(
artifacts = [
"com.fasterxml.jackson.core:jackson-databind:2.12.1",
"org.apache.commons:commons-lang3:3.11"
],
repositories = [
"https://repo1.maven.org/maven2",
"https://jcenter.bintray.com/"
],
);
Here's my second/BUILD
java_binary(
name = "main",
srcs = glob(["src/main/java/**/*.java"]),
deps = [
"//First:first",
],
main_class = "com.test.MyMain",
);
here's my First/Build
java_library(
name = "first",
srcs = glob(["src/main/java/**/*.java"]),
deps = [
"#maven//:com_fasterxml_jackson_core_jackson_databind",
],
visibility =[ "//Second:__pkg__"],
);
when doing
bazel build //Second:main
I get
ERROR: /Users/foobar/Documents/Main/First/BUILD:1:13: error loading package '#maven//': Unable to find package for #bazel_skylib//:bzl_library.bzl: The repository '#bazel_skylib' could not be resolved. and referenced by '//First:first'
ERROR: Analysis of target '//Second:main' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.078s
INFO: 0 processes.
You need to add Bazel Skylib to your workspace. Follow the "workspace setup" instructions here: https://github.com/bazelbuild/bazel-skylib/releases
Related
I have the following in a BUILD file:
proto_library(
name = "proto_default_library",
srcs = glob(["*.proto"]),
visibility = ["//visibility:public"],
deps = [
"#go_googleapis//google/api:annotations_proto",
"#grpc_ecosystem_grpc_gateway//protoc-gen-openapiv2/options:options_proto",
],
)
genrule(
name = "generate-buf-image",
srcs = [
":buf_yaml",
":buf_breaking_image_json",
":protos",
],
exec_tools = [
":proto_default_library",
"//buf:generate-buf-image-sh",
"//buf:generate-buf-image",
],
outs = ["buf-image.json"],
cmd = "$(location //buf:generate-buf-image-sh) --buf-breaking-image-json=$(location :buf_breaking_image_json) $(location :protos) >$#",
)
While executing $(location //buf:generate-buf-image-sh), glob(["*.proto"]) of proto_default_library can be seen in the sandbox but the proto files of #go_googleapis//google/api:annotations_proto and #grpc_ecosystem_grpc_gateway//protoc-gen-openapiv2/options:options_proto cannot. The same goes for the dependencies of //buf:generate-buf-image-sh.
Do I need to explicitly list out all transitive dependencies so they can be processed by generate-buf-image? Is there a programmatic way to do that?
Since genrules are pretty generic, a genrule sees only the default provider of a target, which usually just has the main outputs of that target (e.g., for java_library, a jar of the classes of that library, for proto_library, the proto files of that library). So to get more detailed information, you would write a Starlark rule to access more specific providers. For example:
WORKSPACE:
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_proto",
sha256 = "66bfdf8782796239d3875d37e7de19b1d94301e8972b3cbd2446b332429b4df1",
strip_prefix = "rules_proto-4.0.0",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
],
)
load("#rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
rules_proto_dependencies()
rules_proto_toolchains()
defs.bzl:
def _my_rule_impl(ctx):
output = ctx.actions.declare_file(ctx.attr.name + ".txt")
args = ctx.actions.args()
args.add(output)
inputs = []
for src in ctx.attr.srcs:
proto_files = src[ProtoInfo].transitive_sources
args.add_all(proto_files)
inputs.append(proto_files)
ctx.actions.run(
inputs = depset(transitive = inputs),
executable = ctx.attr._tool.files_to_run,
arguments = [args],
outputs = [output],
)
return DefaultInfo(files = depset([output]))
my_rule = rule(
implementation = _my_rule_impl,
attrs = {
"srcs": attr.label_list(providers=[ProtoInfo]),
"_tool": attr.label(default = "//:tool"),
},
)
ProtoInfo is here: https://bazel.build/rules/lib/ProtoInfo
BUILD:
load(":defs.bzl", "my_rule")
proto_library(
name = "proto_a",
srcs = ["proto_a.proto"],
deps = [":proto_b"],
)
proto_library(
name = "proto_b",
srcs = ["proto_b.proto"],
deps = [":proto_c"],
)
proto_library(
name = "proto_c",
srcs = ["proto_c.proto"],
)
my_rule(
name = "foo",
srcs = [":proto_a"],
)
sh_binary(
name = "tool",
srcs = ["tool.sh"],
)
proto_a.proto:
package my_protos_a;
message ProtoA {
optional int32 a = 1;
}
proto_b.proto:
package my_protos_b;
message ProtoB {
optional int32 b = 1;
}
proto_c.proto:
package my_protos_c;
message ProtoC {
optional int32 c = 1;
}
tool.sh:
output=$1
shift
echo input protos: $# > $output
$ bazel build foo
INFO: Analyzed target //:foo (40 packages loaded, 172 targets configured).
INFO: Found 1 target...
Target //:foo up-to-date:
bazel-bin/foo.txt
INFO: Elapsed time: 0.832s, Critical Path: 0.02s
INFO: 5 processes: 4 internal, 1 linux-sandbox.
INFO: Build completed successfully, 5 total actions
$ cat bazel-bin/foo.txt
input protos: proto_a.proto proto_b.proto proto_c.proto
When I try to compile a bazel project that uses gRPC reflection, I get the following error.
fatal error: external/com_github_grpc_grpc/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h: No such file or directory
In my WORKSPACE, I have the following bindings:
def _com_github_grpc_grpc():
external_http_archive("com_github_grpc_grpc")
external_http_archive("build_bazel_rules_apple")
# Rebind some stuff to match what the gRPC Bazel is expecting.
native.bind(
name = "protobuf_headers",
actual = "#com_google_protobuf//:protobuf_headers",
)
native.bind(
name = "libssl",
actual = "//external:ssl",
)
native.bind(
name = "cares",
actual = "//external:ares",
)
native.bind(
name = "grpc",
actual = "#com_github_grpc_grpc//:grpc++",
)
In my BUILD file, I have the following deps:
deps = [
"//external:protobuf_headers",
"//external:grpc",
],
What additional incantations do I need for the include at the top of the question?
After a spelunking through issues, I figured out that I need the following WORKSPACE
workspace(name = "xxx")
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_github_grpc_grpc",
strip_prefix = "grpc-master",
urls = ["https://github.com/grpc/grpc/archive/master.tar.gz"],
)
load("#com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("#com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()
and the following BUILD:
cc_binary(
name = "ReflectionPlay",
copts = ["-std=c++17"],
srcs = ["reflection_play.cc"],
deps = [
"#com_github_grpc_grpc//:grpc++",
"#com_github_grpc_grpc//:grpc++_reflection",
"#com_github_grpc_grpc//:grpcpp_admin",
],
)
I got this error when build iOS app with openCV:
INFO: Build options --apple_platform_type, --compilation_mode, --cpu, and 3 more have changed, discarding analysis cache.
INFO: Analyzed target //ios-app:ios-app (49 packages loaded, 2428 targets configured).
INFO: Found 1 target...
ERROR: /Volumes/0906411561/My_project/bazel_iOS_sample/examples/tutorial/ios-app/BUILD:36:16: Linking ios-app/ios-app_bin failed: (Aborted): wrapped_clang_pp failed: error executing command external/local_config_cc/wrapped_clang_pp #bazel-out/ios-x86_64-min10.0-applebin_ios-ios_x86_64-fastbuild-ST-7bf874b56ea0/bin/ios-app/ios-app_bin-2.params
Use --sandbox_debug to see verbose messages from the sandbox
Undefined symbols for architecture x86_64:
"cv::Mat::Mat()", referenced from:
___cxx_global_var_init in libwrapper.a(wrapper.o)
___cxx_global_var_init.1 in libwrapper.a(wrapper.o)
___cxx_global_var_init.2 in libwrapper.a(wrapper.o)
___cxx_global_var_init.3 in libwrapper.a(wrapper.o)
"cv::Mat::~Mat()", referenced from:
___cxx_global_var_init in libwrapper.a(wrapper.o)
___cxx_global_var_init.1 in libwrapper.a(wrapper.o)
___cxx_global_var_init.2 in libwrapper.a(wrapper.o)
___cxx_global_var_init.3 in libwrapper.a(wrapper.o)
ld: symbol(s) not found for architecture x86_64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1
Target //ios-app:ios-app failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 24.334s, Critical Path: 0.83s
INFO: 10 processes: 10 internal.
FAILED: Build did NOT complete successfully
In the file wrapper.cpp , I only have this source code:
#include "wrapper.hpp"
#include <iostream>
#include "opencv2.framework/Versions/A/Headers/opencv.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
cv::Mat imgGray,imgBlur,imgCanny,imgDil;
void Wrapper::testEmptyFunc()
{
std::cout << "testEmptyFunc";
}
wrapper.hpp
#include <stdio.h>
class Wrapper
{
public:
void testEmptyFunc();
};
I include from the viewcontroller like this:
#import "wrapper.hpp"
Call the function:
Wrapper* wrapperObj = new Wrapper();
wrapperObj->testEmptyFunc();
My WORKSPACE is:
load("#bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_apple",
sha256 = "c84962b64d9ae4472adfb01ec2cf1aa73cb2ee8308242add55fa7cc38602d882",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.31.2/rules_apple.0.31.2.tar.gz", )
load(
"#build_bazel_rules_apple//apple:repositories.bzl",
"apple_rules_dependencies", )
apple_rules_dependencies()
load(
"#build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies", )
apple_support_dependencies()
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "build_bazel_rules_swift",
sha256 = "f872c0388808c3f8de67e0c6d39b0beac4a65d7e07eff3ced123d0b102046fb6",
url = "https://github.com/bazelbuild/rules_swift/releases/download/0.23.0/rules_swift.0.23.0.tar.gz", )
load(
"#build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies", )
swift_rules_dependencies()
load(
"#build_bazel_rules_swift//swift:extras.bzl",
"swift_rules_extra_dependencies", )
swift_rules_extra_dependencies()
git_repository(
name = "build_bazel_apple_support",
remote = "https://github.com/bazelbuild/apple_support.git",
tag = "0.11.0", )
git_repository(
name = "bazel_skylib",
remote = "https://github.com/bazelbuild/bazel-skylib.git",
tag = "1.0.3", )
http_archive(
name = "ios_opencv",
sha256 = "b85c23953e66f202a5e4b83484f90556ad4ea9df6fcb7934044d5d4decf2898f",
type = "zip",
build_file = "#//third_party:opencv_ios.BUILD",
url = "https://github.com/opencv/opencv/releases/download/4.5.3/opencv-4.5.3-ios-framework.zip", )
# Tesseract
http_archive( name = "ios_tesseract", url = "https://github.com/kang298/Tesseract-builds-for-iOS/archive/refs/tags/tesseract-ios-4.1.1.zip", type = "zip", build_file = "#//third_party:tesseract.BUILD", )
Please help me to solve this issue.
This is how OpenCV works for me under Windows 10:
WORKSPACE.bazel:
workspace(name = "OpenCVDemo")
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# OpenCV
http_archive(
name = "opencv",
build_file = "//ThirdParty:opencv.BUILD",
strip_prefix = "opencv/build",
# Debug
#url = "http://vertexwahn.de/artifacts/opencv-4.3.0-dldt-2020.2-vc16-avx2-debug.zip",
#sha256 = "9bcd2dda258e67ad2ddef7768f1c9b2afcc68cd4b9d9f5c9b841ea3ee47f9d4c",
# Release
url = "https://github.com/opencv/opencv/releases/download/4.3.0/opencv-4.3.0-dldt-2020.2-vc16-avx2.zip",
)
opencv.BUILD:
package(default_visibility = ["//visibility:public"])
MAIN_MODULES = [
"core",
"imgproc",
"imgcodecs",
"videoio",
"highgui",
"video",
"calib3d",
"features2d",
"objdetect",
"dnn",
"ml",
"flann",
"photo",
"stitching",
"gapi",
]
# https://stackoverflow.com/questions/56108940/how-to-specify-the-compiler-flags-to-be-used-in-opt-compilation-mode-by-my-own
config_setting(
name = "fastbuild_mode",
values = {"compilation_mode": "fastbuild"},
)
config_setting(
name = "dbg_mode",
values = {"compilation_mode": "dbg"},
)
cc_import(
name = "tbb",
shared_library = select({
":fastbuild_mode": "bin/tbb.dll",
":dbg_mode": "bin/tbb_debug.dll",
"//conditions:default": "bin/tbb.dll",
}),
)
[
(
cc_import(
name = module,
interface_library = select({
":fastbuild_mode": "lib/opencv_{}430.lib".format(module),
":dbg_mode": "lib/opencv_{}430d.lib".format(module),
"//conditions:default": "lib/opencv_{}430.lib".format(module),
}),
shared_library = select({
":fastbuild_mode": "bin/opencv_{}430.dll".format(module),
":dbg_mode": "bin/opencv_{}430d.dll".format(module),
"//conditions:default": "bin/opencv_{}430.dll".format(module),
}),
)
)
for module in MAIN_MODULES
]
cc_library(
name = "opencv",
hdrs = [
"include/opencv2/calib3d.hpp",
"include/opencv2/calib3d/calib3d.hpp",
"include/opencv2/calib3d/calib3d_c.h",
"include/opencv2/core.hpp",
"include/opencv2/core/hal/interface.h",
"include/opencv2/cvconfig.h",
"include/opencv2/dnn.hpp",
"include/opencv2/features2d.hpp",
"include/opencv2/flann.hpp",
"include/opencv2/flann/config.h",
"include/opencv2/flann/defines.h",
"include/opencv2/flann/miniflann.hpp",
"include/opencv2/highgui.hpp",
"include/opencv2/highgui/highgui.hpp",
"include/opencv2/highgui/highgui_c.h",
"include/opencv2/imgcodecs.hpp",
"include/opencv2/imgproc.hpp",
"include/opencv2/ml.hpp",
"include/opencv2/ml/ml.inl.hpp",
"include/opencv2/objdetect.hpp",
"include/opencv2/opencv.hpp",
"include/opencv2/opencv_modules.hpp",
"include/opencv2/photo.hpp",
"include/opencv2/stitching.hpp",
"include/opencv2/video.hpp",
"include/opencv2/video/background_segm.hpp",
"include/opencv2/video/tracking.hpp",
"include/opencv2/videoio.hpp",
"include/opencv2/videoio/videoio_c.h",
],
includes = ["include"],
deps = MAIN_MODULES + [
"tbb",
],
)
If you change the download URL to opencv-4.5.3-ios-framework.zip it might work
Error:
LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
I am trying to depend on libsodium: https://download.libsodium.org/libsodium/releases/libsodium-1.0.17-stable-msvc.zip
Using the following Bazel configuration:
# WORKSPACE
new_local_repository(
name = "org_libsodium_sodium",
build_file = "third_party/sodium.BUILD",
path = "third_party/sodium",
)
# sodium.BUILD
config_setting(
name = "windows_dbg_build",
constraint_values = ["#bazel_tools//platforms:windows"],
values = {"compilation_mode": "dbg"},
)
config_setting(
name = "windows_fastbuild_build",
constraint_values = ["#bazel_tools//platforms:windows"],
values = {"compilation_mode": "fastbuild"},
)
config_setting(
name = "windows_opt_build",
constraint_values = ["#bazel_tools//platforms:windows"],
values = {"compilation_mode": "opt"},
)
cc_library(
name = "sodium",
srcs = select({
":windows_dbg_build": ["lib/dbg/libsodium.lib"],
":windows_fastbuild_build": ["lib/dbg/libsodium.lib"],
":windows_opt_build": ["lib/opt/libsodium.lib"],
"//conditions:default": ["lib/opt/libsodium.a"],
}),
hdrs = glob(["sodium/**/*.h"]),
defines = ["SODIUM_STATIC"],
visibility = ["//visibility:public"],
)
Is it correct to use the /MT and /MTd Runtime Library for Windows precompiled static libraries?
Any idea what I am doing wrong?
Kind regards,
Ryan
I am newbiew to Bazel, I am trying to use thrift 10 in my bazel build and I need to run thrift binary to generate the thrift files. But I have conflicting version of thrift in my linux box, and somehow build is using wrong version while building.
Can someone help me how to solve this problem? Remember I have thrift.bzl which generates the thrift generated files..
Here is the current third party definition
cc_library(
name = "thrift",
srcs = [
"lib/libthrift.a",
"lib/libthrift.so",
"lib/libthrift.so.0.10.0",
"lib/libthriftc.a",
"lib/libthriftc.so",
"lib/libthriftc.so.0.10.0",
"lib/libthriftz.a",
],
hdrs = glob(["include/**/*.h"]),
includes = ["include"],
linkshared = 0,
tags = make_symlink_tags([
"lib/libthrift.a",
"lib/libthriftc.a",
"lib/libthriftz.a",
"lib/libthrift.so",
"lib/libthriftc.so",
"lib/libthrift.so.0.10.0",
"lib/libthriftc.so.0.10.0",
"lib/libthriftz.so.0.10.0",
]),
visibility = ["//visibility:public"],
deps = ["#boost_repo//:boost"],
)
filegroup(
name = "thrift_gen",
srcs = ["#thrift_repo//:bin/thrift"],
visibility = ["//visibility:public"],
)
thrift.bzl
_generate_thrift_cc_lib = rule(
attrs = {
"src": attr.label(
allow_files = True, # FileType(["*.thrift"]),
single_file = True,
),
"thrifts": attr.label_list(
allow_files = True, # FileType(["*.thrift"]),
),
"base_name": attr.string(),
"service_name": attr.string(),
"service": attr.bool(),
"gen": attr.string(default = "cpp"),
"_thrift": attr.label(
default = Label("#thrift_repo//:thrift_gen"),
executable = True,
cfg = "host",
),
},
output_to_genfiles = True,
outputs = _genthrift_outputs,
implementation = _generate_thrift_lib,
)
And here is the error
INFO: Found 11 targets...
ERROR: ...source/mlp/storage/services/thrift/BUILD:10:1: Generating mlp/storage/services/thrift/umm_geometry_constants.cpp failed (Exit 127).
external/thrift_repo/bin/thrift: error while loading shared libraries: libthriftc.so.0.10.0: cannot open shared object file: No such file or directory