|
| 1 | +def _impl(repository_ctx): |
| 2 | + version = repository_ctx.attr.version |
| 3 | + url_prefix = "https://github.com/GoogleChrome/ripunzip/releases/download/v%s" % version |
| 4 | + build_file = Label("//misc/ripunzip:BUILD.ripunzip.bazel") |
| 5 | + if repository_ctx.os.name == "linux": |
| 6 | + repository_ctx.download_and_extract( |
| 7 | + url="%s/ripunzip_%s-1_amd64.deb" % (url_prefix, version), |
| 8 | + sha256=repository_ctx.attr.sha256_linux, |
| 9 | + canonical_id="ripunzip-deb", |
| 10 | + output="deb", |
| 11 | + ) |
| 12 | + repository_ctx.extract( |
| 13 | + "deb/data.tar.xz", |
| 14 | + strip_prefix="usr", |
| 15 | + ) |
| 16 | + elif repository_ctx.os.name == "windows": |
| 17 | + repository_ctx.download_and_extract( |
| 18 | + url="%s/ripunzip_v%s-x86_64-pc-windows-msvc.zip" % (url_prefix, version), |
| 19 | + sha256=repository_ctx.attr.sha256_windows, |
| 20 | + output="bin", |
| 21 | + ) |
| 22 | + elif repository_ctx.os.name == "macos": |
| 23 | + arch = repository_ctx.os.arch |
| 24 | + if arch == "x86_64": |
| 25 | + suffix = "x86_64-apple-darwin" |
| 26 | + sha256 = repository_ctx.attr.sha256_macos_intel |
| 27 | + elif arch == "aarch64": |
| 28 | + suffix = "aarch64-apple-darwin" |
| 29 | + sha256 = repository_ctx.attr.sha256_macos_arm |
| 30 | + else: |
| 31 | + fail("Unsupported macOS architecture: %s" % arch) |
| 32 | + repository_ctx.download_and_extract( |
| 33 | + url="%s/ripunzip_v%s-%s.tar.gz" % (url_prefix, version, suffix), |
| 34 | + sha256=sha256, |
| 35 | + output="bin", |
| 36 | + ) |
| 37 | + else: |
| 38 | + fail("Unsupported OS: %s" % repository_ctx.os.name) |
| 39 | + repository_ctx.file("WORKSPACE.bazel") |
| 40 | + repository_ctx.symlink(build_file, "BUILD.bazel") |
| 41 | + |
| 42 | +ripunzip_archive = repository_rule( |
| 43 | + implementation=_impl, |
| 44 | + attrs={ |
| 45 | + "version": attr.string(mandatory=True), |
| 46 | + "sha256_linux": attr.string(mandatory=True), |
| 47 | + "sha256_windows": attr.string(mandatory=True), |
| 48 | + "sha256_macos_intel": attr.string(mandatory=True), |
| 49 | + "sha256_macos_arm": attr.string(mandatory=True), |
| 50 | + }, |
| 51 | +) |
0 commit comments