Closed philsc closed 8 years ago
@kchodorow - Is this also due to load() currently taking local paths only, such as mentioned in #429?
You are hitting a bug where new_http_archive only looks in your workspace for the build_file
. Workaround: copy /usr/local/lib/bazel/base_workspace/tools/build_rules/rust/rust.BUILD
to /home/phil/repos/brt/tools/build_rules/rust/rust.BUILD
. You don't have to copy anything else into your tree, just the file used by build_file
.
I don't think there's actually an issue filed for this yet, so I'll use this one to track.
Thanks for the explanation, Kristina. I have updated the bug title and reassigned it to you.
How are people working around this issue? Even when I copy rules out of the bazel repo and into my tools/build_rules directory I still get the following error:
➜ golang blaze run //grpc-gateway:main
ERROR: /tmp/golang/tools/build_rules/go/toolchain/BUILD:15:1: no such package '@golang-darwin-amd64//': In new_http_archive rule //external:golang-darwin-amd64 the 'build_file' attribute does not specify an existing file (/tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain does not exist) and referenced by '//tools/build_rules/go/toolchain:toolchain'.
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 0.961s
ERROR: Build failed. Not running target.
➜ golang cat /tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain
package(
default_visibility = [ "//visibility:public" ])
filegroup(
name = "toolchain",
srcs = glob(["go/bin/*", "go/pkg/**", ]),
)
filegroup(
name = "go_tool",
srcs = [ "go/bin/go" ],
)
We've been running with the patch that Brian posted to revert to the original behavior. I'm sooo looking forwards to the new label based behavior.
@achew22: Did you copy just the *.bzl
files or the whole tools/build_rules
directory? Did you try a bazel shutdown
(Bazel caches things related to external repositories pretty aggressively)?
I'm pretty sure @AustinSchuh is referring to the workaround for #429, which is related but different. This bug is about the buildfile referred to by a `new*rule having to come from the main workspace, while #429 is about
load` statements in those files bringing in Skylark code.
Here is a complete reproduction of my process. Starting in $HOME/Projects/
. My ZSH is configured to show the arrow (colored with the last status code) then the name of the folder then the command. So, ➜ Projects echo
means I'm in a folder called "Projects" and I'm running the command echo
I created a github repo of the folders so if you're not interested in reading scrollback on this, check that out: https://github.com/achew22/bazelgolang
➜ Projects git clone https://github.com/bazelbuild/bazel
Cloning into 'bazel'...
remote: Counting objects: 57063, done.
remote: Compressing objects: 100% (94/94), done.
remote: Total 57063 (delta 31), reused 0 (delta 0), pack-reused 56951
Receiving objects: 100% (57063/57063), 89.65 MiB | 8.85 MiB/s, done.
Resolving deltas: 100% (35878/35878), done.
Checking connectivity... done.
➜ Projects cd bazel
➜ bazel git:(master) git log HEAD^..HEAD | cat -
commit 420804811ddb7798a02c5eb9fd2be1c253799f9d
Author: Michajlo Matijkiw <michajlo@google.com>
Date: Fri Nov 20 20:37:05 2015 +0000
Extract Attribute serialization logic
--
MOS_MIGRATED_REVID=108368348
➜ bazel git:(master) ./compile.sh
INFO: You can skip this first step by providing a path to the bazel binary as second argument:
INFO: ./compile.sh build /path/to/bazel
🍃 Building Bazel from scratch............
🍃 Building Bazel with Bazel.
.Extracting Bazel installation...
...........
INFO: Found 1 target...
Target //src:bazel up-to-date:
bazel-bin/src/bazel
INFO: Elapsed time: 43.075s, Critical Path: 35.55s
🍃 Setting up base workspace.
INFO: You already have a .bazelrc. Make sure it contains the following package paths:
build --package_path %workspace%:/home/achew22/Projects/bazel/base_workspace
fetch --package_path %workspace%:/home/achew22/Projects/bazel/base_workspace
query --package_path %workspace%:/home/achew22/Projects/bazel/base_workspace
Build successful! Binary is here: /home/achew22/Projects/bazel/output/bazel
➜ bazel git:(master) mkdir /tmp/golang
➜ bazel git:(master) cp tools/build_rules/go/toolchain/WORKSPACE.go-toolchain /tmp/golang/WORKSPACE
➜ bazel git:(master) cat - <<EOF > /tmp/golang/BUILD
heredoc> load("/tools/build_rules/go/def", "go_prefix")
heredoc>
heredoc> go_prefix("github.com/joe/project")
heredoc> EOF
➜ bazel git:(master) mkdir /tmp/golang/lib
➜ bazel git:(master) cat - <<EOF > /tmp/golang/lib/BUILD
heredoc> load("/tools/build_rules/go/def", "go_library")
heredoc>
heredoc> go_library(
heredoc> name = "go_default_library",
heredoc> srcs = ["file.go"]
heredoc> )
heredoc> EOF
➜ bazel git:(master) cat - <<EOF > /tmp/golang/lib/file.go
heredoc> package lib
heredoc>
heredoc> func SayHello() string {
heredoc> return "Hello"
heredoc> }
heredoc> EOF
➜ bazel git:(master) mkdir /tmp/golang/src
➜ bazel git:(master) cat - <<EOF > /tmp/golang/src/BUILD
heredoc> load("/tools/build_rules/go/def", "go_binary")
heredoc>
heredoc> go_binary(
heredoc> name = "test",
heredoc> srcs = ["main.go"],
heredoc> deps = ["//lib:go_default_library"],
heredoc> )
heredoc> EOF
➜ bazel git:(master) cat - <<EOF > /tmp/golang/src/main.go
heredoc> package main
heredoc>
heredoc> import "fmt"
heredoc> import "github.com/joe/project/lib"
heredoc>
heredoc> func main() {
heredoc> fmt.Println(lib.SayHello())
heredoc> }
heredoc> EOF
Now I will try building without the tools directory copied in
➜ golang $HOME/Projects/bazel/output/bazel build //src:test
Extracting Bazel installation...
........
ERROR: /home/achew22/tools/bazel/base_workspace/tools/build_rules/go/toolchain/BUILD:24:1: no such package '@golang-linux-amd64//': In new_http_archive rule //external:golang-linux-amd64 the 'build_file' attribute does not specify an existing file (/tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain does not exist) and referenced by '//tools/build_rules/go/toolchain:go_tool'.
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 13.168s
Now just copy the whole tools directory in to see what happens
➜ golang cp -r $HOME/Projects/bazel/tools .
➜ golang cat /tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain
package(
default_visibility = [ "//visibility:public" ])
filegroup(
name = "toolchain",
srcs = glob(["go/bin/*", "go/pkg/**", ]),
)
filegroup(
name = "go_tool",
srcs = [ "go/bin/go" ],
)
➜ golang $HOME/Projects/bazel/output/bazel build //src:test
ERROR: /tmp/golang/tools/build_rules/go/toolchain/BUILD:15:1: no such package '@golang-linux-amd64//': In new_http_archive rule //external:golang-linux-amd64 the 'build_file' attribute does not specify an existing file (/tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain does not exist) and referenced by '//tools/build_rules/go/toolchain:toolchain'.
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 1.056s
➜ golang cat /tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain
package(
default_visibility = [ "//visibility:public" ])
filegroup(
name = "toolchain",
srcs = glob(["go/bin/*", "go/pkg/**", ]),
)
filegroup(
name = "go_tool",
srcs = [ "go/bin/go" ],
)
Okay, that didn't work. Let's try removing tools and just bringing in the build_rules directory
➜ golang rm -rf tools
➜ golang ls tools
ls: cannot access tools: No such file or directory
➜ golang mkdir tools
➜ golang cp -r $HOME/Projects/bazel/tools/build_rules tools/
➜ golang cat /tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain
package(
default_visibility = [ "//visibility:public" ])
filegroup(
name = "toolchain",
srcs = glob(["go/bin/*", "go/pkg/**", ]),
)
filegroup(
name = "go_tool",
srcs = [ "go/bin/go" ],
)
➜ golang ls tools
build_rules
➜ golang $HOME/Projects/bazel/output/bazel build //src:test
ERROR: /tmp/golang/tools/build_rules/go/toolchain/BUILD:15:1: no such package '@golang-linux-amd64//': In new_http_archive rule //external:golang-linux-amd64 the 'build_file' attribute does not specify an existing file (/tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain does not exist) and referenced by '//tools/build_rules/go/toolchain:toolchain'.
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 0.935s
Okay, let's try just copying in the golang specific rules
➜ golang rm -rf tools
➜ golang mkdir -p tools/build_rules
➜ golang cp -r $HOME/Projects/bazel/tools/build_rules/go tools/build_rules/
➜ golang ls tools/build_rules/go
BUILD def.bzl README.md toolchain tools
➜ golang cat /tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain
package(
default_visibility = [ "//visibility:public" ])
filegroup(
name = "toolchain",
srcs = glob(["go/bin/*", "go/pkg/**", ]),
)
filegroup(
name = "go_tool",
srcs = [ "go/bin/go" ],
)
➜ golang $HOME/Projects/bazel/output/bazel build //src:test
ERROR: /tmp/golang/tools/build_rules/go/toolchain/BUILD:24:1: no such package '@golang-linux-amd64//': In new_http_archive rule //external:golang-linux-amd64 the 'build_file' attribute does not specify an existing file (/tmp/golang/tools/build_rules/go/toolchain/BUILD.go-toolchain does not exist) and referenced by '//tools/build_rules/go/toolchain:go_tool'.
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 0.899s
Push it to github so you can see the state
➜ golang git init
Initialized empty Git repository in /tmp/golang/.git/
➜ golang git:(master) ✗ git add .
➜ golang git:(master) ✗ git commit -m "Test go repo"
[master (root-commit) a1f3936] Test go repo
14 files changed, 866 insertions(+)
create mode 100644 BUILD
create mode 100644 WORKSPACE
create mode 100644 lib/BUILD
create mode 100644 lib/file.go
create mode 100644 src/BUILD
create mode 100644 src/main.go
create mode 100644 tools/build_rules/go/BUILD
create mode 100644 tools/build_rules/go/README.md
create mode 100644 tools/build_rules/go/def.bzl
create mode 100644 tools/build_rules/go/toolchain/BUILD
create mode 100644 tools/build_rules/go/toolchain/BUILD.go-toolchain
create mode 100644 tools/build_rules/go/toolchain/WORKSPACE.go-toolchain
create mode 100644 tools/build_rules/go/tools/BUILD
create mode 100644 tools/build_rules/go/tools/generate_test_main.go
➜ golang git:(master) git push --force git@github.com:achew22/bazelgolang.git master
Counting objects: 22, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (22/22), 8.08 KiB | 0 bytes/s, done.
Total 22 (delta 1), reused 0 (delta 0)
To git@github.com:achew22/bazelgolang.git
* [new branch] master -> master
I'm sort of at a loss for what to do from here. Could it be related to sandboxing or something? How can I help debug this?
And after all the pain of making that repo I just saw your comment on running bazel shutdown
. Let me try that before anyone goes and tries to repro.
Wow... that's some aggressive caching. bazel shutdown
did the trick for me. Sorry for the trouble.
➜ golang git:(master) $HOME/Projects/bazel/output/bazel shutdown
➜ golang git:(master) $HOME/Projects/bazel/output/bazel run //src:test
.......
ERROR: /tmp/golang/src/BUILD:3:1: Target '//lib:go_default_library' is not visible from target '//src:test'. Check the visibility declaration of the former target if you think the dependency is legitimate.
ERROR: Analysis of target '//src:test' failed; build aborted.
INFO: Elapsed time: 17.756s
ERROR: Build failed. Not running target.
➜ golang git:(master) vim lib/BUILD
➜ golang git:(master) ✗ cat lib/BUILD
package(default_visibility=["//visibility:public"])
load("/tools/build_rules/go/def", "go_library")
go_library(
name = "go_default_library",
srcs = ["file.go"]
)
➜ golang git:(master) ✗ $HOME/Projects/bazel/output/bazel run //src:test
INFO: Found 1 target...
Target //src:test up-to-date:
bazel-bin/src/test.a
bazel-bin/src/test
INFO: Elapsed time: 4.445s, Critical Path: 0.04s
INFO: Running command line: bazel-bin/src/test
Hello
Sweet! Now to get playing with golang. A sample golang repo is now up on my github at https://github.com/achew22/bazelgolang.
➜ golang git:(master) ✗ git commit -m "Fix visibility"
[master bec07e0] Fix visibility
166 files changed, 18756 insertions(+)
create mode 120000 bazel-bin
create mode 120000 bazel-genfiles
create mode 120000 bazel-golang
create mode 120000 bazel-out
create mode 120000 bazel-testlogs
create mode 100644 tools/BUILD
create mode 100644 tools/android/BUILD
create mode 100755 tools/android/aar_generator.sh
create mode 100644 tools/android/android_permissions.py
create mode 100644 tools/android/bazel_debug.keystore
create mode 100644 tools/android/build_incremental_dexmanifest.py
create mode 100644 tools/android/build_split_manifest.py
create mode 100644 tools/android/build_split_manifest_test.py
create mode 100755 tools/android/idlclass.sh
create mode 100644 tools/android/incremental_install.py
create mode 100644 tools/android/incremental_install_test.py
create mode 100644 tools/android/jack/BUILD
create mode 100644 tools/android/jack/empty
create mode 100755 tools/android/jack/fail.sh
create mode 100755 tools/android/merge_dexzips.sh
create mode 100644 tools/android/merge_manifests.py
create mode 100644 tools/android/merge_manifests_test.py
create mode 100755 tools/android/resources_processor.sh
create mode 100755 tools/android/shuffle_jars.sh
create mode 100644 tools/android/strip_resources.py
create mode 100644 tools/android/stubify_manifest.py
create mode 100644 tools/android/stubify_manifest_test.py
create mode 100644 tools/bazel.rc
create mode 100644 tools/build_defs/d/BUILD
create mode 100644 tools/build_defs/d/README.md
create mode 100644 tools/build_defs/d/d.WORKSPACE
create mode 100644 tools/build_defs/d/d.bzl
create mode 100644 tools/build_defs/d/dmd.BUILD
create mode 100644 tools/build_defs/docker/BUILD
create mode 100644 tools/build_defs/docker/README.md
create mode 100755 tools/build_defs/docker/build_test.sh
create mode 100644 tools/build_defs/docker/create_image.py
create mode 100644 tools/build_defs/docker/docker.bzl
create mode 100644 tools/build_defs/docker/incremental_load.sh.tpl
create mode 100644 tools/build_defs/docker/join_layers.py
create mode 100644 tools/build_defs/docker/rewrite_json.py
create mode 100644 tools/build_defs/docker/rewrite_json_test.py
create mode 100644 tools/build_defs/docker/sha256.py
create mode 100644 tools/build_defs/docker/testdata/BUILD
create mode 100644 tools/build_defs/docker/testdata/bar
create mode 100644 tools/build_defs/docker/testdata/extras_gen.py
create mode 100644 tools/build_defs/docker/testdata/foo
create mode 100644 tools/build_defs/docker/testdata/gen_deb.py
create mode 100644 tools/build_defs/docker/testdata/one.tar
create mode 100644 tools/build_defs/docker/testdata/strip_top.py
create mode 100644 tools/build_defs/docker/testdata/test/BUILD
create mode 100644 tools/build_defs/docker/testdata/test/test
create mode 100644 tools/build_defs/docker/testdata/two.tar
create mode 100644 tools/build_defs/docker/testenv.py
create mode 100755 tools/build_defs/docker/testenv.sh
create mode 100644 tools/build_defs/dotnet/BUILD
create mode 100644 tools/build_defs/dotnet/README.md
create mode 100644 tools/build_defs/dotnet/csharp.bzl
create mode 100644 tools/build_defs/dotnet/dotnet.WORKSPACE
create mode 100644 tools/build_defs/dotnet/nunit.BUILD
create mode 100644 tools/build_defs/groovy/README.md
create mode 100644 tools/build_defs/groovy/groovy.BUILD
create mode 100644 tools/build_defs/groovy/groovy.WORKSPACE
create mode 100644 tools/build_defs/groovy/groovy.bzl
create mode 100644 tools/build_defs/jsonnet/BUILD
create mode 100644 tools/build_defs/jsonnet/README.md
create mode 100644 tools/build_defs/jsonnet/jsonnet.WORKSPACE
create mode 100644 tools/build_defs/jsonnet/jsonnet.bzl
create mode 100644 tools/build_defs/pkg/BUILD
create mode 100644 tools/build_defs/pkg/README.md
create mode 100644 tools/build_defs/pkg/archive.py
create mode 100644 tools/build_defs/pkg/archive_test.py
create mode 100644 tools/build_defs/pkg/build_tar.py
create mode 100755 tools/build_defs/pkg/build_test.sh
create mode 100644 tools/build_defs/pkg/make_deb.py
create mode 100644 tools/build_defs/pkg/pkg.bzl
create mode 100644 tools/build_defs/pkg/testdata/a.ar
create mode 100644 tools/build_defs/pkg/testdata/a_ab.ar
create mode 100644 tools/build_defs/pkg/testdata/a_b.ar
create mode 100644 tools/build_defs/pkg/testdata/a_b_ab.ar
create mode 100644 tools/build_defs/pkg/testdata/ab.ar
create mode 100644 tools/build_defs/pkg/testdata/b.ar
create mode 100644 tools/build_defs/pkg/testdata/empty.ar
create mode 100644 tools/build_defs/pkg/testdata/tar_test.tar
create mode 100644 tools/build_defs/pkg/testdata/tar_test.tar.bz2
create mode 100644 tools/build_defs/pkg/testdata/tar_test.tar.gz
create mode 100644 tools/build_defs/pkg/testdata/tar_test.tar.xz
create mode 100644 tools/build_defs/pkg/testenv.py
create mode 100755 tools/build_defs/pkg/testenv.sh
create mode 100644 tools/build_defs/sass/BUILD
create mode 100644 tools/build_defs/sass/README.md
create mode 100644 tools/build_defs/sass/libsass.BUILD
create mode 100644 tools/build_defs/sass/sass.WORKSPACE
create mode 100644 tools/build_defs/sass/sass.bzl
create mode 100644 tools/build_defs/sass/sassc.BUILD
create mode 100644 tools/build_defs/sass/test/BUILD
create mode 100644 tools/build_defs/sass/test/sass_rule_test.bzl
create mode 100644 tools/build_defs/scala/README.md
create mode 100644 tools/build_defs/scala/scala.bzl
create mode 100644 tools/build_defs/scala/test/BUILD
create mode 100644 tools/build_defs/scala/test/HelloLib.scala
create mode 100644 tools/build_defs/scala/test/JavaBinary.java
create mode 100644 tools/build_defs/scala/test/OtherJavaLib.java
create mode 100644 tools/build_defs/scala/test/OtherLib.scala
create mode 100644 tools/build_defs/scala/test/ScalaBinary.scala
create mode 100644 tools/build_defs/scala/test/src/main/resources/scala/test/hellos
create mode 100644 tools/build_defs/scala/test/src/main/scala/scala/test/ScalaLibBinary.scala
create mode 100644 tools/build_defs/scala/test/src/main/scala/scala/test/ScalaLibResources.scala
create mode 100644 tools/build_rules/appengine/BUILD
create mode 100644 tools/build_rules/appengine/README.md
create mode 100644 tools/build_rules/appengine/appengine.BUILD
create mode 100644 tools/build_rules/appengine/appengine.WORKSPACE
create mode 100644 tools/build_rules/appengine/appengine.bzl
create mode 100644 tools/build_rules/appengine/appengine_deploy.sh.template
create mode 100644 tools/build_rules/appengine/appengine_runner.sh.template
create mode 100644 tools/build_rules/closure/BUILD
create mode 100644 tools/build_rules/closure/README.md
create mode 100644 tools/build_rules/closure/closure.WORKSPACE
create mode 100644 tools/build_rules/closure/closure_compiler.BUILD
create mode 100644 tools/build_rules/closure/closure_js_binary.bzl
create mode 100644 tools/build_rules/closure/closure_js_library.bzl
create mode 100644 tools/build_rules/closure/closure_library.BUILD
create mode 100644 tools/build_rules/closure/closure_stylesheet_library.bzl
create mode 100644 tools/build_rules/closure/closure_template_library.bzl
create mode 100644 tools/build_rules/closure/closure_templates.BUILD
create mode 100644 tools/build_rules/genproto.bzl
create mode 100644 tools/build_rules/java_rules_skylark.bzl
create mode 100644 tools/build_rules/py_rules.bzl
create mode 100644 tools/build_rules/rust/BUILD
create mode 100644 tools/build_rules/rust/README.md
create mode 100644 tools/build_rules/rust/rust.BUILD
create mode 100644 tools/build_rules/rust/rust.WORKSPACE
create mode 100644 tools/build_rules/rust/rust.bzl
create mode 100644 tools/build_rules/rust/test/BUILD
create mode 100644 tools/build_rules/rust/test/rust_rule_test.bzl
create mode 100644 tools/build_rules/test_rules.bzl
create mode 100644 tools/buildstamp/BUILD
create mode 100644 tools/buildstamp/get_workspace_status
create mode 100644 tools/cpp/BUILD
create mode 100644 tools/cpp/CROSSTOOL
create mode 100755 tools/cpp/osx_gcc_wrapper.sh
create mode 100644 tools/defaults/BUILD
create mode 100644 tools/genrule/BUILD
create mode 100755 tools/genrule/genrule-setup.sh
create mode 100644 tools/j2objc/BUILD
create mode 100755 tools/j2objc/j2objc_wrapper.py
create mode 100644 tools/jdk/BUILD
create mode 100644 tools/jdk/proguard_whitelister.py
create mode 100644 tools/jdk/proguard_whitelister_test.py
create mode 100644 tools/jdk/proguard_whitelister_test_input.cfg
create mode 100644 tools/objc/BUILD
create mode 100644 tools/objc/dummy.c
create mode 100644 tools/objc/ios_runner.sh.mac_template
create mode 100644 tools/objc/ios_test.sh.bazel_template
create mode 100755 tools/objc/j2objc_dead_code_pruner.py
create mode 100644 tools/objc/memleaks/BUILD
create mode 100644 tools/objc/memleaks/memleaks_stub
create mode 100644 tools/objc/memleaks_plugin_stub
create mode 100644 tools/objc/sim_devices/BUILD
create mode 100644 tools/objc/testrunner_stub
create mode 100755 tools/python/2to3.sh
create mode 100644 tools/python/BUILD
create mode 100644 tools/test/BUILD
create mode 100755 tools/test/test-setup.sh
create mode 100644 tools/test_sharding_compliant
➜ golang git:(master) git
➜ golang git:(master) git push git@github.com:achew22/bazelgolang.git master
Counting objects: 208, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (194/194), done.
Writing objects: 100% (208/208), 164.90 KiB | 0 bytes/s, done.
Total 208 (delta 33), reused 0 (delta 0)
To git@github.com:achew22/bazelgolang.git
a1f3936..bec07e0 master -> master
This should now be "fixed" by being able to use labels or build file content.
First off, love bazel! Thank you guys for all your hard work. Switched to it at work and I can't believe how much better it is than Makefiles.
I tried using bazel to compile some rust code and followed the instructions from here: https://github.com/bazelbuild/bazel/blob/master/tools/build_rules/rust/README.md
I cannot get this example to compile. I've got a sample project here: https://github.com/philsc/bazel-rust-tests
This is my bazel verison:
Am I misunderstanding something or is there something missing from the README?