How can add tensorflow in bazel project? - xcode

My project structure
/PROJECT
WORKSPACE
BUILD
third_party
tensorflow <-- cloned repository
my_files
BUILD
In WORKSPACE file i added this
local_repository(
name = "tensorflow",
path = "third_party/tensorflow",
)
load("#tensorflow//tensorflow:workspace3.bzl", "workspace")
workspace()
load("#tensorflow//tensorflow:workspace2.bzl", "workspace")
workspace()
load("#tensorflow//tensorflow:workspace1.bzl", "workspace")
workspace()
load("#tensorflow//tensorflow:workspace0.bzl", "workspace")
workspace()
Initially, the following was already written in the file
#Tensorflow repo should always go after the other external dependencies.
# 2020-10-30
_TENSORFLOW_GIT_COMMIT = "84384703c0d8b502e33ff6fd7eefd219dca5ff8e"
_TENSORFLOW_SHA256= "23fb322fc15a20f7a7838d9a31f8b16f60700a494ea654311a0aa8621769df98"
http_archive(
name = "org_tensorflow",
urls = [
"https://github.com/tensorflow/tensorflow/archive/%s.tar.gz" % _TENSORFLOW_GIT_COMMIT,
],
patches = [
"#//third_party:org_tensorflow_compatibility_fixes.diff",
],
patch_args = [
"-p1",
],
strip_prefix = "tensorflow-%s" % _TENSORFLOW_GIT_COMMIT,
sha256 = _TENSORFLOW_SHA256,
)
load("#org_tensorflow//tensorflow:workspace.bzl", "tf_workspace")
tf_workspace(tf_repo_name = "org_tensorflow")
Than in my_files/BUILD i wrote following
objc_library(
deps = [
"#tensorflow//tensorflow/lite/objc:TensorFlowLite",
],
)
When building, I get the following error
ERROR: file '_middlemen/TensorFlowLiteCMetal-ObjcCppSemantics_build_arch_ios-arm64-min10.0-
applebin_ios-ios_arm64-dbg_with_suffix__non_objc_arc' is generated by these conflicting actions:
Label: #tensorflow//tensorflow/lite/delegates/gpu:metal_delegate,
#org_tensorflow//tensorflow/lite/delegates/gpu:metal_delegate
ERROR: com.google.devtools.build.lib.skyframe.ArtifactConflictFinder$ConflictException:
com.google.devtools.build.lib.actions.MutableActionGraph$ActionConflictException: for
_middlemen/TensorFlowLiteCMetal-ObjcCppSemantics_build_arch_ios-arm64-min10.0-applebin_ios-
ios_arm64-dbg_with_suffix__non_objc_arc, previous action: ObjcCppSemantics_build_arch_ios-
arm64-min10.0-applebin_ios-ios_arm64-dbg_with_suffix__non_objc_arc for #org_tensorflow//tensorflow/lite/delegates/gpu:metal_delegate, attempted action:
ObjcCppSemantics_build_arch_ios-arm64-min10.0-applebin_ios-ios_arm64-
dbg_with_suffix__non_objc_arc for #tensorflow//tensorflow/lite/delegates/gpu:metal_delegate
Maybe I somehow incorrectly add tensorlow, but I do not know how to fix it

This issue solved my problem:
https://github.com/tensorflow/tensorflow/issues/46144

Related

use well-known types with cc_proto_library and py_proto_library from protobuf.bzl

I'd like to use google protobuf (master branch) + bazel v4.2.1 to set up communication between C++ and python parts of my program. I've got the following WORKSPACE file:
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "com_google_protobuf",
strip_prefix = "protobuf-master",
urls = ["https://github.com/protocolbuffers/protobuf/archive/master.zip"],
)
load("#com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
and the BUILD file:
load("#com_google_protobuf//:protobuf.bzl", "cc_proto_library")
load("#com_google_protobuf//:protobuf.bzl", "py_proto_library")
cc_proto_library(
name = "container_cc_proto",
srcs = ["container.proto"],
visibility = ["//visibility:public"],
deps = ["#com_google_protobuf//:any_proto",],
)
py_proto_library(
name = "container_py_proto",
srcs = ["container.proto"],
visibility = ["//visibility:public"],
deps = ["#com_google_protobuf//:any_proto",],
)
The container.proto tries to include "google/protobuf/any.proto". On my command bazel build //:container_cc_proto I see the following error:
ERROR: /home/*user*/sandbox/bypass/BUILD:31:17: no such target '#com_google_protobuf//:any_proto_genproto': target 'any_proto_genproto' not declared in package '' defined by /home/*some path*/external/com_google_protobuf/BUILD and referenced by '//:container_cc_proto_genproto'
Could anyone please tell me how to include any.proto correctly, or any other known workarounds. Thanks!

Bazel build error with third party library - no such package

I'm using bazel 4.1.0 to build to project.
Current set up:
go.mod file
...
github.com/mwitkow/go-proto-validators v0.3.2 // indirect
...
WORKSPACE file
load("#bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
load("//:repositories.bzl", "go_repositories")
go_repositories()
in repositories.blz file
...
go_repository(
name = "com_github_mwitkow_go_proto_validators",
importpath = "github.com/mwitkow/go-proto-validators",
sum = "h1:qRlmpTzm2pstMKKzTdvwPCF5QfBNURSlAgN/R+qbKos=",
version = "v0.3.2",
)
....
in students/api.v1/api.proto file
import "google/api/annotations.proto";
import "github.com/mwitkow/go-proto-validators/validator.proto";
after running bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=repositories.bzl%go_repositories -prune=true and bazel run //:gazelle
it generate students/api.v1/BUILD.bazel file
proto_library(
name = "api_proto",
srcs = ["api.proto"],
visibility = ["//visibility:public"],
deps = [
"//github.com/mwitkow/go-proto-validators:validators_proto",
"#go_googleapis//google/api:annotations_proto",
],
)
go_proto_library(
name = "api_go_proto",
compilers = ["#io_bazel_rules_go//proto:go_grpc"],
importpath = "students/generated/api",
proto = ":api_proto",
visibility = ["//visibility:public"],
deps = [
"//github.com/mwitkow/go-proto-validators:validator_proto",
"#go_googleapis//google/api:annotations_go_proto",
],
)
When I run bazel build //..., it produces an error
ERROR: /my-app/students/api.v1/BUILD.bazel:15:17: no such package 'github.com/mwitkow/go-proto-validators': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
- /my-app/github.com/mwitkow/go-proto-validators and referenced by '/students/api.v1:api_go_proto'
ERROR: Analysis of target '//students/api.v1:api' failed; build aborted: Analysis failed
I would like to make the build work without error. Thank you very much for your help.
I think in BUILD.bazel file, //github.com/mwitkow/go-proto-validators:validators_proto should be #github.com/mwitkow/go-proto-validators:validators_proto, like #go_googleapis//google/api:annotations_proto but it's just a vague idea.

How to coexist 2 Imgui versions in bazel project?

I am a programmer in an auto-driving company. We use ImGui to draw HMI interface. ImGui's Docking branch is in BETA. We want to use the Docking branch in local testing, and released version branch in online.
We use bazel to build project. How to coexist 2 branches in our project and easy to switch? When compiling online version, type bazel build all. When compiling local testing version, type something like this bazel build all --use_imgui_docking_branch?
Can bazel achive this requirement?
I worked out.
Add imgui_docking in WORKSPACE
http_archive(
name = "imgui_docking",
build_file = "#//:third_party/imgui_docking.BUILD",
sha256 ="...",
strip_prefix = "...",
urls = [...],
)
Use select in cc_library
config_setting(
name = "imgui_docking",
values = {"define": "imgui=docking"},
)
cc_library(
name = "...",
srcs = [...],
hdrs = [...],
deps = [...]
+ select({
"imgui_docking" : [ "#imgui_docking" ],
"//conditions:default" : [ "#imgui" ]
}),
defines = select({
"imgui_docking" : [ "IMGUI_DOCKING" ],
"//conditions:default" : []
}),
)
Use macro control include in header
#ifdef IMGUI_DOCKING
#include "imgui_docking/imgui.h"
#include "imgui_docking/imgui_internal.h"
#else
#include "imgui/imgui.h"
#include "imgui/imgui_internal.h"
#endif
When compiling add --define
--define docking=imgui

'No such file or directory' error when using buildGoPackage in nix

I'm trying to build the hasura cli: https://github.com/hasura/graphql-engine/tree/master/cli with the following code (deps derived from dep2nix):
{ buildGoPackage, fetchFromGitHub }:
buildGoPackage rec {
version = "1.0.0-beta.2";
name = "hasura-${version}";
goPackagePath = "github.com/hasura/graphql-engine";
subPackages = [ "cli" ];
src = fetchFromGitHub {
owner = "hasura";
repo = "graphql-engine";
rev = "v${version}";
sha256 = "1b40s41idkp1nyb9ygxgsvrwv8rsll6dnwrifpn25bvnfk8idafr";
};
goDeps = ./deps.nix;
}
but I get the following errors after the post-installation fixup step:
find: '/nix/store/gkck68cm2z9k1qxgmh350pq3kwsbyn8q-hasura-cli-1.0.0-beta.2': No such file or directory.
What am I doing wrong here? For reference, I'm on macOS and using home-manager.
For anyone still wondering:
There are a couple of things to consider:
dep has been deprecated in favor of go modules
This is also reflected in Nix, as buildGoPackage is now legacy and moved to buildGoModule
There is already a hasura-cli package in nixpkgs. You can just use it with nix-shell -p hasura-cli

Bazel build is not working on from Maven project

I'm new to Bazel and learning its build work, currently I am trying to do with bazel build from a Maven project, please advise me how to make it working, thanks.
Here is the WORKSPACE file I am trying to define:
maven_jar(
name = "junit",
artifact = "junit:junit:3.8.1",
)
maven_jar(
name = "log4j1",
artifact = "org.apache.logging.log4j:log4j-core:2.6.2",
)
maven_jar(
name = "log4j2",
artifact = "org.apache.logging.log4j:log4j-api:2.6.2",
)
.....
Here is the BUILD file I am trying to define:
package(default_visibility = ["//visibility:public"])
java_binary(
name = "everything",
srcs = glob(["src/main/java/**/*.java"]),
resources = glob(["src/main/resources/**"]),
main_class = "src/main/java/com/test/test/test/App",
deps = [
"#junit//jar",
"#log4j1//jar",
"#log4j2//jar",
"#jackson//jar",
"#jsonsimple//jar",
"#commonsdbutils//jar",
"#commons//jar",
"#guava//jar",
"#poi//jar"],
)
Here is I got Bazel build results:
mbp:bazel_test me$ bazel build //:everything
INFO: Analysed target //:everything (1 packages loaded).
INFO: Found 1 target...
ERROR: /Users/me/git/test/test/BUILD:4:1: Building everything-class.jar (104 source files) failed (Exit 1)
src/main/java/com/test/test/test/Testapp.java:13: error: cannot find symbol
import org.apache.poi.ss.usermodel.Cell;
^
symbol: class Cell
location: program package org.apache.poi.ss.usermodel
.....
Target //:everything failed to build
I see two problems here:
The main_class attribute should use dots instead of slashes:
java_binary(
name = "everything",
srcs = glob(["src/main/java/**/*.java"]),
main_class = "src.main.java.com.test.test.test.App",
...
There's no org.apache.poi.ss.usermodel.Cell class in the poi jar.
Find the jar's name:
$ bazel query --output=build #poi//jar
...
java_import(
name = "jar",
visibility = ["//visibility:public"],
jars = ["#poi//jar:poi-ooxml-3.9.jar"],
srcjar = "#poi//jar:poi-ooxml-3.9-sources.jar",
)
The package's location is $(bazel info output_base)/external/poi, and now we know (from the srcs attribute in the bazel query output above) that the file is called poi-ooxml-3.9.jar:
$ unzip -l $(bazel info output_base)/external/poi/jar/poi-ooxml-3.9.jar | grep "org.apache.poi.ss.usermodel"
0 2012-11-26 17:14 org/apache/poi/ss/usermodel/
2970 2012-11-26 17:14 org/apache/poi/ss/usermodel/WorkbookFactory.class

Resources