【问题标题】:Is there a bazel rule that supports publishing a go binary?是否有支持发布 go 二进制文件的 bazel 规则?
【发布时间】:2020-12-13 01:26:38
【问题描述】:

在成功构建 go 二进制文件 (cli) 后,我想将二进制文件发布到存储库管理器,例如神器。我发现了各种关于上传 jar 依赖项的参考,但没有特定于 rules_go

谁能指出我正确的方向?

【问题讨论】:

    标签: bazel bazel-rules


    【解决方案1】:

    我认为 go 没有发布故事。 实现#1372 花了 4 年时间,将发布部分留在以构建为使命的 Bazel 之外可能更容易。

    【讨论】:

      【解决方案2】:

      感谢您的跟进。我一直在挖掘并没有找到解决方案,但想出了以下解决方案。

      def _local_deploy_impl(ctx):
          target = ctx.attr.target
          shell_commands = ""
      
          for s in ctx.files.srcs:
              shell_commands += "sudo cp %s %s\n" % (s.short_path, target) # <2>
      
          ctx.actions.write(
              output = ctx.outputs.executable,
              is_executable = True,
              content = shell_commands,
          )
          runfiles = ctx.runfiles(files = ctx.files.srcs)
          return DefaultInfo(
              executable = ctx.outputs.executable,
              runfiles = runfiles,
          )
      
      local_deploy = rule(
          executable = True,
          implementation = _local_deploy_impl,
          attrs = {
              "srcs": attr.label_list(allow_files = True),
              "target": attr.string(default = "/usr/local/bin", doc = "Deployment target directory"),
          },
      )
      
      

      包含在构建文件中:

      local_deploy(
          name = "install",
          srcs = [":binary"],
      )
      

      srcs 引用另一个将在本地安装的规则的二进制输出。

      有什么改进建议吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-21
        • 2011-09-08
        • 1970-01-01
        • 1970-01-01
        • 2021-04-12
        • 1970-01-01
        • 2017-03-02
        • 2015-06-18
        相关资源
        最近更新 更多