bazel build c++ project failed with *.h could not find - c++

my project A is relying on brpc:https://github.com/apache/incubator-brpc
projectA.WORKSPACE:
git_repository(
name = "brpc",
# remote = "https://github.com/apache/incubator-brpc.git",
remote = "git#github.com:apache/incubator-brpc.git",
commit = "c4de79975ea54684634d1e52d4691f96d134d34a",
shallow_since = "1671716289 +0800"
)
projectA.classB BUILD
load("#rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "client",
srcs = glob([
"*.cpp",
]),
hdrs = glob([
"*.h",
]),
deps = [ "#brpc//:brpc"
],
visibility = ["//visibility:public"],
)
thrid_party/brpc BUILD
load("#rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "brpc",
srcs = glob([
"src/brpc/*.cpp",
"src/bthread/*.cpp",
"src/brpc/*.h",
]),
deps = [
],
includes = [
".",
],
include_prefix = "brpc",
strip_include_prefix = "brpc",
visibility = ["//visibility:public"],
)
bazel build msg:
INFO: Invocation ID: 9aae1a04-1225-4f62-9780-d334df616f9a
WARNING: errors encountered while analyzing target '//client:client': it will not be built
INFO: Analysis succeeded for only 1 of 2 top-level targets
INFO: Analyzed 2 targets (19 packages loaded, 56 targets configured).
INFO: Found 1 target...
Target //third_party/brpc:brpc up-to-date (nothing to build)
ERROR: command succeeded, but not all targets were analyzed
INFO: Elapsed time: 0.262s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
FAILED: Build did NOT complete successfully
still can not find *.h in brpc
figure out which bazel config is wrong?

I assume the above issue because there might not be visibility of the header (.h) file to the sandbox and it gets fail. Try adding the files as mentioned here. Please reach if that did not resolve your issue.

Related

Bazel - gtkmm library - missing dependencies

I have created a Bazel project (C++) and have tried to include the gtkmm library in my project.
I get the below error, that header files are missing, e.g.:
Showing Recent Messages
../mediapipe/external/gtkmm/gtkmm/accelerator.cc:18:10: fatal error: 'glibmm/utility.h' file not found
#include <glibmm/utility.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
Error in child process '/usr/bin/xcrun'. 1
Aspect #tulsi//:tulsi/tulsi_aspects.bzl%tulsi_outputs_aspect of //mediapipe/examples/motionize/motionize:motionize up-to-date:
bazel-bin/mediapipe/examples/motionize/motionize/motionize.tulsiouts
/private/var/tmp/_bazel_{user}/5a416b3c18d355cbf1dfbcf0102ffc0b/external/gtkmm/BUILD.bazel:7:11: Compiling gtkmm/accelerator.cc failed: (Aborted): wrapped_clang_pp failed: error executing command
Elapsed time: 10.459s, Critical Path: 0.45s
12 processes: 12 internal.
<*> Running Bazel completed in 10826.492 ms
Build did NOT complete successfully
The includes in the library do not seem to find the header files in general, not just this one. I have tried different setups and also a local repository instead of http_archive and I still get this kind of errors
Note: I am using Tulsi to create the Bazel xcode project
I have added the following in my WORKSPACE file:
http_archive(
name = "gtkmm",
strip_prefix = "gtkmm-4.8.0/gtk",
urls = ["https://github.com/GNOME/gtkmm/archive/refs/tags/4.8.0.zip"],
build_file = "#//third_party:gtkmm.BUILD",
)
I also added the gtkmm.BUILD file which looks like this:
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # BSD license
exports_files(["LICENSE"])
cc_library(
name = "main",
srcs = glob(
["**/*.cc"],
),
hdrs = glob([
"*.h",
"gtkmm/**/object_p.h",
"**/*.hg",
"**/*.h",
"**/selectiondata_private.h"
]),
includes = glob([
"*.h",
"gtkmm/**/object_p.h",
"**/*.hg",
"**/*.h",
"**/selectiondata_private.h"
]),
copts = ["-Iexternal/gtkmm-4.8.0/gtk"],
linkopts = ["-pthread"],
visibility = ["//visibility:public"],
)
Finally my BUILD file:
cc_binary(
name="motionize",
srcs=["main.cpp"],
copts = [
"-Iexternal/gtkmm-4.8.0/gtk/gtkmm",
"-Iexternal/gtkmm-4.8.0/gtk/",
"-Iexternal/gtkmm-4.8.0/gtk/src",
"-Iexternal/gtkmm-4.8.0/gtk/gtkmm/private",
],
deps=[
"//mediapipe/framework:calculator_framework",
"//mediapipe/calculators/core:pass_through_calculator",
"//mediapipe/calculators/image:image_cropping_calculator",
"//mediapipe/calculators/image:scale_image_calculator",
"//mediapipe/framework/formats:image_frame",
"//mediapipe/framework/formats:image_frame_opencv",
"//mediapipe/framework/port:opencv_core",
"//mediapipe/framework/port:opencv_highgui",
"//mediapipe/framework/port:opencv_imgproc",
"//mediapipe/framework/port:opencv_imgcodecs",
"//mediapipe/framework/port:opencv_video",
"//mediapipe/framework/port:parse_text_proto",
"//mediapipe/framework/port:status",
"#gtkmm//:main",
],
)

Making a Bazel genrule that modifies an executable generated by cc_binary

Assuming I have a cc_binary() rule like this:
cc_binary(
name = "App",
srcs = [
"app.cpp",
],
)
This will produce App.exe somewhere in bazel-bin. I need to write a genrule that can read App.exe and produce another version of it. How can I do that?
Edit: this is my current attempt for a genrule, but it forces the recompilation of :hello_main with a different configuration and I end up getting errors like "error C2955: 'std::pair': use of class template requires template argument list"
genrule(
name = "tbds",
srcs = [
":data",
],
outs = ["tbds.exe"],
exec_tools = ["#libpackfiles//FilePacker"],
tools = [":hello_main"],
cmd = "cp $(location :hello_main) $(OUTS) && $(location #libpackfiles//FilePacker) $(OUTS) -files $(SRCS) -append",
executable = true,
)
cc_binary(
name = "hello_main",
srcs = ["hello_main.cc"],
deps = [
":hello",
],
)
genrule(
name = "foo",
outs = ["out.txt"],
cmd = "du -sh $(location :hello_main)` > $#",
tools = [":hello_main"],
visibility = ["//visibility:public"],
)
will create a out.txt file with an output of a du -sh command. You can add an another tool to a tools attribute to run some transforming script on your binary

meson doesn't link library

I'm tring to a fix a meson build not picking up on a link library. The meson.build file has
tz_dep = dependency(
'date',
default_options : [ 'use_system_tzdb=true' ],
fallback: [ 'date', 'tz_dep' ]
)
# ...
executable(
'waybar',
src_files,
dependencies: [
# ...
tz_dep
],
include_directories: [include_directories('include')],
install: true,
)
and it does find /usr/lib/x86_64-linux-gnu/cmake/date/dateConfig.cmake. The corresponding dateTargets-none.cmake is
#----------------------------------------------------------------
# Generated CMake target import file for configuration "None".
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Import target "date::date-tz" for configuration "None"
set_property(TARGET date::date-tz APPEND PROPERTY IMPORTED_CONFIGURATIONS NONE)
set_target_properties(date::date-tz PROPERTIES
IMPORTED_LOCATION_NONE "${_IMPORT_PREFIX}/lib/x86_64-linux-gnu/libdate-tz.so.2.4.1"
IMPORTED_SONAME_NONE "libdate-tz.so.2.4.1"
)
list(APPEND _IMPORT_CHECK_TARGETS date::date-tz )
list(APPEND _IMPORT_CHECK_FILES_FOR_date::date-tz "${_IMPORT_PREFIX}/lib/x86_64-linux-gnu/libdate-tz.so.2.4.1" )
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
However, meson does not link /usr/lib/x86_64-linux-gnu/libdate-tz.so.2.4.1.
I'm not sure if the problem is in meson or the cmake config. I can provide more details if required.
i am wrinting an ebuild (gentoo package) for waybar right now and had the same issue you are describing. The solution is in your meson.build file, it specified the date dependency incomplete.
This is the patch i apply, and then it works (i have no clue about meson and stuff, but this seems makes waybar compile):
diff --git a/meson.build b/meson.build
index 5d45a29..dd56c29 100644
--- a/meson.build
+++ b/meson.build
## -98,7 +98,7 ## gtk_layer_shell = dependency('gtk-layer-shell-0',
required: get_option('gtk-layer-shell'),
fallback : ['gtk-layer-shell', 'gtk_layer_shell_dep'])
systemd = dependency('systemd', required: get_option('systemd'))
-tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], fallback: [ 'date', 'tz_dep' ])
+tz_dep = dependency('date', default_options : [ 'use_system_tzdb=true' ], modules : [ 'date::date', 'date::date-tz' ], fallback: [ 'date', 'tz_dep' ])
prefix = get_option('prefix')
sysconfdir = get_option('sysconfdir')
Maybe that helps!
Best Regards, Jonas

How to add 3rd party C library to tensorflow?

I want to add a third-party C library to tensorflow so I can use it in one of the examples. There doesn't seem to be any examples to follow so any assistance would be appreciated.
Here's my work using event2 as the third-party C library.
I've created an 'ln -s' in tensorflow/third_party to provide the event2/ headers:
ls -al ~/code/tensorflow/third_party/event2
lrwxr-xr-x 1 XXXX staff 25 May 17 16:03 ~/code/tensorflow/third_party/event2 -> /usr/local/include/event2
/usr/local/include> ls event2
BUILD bufferevent_struct.h event_compat.h listener.h thread.h
buffer.h dns.h event_struct.h rpc.h util.h
buffer_compat.h dns_compat.h http.h rpc_compat.h visibility.h
bufferevent.h dns_struct.h http_compat.h rpc_struct.h
bufferevent_compat.h event-config.h http_struct.h tag.h
bufferevent_ssl.h event.h keyvalq_struct.h tag_compat.h
third_party/event2/BUILD:
licenses(["notice"])
cc_library(
name = "event2",
srcs = glob( [ "*.h" ] ),
visibility = [ "//visibility:public" ],
)
In tensorflow/examples/label_image/BUILD, I added the reference to libevent and my test files that use the events2 library:
cc_binary(
name = "label_image",
srcs = [
"main.cc",
"my_new_file_using_events.c",
"my_new_file_using_events.h",
],
linkopts = ["-lm", ],
copts = [ "-Ithird_party", ],
deps = [
"//tensorflow/cc:cc_ops",
"//tensorflow/core:framework_internal",
"//tensorflow/core:tensorflow",
"//third_party/event2:event2",
],
)
It compiles fine but when I run the binary I get the following errors:
dyld: lazy symbol binding failed: Symbol not found: _event_base_new
Referenced from: /Users/XXXX/code/tensorflow/bazel-bin/tensorflow/examples/label_image/label_image
Expected in: flat namespace
dyld: Symbol not found: _event_base_new
Referenced from: /Users/XXXX/code/tensorflow/bazel-bin/tensorflow/examples/label_image/label_image
Expected in: flat namespace
[1] 41395 trace trap bazel-bin/tensorflow/examples/label_image/label_image
The libevent.a, libevent.dylib and other libevent* libs are in /usr/local/lib. according to nm, event_base undefined.
nm -f label_image | grep event_base
U _event_base_dispatch
U _event_base_new
How do I resolve this linkage error? Thanks.
Aren't we missing event2 sources there? Also, I think you want to put .h into hdrs attribute.
cc_library(
name = "event2",
hdrs = glob( [ "*.h" ] ),
srcs = glob( [ "*.cpp" ] ),
visibility = [ "//visibility:public" ],
)
Does this help?

Bazel rules and filegroup inconsistency

I created a filegroup rule to have in one label all the .proto files of a library.
filegroup(
name = "protos_all_src",
srcs = glob(
["**/*.proto"],
exclude = [
"protobuf/worker.proto",
"protobuf/worker_service.proto",
"protobuf/master.proto",
"protobuf/master_service.proto",
],
)
)
tf_proto_library(
name = "protos_all",
srcs = ":protos_all_src",
),
...
)
but strangely with this format this other rule fails:
cc_library(
name = "lib_internal",
srcs = glob(
[
"lib/**/*.h",
"lib/**/*.cc",
"platform/*.h",
"platform/*.cc",
] + tf_additional_lib_srcs(),
exclude = [
"**/*test*",
"platform/**/cuda.h",
"platform/**/stream_executor.h",
],
),
hdrs = [
"lib/core/blocking_counter.h",
"lib/core/refcount.h",
"lib/gtl/edit_distance.h",
"lib/gtl/int_type.h",
"lib/gtl/iterator_range.h",
"lib/gtl/manual_constructor.h",
"lib/gtl/top_n.h",
"lib/io/iterator.h",
"lib/io/match.h",
"lib/jpeg/jpeg_handle.h",
"lib/png/png_io.h",
"lib/random/random.h",
"lib/random/random_distributions.h",
"lib/random/weighted_picker.h",
"lib/strings/ordered_code.h",
"lib/strings/proto_text_util.h",
"lib/strings/regexp.h",
"lib/strings/scanner.h",
"lib/wav/wav_io.h",
"platform/demangle.h",
"platform/denormal.h",
"platform/platform.h",
"platform/tensor_coding.h",
"platform/tracing.h",
],
copts = tf_copts(),
linkopts = ["-ldl"],
deps = [
":protos_all_cc",
"//tensorflow/core/platform/default/build_config:platformlib",
"//third_party/eigen3",
],
)
note the protos_all_cc rule as a dep.
if I revert back to
tf_proto_library(
name = "protos_all",
srcs = glob(
["**/*.proto"],
exclude = [
"protobuf/worker.proto",
"protobuf/worker_service.proto",
"protobuf/master.proto",
"protobuf/master_service.proto",
],
),
everything works fine.
I would expect that the first and the second format would be completely equal. What I am missing ?
EDIT:
The tf_proto_library is defined here:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/platform/default/build_config.bzl#L26
and the cc_proto_library is defined here:
https://github.com/google/protobuf/blob/master/protobuf.bzl#L109
bazel version:
Build label: 0.2.3-homebrew
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue May 17 15:07:52 2016 (1463497672)
Build timestamp: 1463497672
Build timestamp as int: 1463497672
Could you paste your actual code and the error message you're getting? It looks like there are several problems and I'm not sure which are copy-paste errors and which are code.
I'd guess the issue you're having is that you cannot list files (nor filegroups) as deps in a cc_library rule, and ":protos_all_cc" is a filegroup. deps must be other cc_libraries (it's "things this rule should link together"). But it's very hard to tell with out the error message nor definition of protos_all_cc.
The srcs attribute should be a list, so your definition of protos_all should be
tf_proto_library(
name = "protos_all",
srcs = [":protos_all_src"], # note the list here
...
)
Maybe this is just a typo in the question, and the real problem is something else?
I get weird Permission denied problems when I try your filegroup approach.