diff --git a/flake.nix b/flake.nix index 6d6437f979..c97855b2e5 100644 --- a/flake.nix +++ b/flake.nix @@ -51,7 +51,6 @@ nativeBuildInputs = with pkgs; [ envsubst - unzip nodejs tilt typescript diff --git a/third-party/proto/BUCK b/third-party/proto/BUCK deleted file mode 100644 index 14c88fc35d..0000000000 --- a/third-party/proto/BUCK +++ /dev/null @@ -1,18 +0,0 @@ -load(":defs.bzl", "protoc_distribution") - -protoc_distribution( - name = "distribution", - version = "21.4", -) - -alias( - name = "protoc", - actual = ":distribution[protoc]", - visibility = ["PUBLIC"], -) - -alias( - name = "google_protobuf", - actual = ":distribution[google_protobuf]", - visibility = ["PUBLIC"], -) diff --git a/third-party/proto/defs.bzl b/third-party/proto/defs.bzl deleted file mode 100644 index 963b32974c..0000000000 --- a/third-party/proto/defs.bzl +++ /dev/null @@ -1,104 +0,0 @@ -load("@prelude//http_archive/exec_deps.bzl", "HttpArchiveExecDeps") -load(":releases.bzl", "releases") - -ProtocReleaseInfo = provider(fields = [ - "version", - "url", - "sha256", -]) - -def _get_protoc_release( - version: str, - platform: str) -> ProtocReleaseInfo: - if not version in releases: - fail("Unknown protoc release version '{}'. Available versions: {}".format( - version, - ", ".join(releases.keys()), - )) - protoc_version = releases[version] - artifact = "protoc-{}-{}.zip".format(version, platform) - if not artifact in protoc_version: - fail("Unsupported platform '{}'. Available artifacts: {}".format( - platform, - ", ".join(protoc_version.keys()), - )) - protoc_artifact = protoc_version[artifact] - return ProtocReleaseInfo( - version = version, - url = protoc_artifact["url"], - sha256 = protoc_artifact["sha256"], - ) - -def _turn_http_archive_into_protoc_distribution( - providers: ProviderCollection, - protoc_filename: str) -> list[Provider]: - downloads = providers[DefaultInfo].sub_targets - include = downloads["include"][DefaultInfo] - protoc = downloads[protoc_filename][DefaultInfo] - - return [DefaultInfo( - sub_targets = { - "google_protobuf": [include], - "protoc": [ - protoc, - RunInfo(args = protoc.default_outputs[0]), - ], - }, - )] - -def _download_protoc_distribution_impl(ctx: AnalysisContext) -> Promise: - protoc_filename = "bin/protoc" + ctx.attrs.exe_extension - - return ctx.actions.anon_target(native.http_archive, { - "exec_deps": ctx.attrs._http_archive_exec_deps, - "sha256": ctx.attrs.sha256, - "sub_targets": [ - protoc_filename, - "include", - ], - "urls": [ctx.attrs.url], - }).promise.map(lambda providers: _turn_http_archive_into_protoc_distribution( - providers = providers, - protoc_filename = protoc_filename, - )) - -download_protoc_distribution = rule( - impl = _download_protoc_distribution_impl, - attrs = { - "exe_extension": attrs.string(), - "sha256": attrs.string(), - "url": attrs.string(), - "_http_archive_exec_deps": attrs.default_only(attrs.exec_dep(providers = [HttpArchiveExecDeps], default = "prelude//http_archive/tools:exec_deps")), - }, -) - -def _host_platform(): - os = host_info().os - arch = host_info().arch - if os.is_linux and arch.is_x86_64: - return "linux-x86_64" - elif os.is_linux and arch.is_aarch64: - return "linux-aarch_64" - elif os.is_macos and arch.is_x86_64: - return "osx-x86_64" - elif os.is_macos and arch.is_aarch64: - return "osx-aarch_64" - elif os.is_windows and arch.is_x86_64: - return "win64" - else: - fail("Unknown platform: os={}, arch={}".format(os, arch)) - -def protoc_distribution( - name: str, - version: str, - platform: [None, str] = None): - if platform == None: - platform = _host_platform() - exe_extension = ".exe" if platform.startswith("win") else "" - release = _get_protoc_release(version, platform) - download_protoc_distribution( - name = name, - url = release.url, - sha256 = release.sha256, - exe_extension = exe_extension, - ) diff --git a/third-party/proto/releases.bzl b/third-party/proto/releases.bzl deleted file mode 100644 index 153ca496e4..0000000000 --- a/third-party/proto/releases.bzl +++ /dev/null @@ -1,46 +0,0 @@ -# @generated -# Update with ./update.py > releases.bzl -releases = { - "21.4": { - "protoc-21.4-win32.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-win32.zip", - "sha256": "09760ff98f76ac30c8bca7433715c47161fe305bf41573a7cd00b0afcc518617" - }, - "protoc-21.4-osx-x86_64.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-osx-x86_64.zip", - "sha256": "27ac01aee3e8b95ebec017b7b3aee55d4eb095cbd2a5148d2a20350af006072e" - }, - "protoc-21.4-osx-universal_binary.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-osx-universal_binary.zip", - "sha256": "0cf1a340d1fa1366cdf22043e3f92e5374096647037020b405acea706438c603" - }, - "protoc-21.4-osx-aarch_64.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-osx-aarch_64.zip", - "sha256": "6a677c88a5e5b032aaff96767461788a316408d4ed0afef3f1455390a689ec18" - }, - "protoc-21.4-linux-x86_64.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-linux-x86_64.zip", - "sha256": "d51e8f030162f08823a4738ab0ac00bee537e30b583a562e6962dbb040d86736" - }, - "protoc-21.4-linux-x86_32.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-linux-x86_32.zip", - "sha256": "2101e3a4dd490625c15d31274a599e3bfb1f8c9fdd381ca9501da17bb6f7a3d2" - }, - "protoc-21.4-linux-s390_64.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-linux-s390_64.zip", - "sha256": "e0b69b4242bf409c825d787669a4683d63320d6e52280750df971a3376e0af56" - }, - "protoc-21.4-linux-ppcle_64.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-linux-ppcle_64.zip", - "sha256": "58c1be8ca89b8b2712f95a9dd9aeb174f8f479be9f55e71f6ffe0b0e83ef8be9" - }, - "protoc-21.4-linux-aarch_64.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-linux-aarch_64.zip", - "sha256": "5a377b505cf8c3ed29ad0b6e3827c5eb27273c00147fcfd833b9686192143e8d" - }, - "protoc-21.4-win64.zip": { - "url": "https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-win64.zip", - "sha256": "090af381392abaf5fd8ae3070d8fc2a4ba2d0a9f8e52915d69b439c33be72da5" - } - } -} diff --git a/third-party/proto/update.py b/third-party/proto/update.py deleted file mode 100755 index cfee489f67..0000000000 --- a/third-party/proto/update.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python3 -"""Query recent Github release artifacts for protobuf. - -Use this script to update the releases.bzl file that contains metadata about -protoc releases. - -This script is not executed during the regular Buck2 build. -""" - -import aiohttp -import asyncio -from contextlib import asynccontextmanager -from copy import deepcopy -from gql import gql, Client -from gql.transport.aiohttp import AIOHTTPTransport -import hashlib -import json -import os - -GITHUB_GRAPHQL_URI = "https://api.github.com/graphql" -GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN") -GITHUB_QUERY = """\ -query { - repository(owner: "protocolbuffers", name: "protobuf") { - releases(last: 1) { - nodes { - tagName - releaseAssets(first: 100) { - nodes { - name - downloadUrl - } - } - } - } - } -} -""" - -async def query_releases(): - async with aiohttp.ClientSession(raise_for_status=True) as session: - assert GITHUB_TOKEN is not None, "Provide a Github API token in $GITHUB_TOKEN" - headers = {'Authorization': f'bearer {GITHUB_TOKEN}'} - body = {"query": GITHUB_QUERY} - async with session.post(GITHUB_GRAPHQL_URI, headers=headers, json=body) as resp: - response = await resp.json() - return response["data"] - - -def format_releases(releases): - return { - release["tagName"].strip("v"): { - asset["name"]: { - "url": asset["downloadUrl"], - } - for asset in release["releaseAssets"]["nodes"] - if asset["name"].startswith("protoc-") - } - for release in releases["repository"]["releases"]["nodes"] - } - - -async def fetch_sha256(session, url): - async with session.get(url) as resp: - hasher = hashlib.sha256() - async for chunk, _ in resp.content.iter_chunks(): - hasher.update(chunk) - return hasher.hexdigest() - - -async def hash_releases(releases): - async def hash_asset(session, version, name, url): - sha256 = await fetch_sha256(session, url) - return (version, name, sha256) - - tasks = [] - async with aiohttp.ClientSession() as session: - for version, assets in releases.items(): - for name, asset in assets.items(): - tasks.append(hash_asset(session, version, name, asset["url"])) - - result = deepcopy(releases) - hashes = await asyncio.gather(*tasks) - for version, name, sha256 in hashes: - result[version][name]["sha256"] = sha256 - - return result - - -async def main(): - releases = await query_releases() - formatted = format_releases(releases) - with_sha256 = await hash_releases(formatted) - print("# @" + "generated") - print("# Update with ./update.py > releases.bzl") - print("releases = ", json.dumps(with_sha256, indent=4)) - - -asyncio.run(main()) diff --git a/toolchains/rust/macros.bzl b/toolchains/rust/macros.bzl index e15810df09..45f87cc5db 100644 --- a/toolchains/rust/macros.bzl +++ b/toolchains/rust/macros.bzl @@ -114,19 +114,17 @@ def galoy_rust_lib( ) build_env = build_env or {} - build_env.update( - { - "PROTOC": "$(exe //third-party/proto:protoc)", - "PROTOC_INCLUDE": "$(location //third-party/proto:google_protobuf)", - }, - ) - + # When using protoc included via buck: + # build_env.update( + # { + # "PROTOC": "$(exe //third-party/proto:protoc)", + # "PROTOC_INCLUDE": "$(location //third-party/proto:google_protobuf)", + # }, + # ) native.genrule( name = proto_name, - srcs = protos + [ - "//third-party/proto:google_protobuf", - ], + srcs = protos, out = ".", cmd = "$(exe :" + build_name + ")", env = build_env, diff --git a/vendir.lock.yml b/vendir.lock.yml index 2c81a60733..c1d70f5f10 100644 --- a/vendir.lock.yml +++ b/vendir.lock.yml @@ -24,12 +24,4 @@ directories: - 2023-10-15-425-gf3c685667 path: . path: third-party/rust/fixups/ring/include -- contents: - - git: - commitTitle: 'client: Fix "ctrl-c was pressed" bug...' - sha: f3c685667ef22d0130687003012b6960abec6b3b - tags: - - 2023-10-15-425-gf3c685667 - path: . - path: third-party/proto kind: LockConfig diff --git a/vendir.yml b/vendir.yml index 5ad30ffe33..9617768645 100644 --- a/vendir.yml +++ b/vendir.yml @@ -28,12 +28,3 @@ directories: includePaths: - shim/third-party/rust/fixups/ring/include/**/* newRootPath: shim/third-party/rust/fixups/ring/include -- path: third-party/proto - contents: - - path: . - git: - url: https://github.com/facebook/buck2.git - ref: f3c685667ef22d0130687003012b6960abec6b3b - includePaths: - - shim/third-party/proto/**/* - newRootPath: shim/third-party/proto diff --git a/vendir/template.yml b/vendir/template.yml index 74e37674f8..86da12df26 100644 --- a/vendir/template.yml +++ b/vendir/template.yml @@ -31,12 +31,3 @@ directories: includePaths: - shim/third-party/rust/fixups/ring/include/**/* newRootPath: shim/third-party/rust/fixups/ring/include - - path: third-party/proto - contents: - - path: . - git: - url: https://github.com/facebook/buck2.git - ref: #@ data.values.ring_fixup_git_ref - includePaths: - - shim/third-party/proto/**/* - newRootPath: shim/third-party/proto