Is there any way to load foo.bzl for all BUILD files automatically?

631 views
Skip to first unread message

Ming Zhao

unread,
May 15, 2015, 8:11:08 PM5/15/15
to bazel-...@googlegroups.com
Essentially I'd like to make some custom macros or skylark rules can
be just used for BUILD files within my workspace. Do I put something
like load(...) in my workspace file?

Thanks.

Damien Martin-guillerez

unread,
May 18, 2015, 2:25:10 AM5/18/15
to Ming Zhao, bazel-...@googlegroups.com
You can put it in a file in tools/build_rules/prelude_bazel and it will be prepended to all your BUILD file in your workspace.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAN0GiO0uaWTM57rgvw8Q9oGiWj6HK5V_kqjfKbSzgRKpkMaPJw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Hu David

unread,
Dec 1, 2015, 2:35:09 AM12/1/15
to bazel-discuss, ming...@gmail.com
Is this still available?
I would like to include a native rule to all my build files.
I add the native rule to %bazel/tools/build_rules/prelude_bazel file. However, it does not take affect.

Do I miss anything? Thanks.

David

Kristina Chodorow

unread,
Dec 1, 2015, 11:32:16 AM12/1/15
to Hu David, bazel-discuss, Ming Zhao
The prelude_bazel file should still work.  You'll need a BUILD file in tools/build_rules/ (it can be empty).

Also, just a note: these are not called native rules.  Native rules are written in Java and compiled into Bazel.  Anything written in Skylark and loaded at runtime is non-native.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Hu David

unread,
Dec 1, 2015, 11:16:43 PM12/1/15
to bazel-discuss, chi...@gmail.com, ming...@gmail.com
Thanks! I forget the BUILD file.

Kristina Chodorow

unread,
Dec 2, 2015, 11:25:26 AM12/2/15
to Hu David, bazel-discuss, Ming Zhao
The BUILD file actually wasn't a requirement when this thread was originally created: we're gradually moving to referring to .bzl files by label, so the internal load('/tools/build_rules/prelude_bazel') (no BUILD file required) was recently changed to load('//tools/build_rules:prelude_bazel') (where //tools/build_rules has to be a package, i.e., contain a BUILD file).  

On Tue, Dec 1, 2015 at 11:16 PM, Hu David <chi...@gmail.com> wrote:
Thanks! I forget the BUILD file.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Andrew Allen

unread,
Dec 3, 2015, 1:44:48 AM12/3/15
to Kristina Chodorow, Hu David, bazel-discuss, Ming Zhao
Does this mean that you need to export_files(['prelude_bazel']) in that build file?


/** ~Andrew Z Allen */

Kristina Chodorow

unread,
Dec 3, 2015, 10:48:02 AM12/3/15
to Andrew Allen, Hu David, bazel-discuss, Ming Zhao
You don't actually have to.  I don't know whether that's a bug.

Damien Martin-guillerez

unread,
Dec 3, 2015, 10:50:42 AM12/3/15
to Kristina Chodorow, Andrew Allen, Hu David, bazel-discuss, Ming Zhao
AFAICT the simple existence of a file define the corresponding label and load statement are not restricted by visibility so I think this work as designed but not necessarly work as intended (but visibility restrictions on load statements are complex, that's why it is not enforced right now).

Reply all
Reply to author
Forward
0 new messages