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

cgo_library() cannot find source files when used with new_git_repository() #35

Closed
hochhaus opened this issue Jun 6, 2016 · 6 comments · Fixed by #36
Closed

cgo_library() cannot find source files when used with new_git_repository() #35

hochhaus opened this issue Jun 6, 2016 · 6 comments · Fixed by #36
Assignees
Labels

Comments

@hochhaus
Copy link
Contributor

hochhaus commented Jun 6, 2016

@yugui This is a followup to bb7e87b.

When using cgo_library() with new_git_repository() bazel is unable to find source files. For example, consider https://golang.org/x/sys/unix.

...

SYS_UNIX_BUILD = """
load("@io_bazel_rules_go//go:def.bzl", "go_prefix", "go_library", "cgo_library")
go_prefix("golang.org/x/sys/unix")
go_library(
    name = "go_default_library",
    srcs = glob([
        "unix/*_linux_amd64.s",
        "unix/*_linux.go",
        "unix/*_linux_amd64.go",
        "unix/*_unix.go",
        "unix/syscall.go",
        "unix/race0.go",
        "unix/str.go",
      ],
      exclude = ["unix/types_linux.go", "unix/gccgo_*"],
    ),
    deps = [
        ":types_linux",
    ],
    visibility = ["//visibility:public"],
)

cgo_library(
    name = "types_linux",
    srcs = ["unix/types_linux.go"],
)
"""
new_git_repository(
    name = "org_golang_x_sys_unix",
    remote = "https://go.googlesource.com/sys",
    commit = "076b546753157f758b316e59bcb51e6807c04057",
    build_file_content = SYS_UNIX_BUILD,
)

When building, I receive the following error:

ahochhaus@debian:~/ll$ b build ...
INFO: Found 51 targets...
ERROR: /home/ahochhaus/.cache/bazel/_bazel_ahochhaus/9b0316414c69160d24362f2991b802bb/external/org_golang_x_sys_unix/BUILD:23:1: error executing shell command: 'export GOROOT=$(pwd)/external/golang_linux_amd64/go/bin/.. && export CC=$(cd $(dirname /usr/bin/gcc); pwd)/$(basename /usr/bin/gcc) && export CXX=$CC && objdir=$(pwd)/bazel-out/local-fastbuild/genf...' failed: namespace-sandbox failed: error executing command /home/ahochhaus/.cache/bazel/_bazel_ahochhaus/9b0316414c69160d24362f2991b802bb/ll/_bin/namespace-sandbox ... (remaining 5 argument(s) skipped).
open unix/types_linux.go: no such file or directory
INFO: Elapsed time: 21.208s, Critical Path: 20.88s

Is cgo_library() expected to work with new_git_repository()?

@yugui yugui added the bug label Jun 8, 2016
@yugui yugui self-assigned this Jun 8, 2016
yugui added a commit that referenced this issue Jun 10, 2016
* The current package name might be empty.
* The current package might be in a non-root workspace. #35
* A cgo source file might be a generated file and it might be in
  $(GENDIR) or in $(BINDIR)
* cgo source files might be in a subdirectory of the bazel
  package directory.
@hochhaus
Copy link
Contributor Author

hochhaus commented Jun 10, 2016

@yugui Thanks. Your fix resolves my issue. Could this change be moved to the master branch?

@hochhaus
Copy link
Contributor Author

@yugui This fix works to allow use of files in a cgo_library() from new_git_repository() in bazel 0.2.3. However, with bazel 0.3.0, it fails with the file not found error. Can we reopen this issue for bazel 0.3.0?

@yugui
Copy link
Member

yugui commented Jun 29, 2016

@hochhaus
Sure. Sorry for your inconvenience.

@yugui yugui reopened this Jun 29, 2016
@hochhaus
Copy link
Contributor Author

No problem! Thanks for taking a look.

@yugui
Copy link
Member

yugui commented Jun 30, 2016

Note for investigation:

short_path of the file "@org_golang_x_sys//:unix/types_linux.go" used to be external/org_golang_x_sys/unix/types_linux.go but not it is ../org_golang_x_sys/unix/types_linux.go

I am wondering if this is an issue of Bazel because "/".join([f.root.path, f.short_path]) is different from f.path.

  • f.path: "external/org_golang_x_sys/unix/types_linux.go"
  • f.root.path: ""
  • f.short_path: "../org_golang_x_sys/unix/types_linux.go"

@yugui
Copy link
Member

yugui commented Jun 30, 2016

Looks to be a side-effect of the runfiles structure change in Bazel 0.3.0.

groodt pushed a commit to groodt/rules_go that referenced this issue Mar 14, 2022
* Array comprehensions

Implemented using flatMap.

The representation in AST was changed - now it expresses
the semantic structure better.

Ifs in comprehensions are not supported yet, but easy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants