title: How to not rebuild artifacts on every invocation
body: <p>I want to download and build ruby within a workspace.  I've been trying to implement this by mimicking rules_go.  I have that part working.  The issue I'm having is it rebuilds the openssl and ruby artifacts each time <code>ruby_download_sdk</code> is invoked.  In the code below the download artifacts are cached but the builds of openssl and ruby are always executed.  </p>
  
  <pre class="lang-py prettyprint-override"><code>def ruby_download_sdk(name, version = None):
      # TODO detect os and arch
      os, arch = "osx", "x86_64"
  
      _ruby_download_sdk(
          name = name, 
          version = version,
      )
      _register_toolchains(name, os, arch)
  
  def _ruby_download_sdk_impl(repository_ctx):
      # TODO detect platform
      platform = ("osx", "x86_64")
  
      _sdk_build_file(repository_ctx, platform)
      _remote_sdk(repository_ctx)
  
  _ruby_download_sdk = repository_rule(
      _ruby_download_sdk_impl,
      attrs = {
          "version": attr.string(),
      },
  )
  
  def _remote_sdk(repository_ctx):
      _download_openssl(repository_ctx, version = "1.1.1c")
      _download_ruby(repository_ctx, version = "2.6.3")
  
      openssl_path, ruby_path = "openssl/build", ""
      _build(repository_ctx, "openssl", openssl_path, ruby_path)
      _build(repository_ctx, "ruby", openssl_path, ruby_path)
  
  def _build(repository_ctx, name, openssl_path, ruby_path):
      script_name = "build-{}.sh".format(name)
      template_name = "build-{}.template".format(name)
  
      repository_ctx.template(
          script_name,
          Label("@rules_ruby//ruby/private:{}".format(template_name)),
          substitutions = {
              "{ssl_build}": openssl_path,
              "{ruby_build}": ruby_path,
          }
      )
      repository_ctx.report_progress("Building {}".format(name))
      res = repository_ctx.execute(["./" + script_name], timeout=20*60)
  
      if res.return_code != 0:
          print("res %s" % res.return_code)
          print(" -stdout: %s" % res.stdout)
          print(" -stderr: %s" % res.stderr)
  </code></pre>
  
  <p>Any advice on how I can make bazel aware such that it doesn't rebuild these build artifacts every time?</p>