title: Restricting a Bazel target to specific platforms
body: <p>I have a target which can only be built for Linux (in this case, because it depends on syscalls only available on Linux and there is no desire to try and make this cross-platform). How can I express this in my <code>BUILD</code> files? </p>
  
  <p>I can see from the <a href="https://docs.bazel.build/versions/master/platforms.html" rel="noreferrer">Platforms documentation</a> that there exists a Linux platform definition as <code>@bazel_tools//platforms:linux</code>, but it is not clear to me how to make use of this to restrict a target. Trying to specify this in <code>compatible_with</code> results in an error like this:</p>
  
  <pre><code>(13:27:09) ERROR: /foo/BUILD:4:1: in compatible_with attribute of go_library rule //foo:go_default_library: constraint_value rule '@bazel_tools//platforms:linux' is misplaced here (expected environment). Since this rule was created by the macro 'go_library_macro', the error might have been caused by the macro implementation in /foo/BUILD:4:1
  </code></pre>
  
  <p>So I have a few related questions:</p>
  
  <ul>
  <li>The error seems to indicate I've supplied the wrong type of rule to <code>compatible_with</code>. What is an <code>environment</code> and how do I provide one? (I've struggled to find documentation on this)</li>
  <li>I gather that the migration to Platforms might not yet be complete and <code>rules_go</code> might not have been updated. If it's not possible with Platforms, is there an "old way" to do this instead?</li>
  <li>Ideally, I would like this not to result in build errors when running commands like <code>bazel test //:all</code> on a different (non-Linux) platform – ie. I'd prefer it just exclude these, or something. Is this possible?</li>
  </ul>
  
  <p>Thanks for your help </p>