title: Skylark struct with methods
body: <p>Here's something I tried to do, and it works well. I find it useful, but it feels like a hack, so I'm afraid it will break in the future.</p>
  
  <p>I'm working on converting a large project to Bazel, and we have lots of local wrappers, something like:</p>
  
  <pre><code>my_cc_library(name='a', srcs=['lib.c'])
  my_cc_binary(name='b', deps=['a'], srcs=['main.c'])
  </code></pre>
  
  <p>This requires lots of <code>load</code> commands, which are annoying and a repeating source of errors.
  If it was normal Python, I'd simply import a whole module. But Skylark requires loading functions one by one.</p>
  
  <p>I can remove the need for individual loads, using a struct.</p>
  
  <p>In <code>my.bzl</code>:</p>
  
  <pre><code>def _my_cc_library(...): ...
  def _my_cc_binary(...): ...
  
  my = struct(cc_library=_my_cc_library, cc_binary=_my_cc_binary)
  </code></pre>
  
  <p>In various <code>BUILD</code> files:</p>
  
  <pre><code>load('//my.bzl', 'my')
  my.cc_library(name='a', srcs=['lib.c'])
  my.cc_binary(name='b', deps=['a'], srcs=['main.c'])
  </code></pre>
  
  <p>As I wrote above, it all works well. I can use if for wrappers to native rules, and for various other functions.</p>
  
  <p>But an I abusing the language? Is it prone to break in the future?</p>
  
  <p>Thanks.</p>