Unable to build bazel - Getting error running bazel with gin package - go

I'm trying to add the gin package in the BUILD file. When I build the file I get the following error
no such package '#com_github_gin_gonic_gin//go_default_library': The repository '#com_github_gin_gonic_gin' could not be resolved: Repository '#com_github_gin_gonic_gin' is not defined and referenced by
load("#io_bazel_rules_go//go:def.bzl", "go_library")
load("#bazel_gazelle//:def.bzl", "gazelle")
package(default_visibility = ["//visibility:public"])
go_library(
name = "",
srcs = [""],
importpath = "",
visibility = ["//visibility:public"],
deps = [
"#com_github_gin_gonic_gin//go_default_library",
"#io_k8s_client_go//kubernetes",
"#io_k8s_client_go//tools/clientcmd",
"#io_k8s_client_go//util/homedir",
],
)

In your workspace file try calling go_rules_dependencies() first and then load other dependencies with respect to gin packages.

Related

no such target '#maven//:io_lettuce_lettuce_core': target 'io_lettuce_lettuce_core' not declared in package

I am trying to write a very simple example in kotlin to interact with redis.
I want to use bazel to drive the build process.
Here is the WORKSOPACE file
workspace(
name = "com_ahwkong_kotlin",
managed_directories = {},
)
load("#bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
RULES_KOTLIN_VERSION = "legacy-1.4.0-rc3"
RULES_KOTLIN_SHA = "da0e6e1543fcc79e93d4d93c3333378f3bd5d29e82c1bc2518de0dbe048e6598"
http_archive(
name = "io_bazel_rules_kotlin",
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/%s/rules_kotlin_release.tgz" % RULES_KOTLIN_VERSION],
sha256 = RULES_KOTLIN_SHA,
)
load("#io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below
# maven
RULES_JVM_EXTERNAL_TAG = "2.8"
RULES_JVM_EXTERNAL_SHA = "79c9850690d7614ecdb72d68394f994fef7534b292c4867ce5e7dec0aa7bdfad"
http_archive(
name = "rules_jvm_external",
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("#rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
artifacts = [
"com.google.code.findbugs:jsr305:1.3.9",
"com.google.errorprone:error_prone_annotations:2.0.18",
"com.google.j2objc:j2objc-annotations:1.1",
],
repositories = [
"https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2",
],
)
This is my BUILD file
load("#io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_compiler_plugin", "kt_jvm_library", "kt_jvm_binary")
kt_compiler_plugin(
name = "open_for_testing_plugin",
id = "org.jetbrains.kotlin.allopen",
options = {
"annotation": "plugin.allopen.OpenForTesting",
},
deps = [
"#com_github_jetbrains_kotlin//:allopen-compiler-plugin",
],
)
kt_jvm_library(
name = "ex1_lib",
srcs = glob(["ex1*/src/**/*.kt"]),
deps = [
"#maven//:io_lettuce_lettuce_core",
]
)
java_binary(
name = "ex1",
main_class = "ex1.App",
srcs = glob(["ex1*/src/**/*.kt"]),
visibility = ["//visibility:public"],
runtime_deps = [":ex1_lib"],
)
This is my kotlin file
package ex1
import io.lettuce.core.RedisClient
import io.lettuce.core.RedisReactiveCommandsImpl
import io.lettuce.core.RedisURI
import io.lettuce.core.api.StatefulRedisConnection
import io.lettuce.core.api.reactive.RedisReactiveCommands
import java.time.Duration
class ConnectionFactory {
// https://kotlinlang.org/docs/tutorials/kotlin-for-py/objects-and-companion-objects.html
// If you need a function or a property to be tied to a class rather than to instances of it
// (similar to #staticmethod in Python), you can declare it inside a companion object:
companion object {
fun createConnection(port: Int = 6380, host: String = "127.0.0.1"): RedisClient =
RedisClient.create(RedisURI.builder()
.withTimeout(Duration.ofMinutes(1))
.withHost(host)
.withPort(port)
.build())
}
}
Without the maven dependency I will not be able to compile the above code.
Here is the error message:
$ bazel build ex1
ERROR: /Users/antkong/dev/canva/kongakong-experiments.3.diagrams/tech_talk/kotlin/BUILD:26:1: no such target '#maven//:io_lettuce_lettuce_core': target 'io_lettuce_lettuce_core' not declared in package '' defined by /private/var/tmp/_bazel_antkong/3496a0772a2021d0f0b3c230bf912ab1/external/maven/BUILD and referenced by '//:ex1_lib'
ERROR: Analysis of target '//:ex1' failed; build aborted: Analysis failed
If the issue is "no such target '#maven//:io_lettuce_lettuce_core', how can I define this target?
I need to add this rule to the WORKSPACE
maven_repositories = [
"https://repo.maven.apache.org/maven2/",
"https://s3.amazonaws.com/maven.canva-build.com/release/",
"https://github.com/getdyspatch/dyspatch-java-mvn/raw/master/releases/",
]
maven_install(
artifacts = [
"io.lettuce:lettuce-core:jar:5.3.4.RELEASE",
],
repositories = maven_repositories,
)

Bazel/Golang: rule 'go_embed_data' doesn't contain declared provider 'GoArchive'

I'm trying to create a Bazel rule for my project that just embeds a collection of files. The embed rule is as follows:
go_embed_data(
name = "my_files_go",
src = [
"embedded/src1", "embedded/src2"
],
package = "my_lib",
var = "myFiles",
)
Which I then add in my go_library rule:
go_library(
name = "library",
srcs = [
"library.go",
],
importpath = "github.com/nickfelker/golang-app",
deps = [
":my_files_go"
"//otherLib",
],
)
However when I try to build this, I end up getting an obscure error that I cannot find elsewhere.
Error: <target //library:my_files_go> (rule 'go_embed_data') doesn't contain declared provider 'GoArchive'
ERROR: Analysis of target '//:binary' failed; build aborted: Analysis of target '//library:library' failed
How am I supposed to get around this error?
The rule created for go_embed_data does not go as a dependency to the go_library rule. Instead, it should be considered one of the srcs, as so:
go_embed_data(
name = "my_files_go",
src = [
"embedded/src1", "embedded/src2"
],
package = "my_lib",
var = "myFiles",
)
go_library(
name = "library",
srcs = [
":my_files_go",
"library.go",
],
importpath = "github.com/nickfelker/golang-app",
deps = [
"//otherLib",
],
)

Why nogo config is not considered when using bazel coverage

Hello our golang project is using nogo for static code analysis. We also have a nogo-config.json file to exclude certain paths for some of the rules. I found that bazel build //... and bazel test //... all use the config(because they don't complain the shadow variable error configured in the nogo_config.json) however bazel coverage //... will report variable shadow error for code under foo/bar which means the bazel coverage didn't obey the nogo_config.json. Why? (I am using bazel 2.2.0, golang go1.13.6 darwin/amd64)
WORKSPACE file
go_register_toolchains(nogo = "#//:my_nogo")
BUILD.bazel file
load("#io_bazel_rules_go//go:def.bzl", "nogo")
nogo(
name = "my_nogo",
config = "nogo-config.json", # Exclude analysis of 3rd party libraries
visibility = ["//visibility:public"],
deps = [
"#org_golang_x_tools//go/analysis/passes/shadow:go_tool_library",
],
)
nogo_config.json
{
"shadow": {
"exclude_files": {
"external/*": "",
"foo/bar/*": "Some generated model files don't behave by these go rules"
}
},
}

Bazel googleapi gRPC cc_grpc_library output was not created

I am running into Bazel build issues when I try to build googleapis texttospeech_proto and speech_proto with gRPC service. In the root directory of my project, I receive the following error:
ERROR: <>/BUILD:42:1: output 'external/com_google_googleapis/google/cloud/texttospeech/v1/cloud_tts.grpc.pb.h' was not created
ERROR: <>/BUILD:42:1: output 'external/com_google_googleapis/google/cloud/texttospeech/v1/cloud_tts.grpc.pb.cc' was not created
ERROR: <>/BUILD:42:1: not all outputs were created or valid
My BUILD/WORKSPACE files are below:
BUILD
load("#com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
cc_proto_library(
name = "speech_cc_proto",
deps = [
"#com_google_googleapis//google/cloud/speech/v1p1beta1:speech_proto",
],
visibility = ["//visibility:public"],
)
cc_grpc_library(
name = "cloud_speech_grpc",
srcs = [
"#com_google_googleapis//google/cloud/speech/v1p1beta1:speech_proto",
],
deps = [
":speech_cc_proto",
],
grpc_only = 1,
use_external = 1,
visibility = ["//visibility:public"],
)
cc_proto_library(
name = "texttospeech_cc_proto",
deps = [
"#com_google_googleapis//google/cloud/texttospeech/v1:texttospeech_proto",
],
visibility = ["//visibility:public"],
)
cc_grpc_library(
name = "cloud_texttospeech_grpc",
srcs = [
"#com_google_googleapis//google/cloud/texttospeech/v1:texttospeech_proto",
],
deps = [
":texttospeech_cc_proto",
],
grpc_only = 1,
use_external = 1,
visibility = ["//visibility:public"],
)
WORKSPACE
git_repository(
name = "com_github_grpc_grpc",
remote = "https://github.com/grpc/grpc.git",
tag = "v1.27.0-pre1",
)
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()
load("#io_bazel_rules_python//python:pip.bzl", "pip_import", "pip_repositories")
pip_import(
name = "grpc_python_dependencies",
requirements = "#com_github_grpc_grpc//:requirements.bazel.txt",
)
load("#grpc_python_dependencies//:requirements.bzl", "pip_install")
pip_repositories()
pip_install()
git_repository(
name = "com_google_googleapis",
remote = "https://github.com/googleapis/googleapis.git",
commit = "3c39a1d6e23c1ef63c7fba4019c25e76c40dfe19",
)
load("#com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
switched_rules_by_language(
name = "com_google_googleapis_imports",
cc = True,
grpc = True,
)
If I move my BUILD file out of the root workspace (into a child workspace/folder), I receive a different error saying the cloud_speech.proto / cloud_tts.proto files are not within the child workspace.

Redefinition of module 'minizip' Error

I am trying to create a COACOAPOD Library that uses IOS-Pods-DFU-Library as one of the dependency. I am using COACOAPODS for my dependency management. I am releasing my library as a binary framework and customers will integrate it with their app using COACOAPODS from localhost server with our custom podspec file that will download our binary framework from locahost server and resolve other dependencies.
Before Integrating iOSDFULibrary its used to works fine in the Customer applications. But after specifying iOSDFULibrary I am getting the following error
CustomerTest/Pods/Zip/Zip/minizip/module.modulemap:1:8: error: redefinition of module 'minizip'
module minizip [system][extern_c] {
^
/Modules/xxxxxx/Pods/Zip/Zip/minizip/module.modulemap:1:8: note: previously defined here
module minizip [system][extern_c] {
^
:0: error: could not build Objective-C module 'Zip'
Am i missing something here? Any help will be appreciated.
Below are our sample podspec file and example how user includes our library.
Pod::Spec.new do |s|
s.name = "xxxxxx"
s.version = "1.0.0"
s.summary = "xxxxxx description ."
s.author = { "" => "" }
s.license = { :type => 'Apache-2.0', :file => 'LICENSE' }
s.ios.preserve_paths = 'xxxxxx.framework/*.bundle'
s.ios.deployment_target = "9.0"
s.source = {
:http => 'http://localhost:8000/xxxxxx.zip'
}
s.ios.vendored_frameworks = 'xxxxxx.framework'
s.dependency 'SSZipArchive', ' 2.1'
s.dependency 'XCGLogger', ' 6.0'
s.dependency "iOSDFULibrary", '4.1.1'
end
Customers will include our library by specifying above podsepec file path as below in their pod file
pod 'xxxxxx', :podspec => './xxxxxx.podspec'
I had the same problem with the minizip module when using the Zip Cocoapod. For me the module was also declared double in both the Pods project as well as the app project. What fixed it for me was this answer.

Resources