Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to depend on "@org_golang_google_grpc//:go_default_library" #293

Closed
bbarnes52-zz opened this issue Aug 15, 2018 · 5 comments
Closed

Comments

@bbarnes52-zz
Copy link

bbarnes52-zz commented Aug 15, 2018

In my understanding google.golang.org/grpc and golang.org/x/sys are provided by default when calling go_rules_dependencies()

ERROR:

/private/var/tmp/_bazel_brian/773e68ba09138a3e0d933a215b2b78a9/external/org_golang_google_grpc/internal/channelz/BUILD.bazel:3:1: GoCompile external/org_golang_google_grpc/internal/channelz/linux_amd64_pure_stripped/go_default_library%/google.golang.org/grpc/internal/channelz.a failed (Exit 1)
GoCompile: missing strict dependencies:
        /private/var/tmp/_bazel_brian/773e68ba09138a3e0d933a215b2b78a9/sandbox/darwin-sandbox/1/execroot/__main__/external/org_golang_google_grpc/internal/channelz/types_linux.go: import of "golang.org/x/sys/unix"
Known dependencies are:
        google.golang.org/grpc/connectivity
        google.golang.org/grpc/credentials
        google.golang.org/grpc/grpclog
Check that imports in Go sources match importpath attributes in deps.
Target //roboflow/server:server failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.846s, Critical Path: 0.47s
INFO: 4 processes: 4 darwin-sandbox.

WORKSPACE:

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()

http_archive(
        name = "bazel_gazelle",
        urls = ["https://github.com/bazelbuild/bazel-gazelle/releases/download/0.14.0/bazel-gazelle-0.14.0.tar.gz"],
        sha256 = "c0a5739d12c6d05b6c1ad56f2200cb0b57c5a70e03ebd2f7b87ce88cabf09c7b",
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
gazelle_dependencies()

load("@bazel_gazelle//:deps.bzl", "go_repository")

go_repository(
        name = "org_golang_x_crypto",
        commit = "de0752318171da717af4ce24d0a2e8626afaeb11",
        importpath = "golang.org/x/crypto",
)

BUILD:

go_image(
        name = "server",
        srcs = [ 
                "main.go",
        ],  
        deps = [ 
                "//roboflow/server/proto:go_proto_lib",
                "@org_golang_google_grpc//:go_default_library",
                "@org_golang_x_crypto//bcrypt:go_default_library",
        ],  
        goarch = "amd64",
        goos = "linux",
        pure = "on",
        visibility = ["//visibility:public"],
)
@jayconrod
Copy link
Contributor

Here's the go_library rule that's failing:

go_library(
    name = "go_default_library",
    srcs = [
        "funcs.go",
        "types.go",
        "types_linux.go",
        "types_nonlinux.go",
        "util_linux_go19.go",
        "util_nonlinux_pre_go19.go",
    ],
    importpath = "google.golang.org/grpc/internal/channelz",
    visibility = ["//:__subpackages__"],
    deps = [
        "//connectivity:go_default_library",
        "//credentials:go_default_library",
        "//grpclog:go_default_library",
    ] + select({
        "@io_bazel_rules_go//go/platform:linux": [
            "@org_golang_x_sys//unix:go_default_library",
        ],
        "//conditions:default": [],
    }),
)

You're seeing this issue because the default target OS is not linux, so when Bazel evaluates that select expression as it builds the configured target graph, it gets an empty list of dependencies. If we don't include that select expression, the build will likely fail on non-Unix platforms, even if the dependency isn't needed.

Unfortunately, right now it's not possible to set the default target platform by setting goos and goarch; these only affect the target and dependencies after the configured target graph is constructed; they cannot influence how the configured target graph is built.

You may be able to work around this by providing --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 on the command line or in a bazelrc file. That will set the default target platform.

Bazel developers are working on explicit configuration transitions. I'd encourage you to follow the Bazel Configurability roadmap. We'd need most of the work in Platforms and User-defined configuration to be done before we can support this. It looks like that probably won't be ready until the end of 2018.

@seh
Copy link
Contributor

seh commented Dec 19, 2019

I know this issue has been closed a while ago, but today I'm wondering if it should be possible to build a program for macOS using this google.golang.org/grpc module.

In the internal/channelz package, file types_linux.go has a build tag that says "anything but appengine." The file name suffix suggests that that file should only be used for Linux. Looking at the BUILD.bazel file that Gazelle generated, though, it looks like that file is included regardless of the governing platform.

load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "go_default_library",
    srcs = [
        "funcs.go",
        "types.go",
        "types_linux.go",
        "types_nonlinux.go",
        "util_linux.go",
        "util_nonlinux.go",
    ],
    importpath = "google.golang.org/grpc/internal/channelz",
    visibility = ["//:__subpackages__"],
    deps = [
        "//connectivity:go_default_library",
        "//credentials:go_default_library",
        "//grpclog:go_default_library",
    ] + select({
        "@io_bazel_rules_go//go/platform:android": [
            "@org_golang_x_sys//unix:go_default_library",
        ],
        "@io_bazel_rules_go//go/platform:linux": [
            "@org_golang_x_sys//unix:go_default_library",
        ],
        "//conditions:default": [],
    }),
)

go_test(
    name = "go_default_test",
    srcs = ["util_test.go"],
    embed = [":go_default_library"],
    deps = select({
        "@io_bazel_rules_go//go/platform:android": [
            "@org_golang_x_sys//unix:go_default_library",
        ],
        "@io_bazel_rules_go//go/platform:linux": [
            "@org_golang_x_sys//unix:go_default_library",
        ],
        "//conditions:default": [],
    }),
)

I bring this up because I'm able to build my program on macOS for Linux just fine, but I'd like to be able to execute unit tests on macOS, and that requires compiling a test program for macOS.

@jayconrod, is this problem due to this gRPC module, or maybe Gazelle, or am I doing it all wrong? Please advise.

@seh
Copy link
Contributor

seh commented Dec 19, 2019

It looks like bazel-contrib/rules_go#2009 was an earlier fix for this, but that file seems to have been deleted since (in bazel-contrib/rules_go#2126).

@jayconrod
Copy link
Contributor

@seh Source files are filtered during execution, so it's fine for Gazelle to generate srcs lists without platform-specific select expressions.

google.golang.org/grpc should build in general, but I don't know enough about your environment to answer more than that.

Feel free to open a new issue with enough information to reproduce the problem you're seeing.

@seh
Copy link
Contributor

seh commented Dec 20, 2019

@jayconrod, per your request, please see #684.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants