From 860e7914e45f0fb79ae65b2aaf01c0de236dfb11 Mon Sep 17 00:00:00 2001 From: Kimura Yu <33382781+KimuraYu45z@users.noreply.github.com> Date: Tue, 31 Aug 2021 07:24:26 +0900 Subject: [PATCH] Fix Bazel build and add a GitHub action to exercise the build on different platforms (#43) * feat: http_archive * feat: gen_cc * feat: actions * feat: platforms configurations * fix: nitpicks * fix: actions --- .github/workflows/binary.yml | 30 +++++++++++++++++++++++++ BUILD | 43 ++++++++++++++++++++++++++++++++++++ bazel/BUILD | 1 - bazel/defs.bzl | 3 ++- bazel/repositories.bzl | 36 +++++++++++++++++++++++------- 5 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/binary.yml diff --git a/.github/workflows/binary.yml b/.github/workflows/binary.yml new file mode 100644 index 0000000..4b06654 --- /dev/null +++ b/.github/workflows/binary.yml @@ -0,0 +1,30 @@ +name: Binary + +on: + release: + types: + - created + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + arch: [amd64, arm64] + targetos: [windows, darwin, linux] + name: ${{ matrix.arch }}-${{ matrix.targetos }} + steps: + - uses: actions/checkout@v2 + - run: | + sudo apt install apt-transport-https curl gnupg + curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg + sudo mv bazel.gpg /etc/apt/trusted.gpg.d/ + sudo echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" > /etc/apt/sources.list.d/bazel.list + - run: | + bazel build @com_google_protobuf//:protoc + bazel build //firebase_rules_generator:protoc-gen-firebase_rules --platforms=//:${{ matrix.targetos }}-${{ matrix.arch }} + + - uses: actions/upload-artifact@v2 + with: + name: protoc-gen-firebase_rules-${{ matrix.targetos }}-${{ matrix.arch }} + path: bazel-bin/firebase_rules_generator/protoc-gen-firebase_rules diff --git a/BUILD b/BUILD index 39a336f..6adb8d0 100644 --- a/BUILD +++ b/BUILD @@ -30,3 +30,46 @@ py_test( "@com_google_protobuf//:timestamp_proto", ], ) + +platform( + name = "windows-amd64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:x86_64", + ], +) +platform( + name = "windows-arm64", + constraint_values = [ + "@platforms//os:windows", + "@platforms//cpu:arm64", + ], +) +platform( + name = "darwin-amd64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:x86_64", + ], +) +platform( + name = "darwin-arm64", + constraint_values = [ + "@platforms//os:macos", + "@platforms//cpu:arm64", + ], +) +platform( + name = "linux-amd64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], +) +platform( + name = "linux-arm64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:arm64", + ], +) diff --git a/bazel/BUILD b/bazel/BUILD index 8b13789..e69de29 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1 +0,0 @@ - diff --git a/bazel/defs.bzl b/bazel/defs.bzl index 8ab3e92..8a48855 100644 --- a/bazel/defs.bzl +++ b/bazel/defs.bzl @@ -56,7 +56,7 @@ def firestore_rules_proto_library( **kargs: other keyword arguments that are passed to ts_library. """ - outs = _outputs(srcs, ".rules") + outs = _outputs(srcs, ".cc") includes = [] if include != None: @@ -75,6 +75,7 @@ def firestore_rules_proto_library( plugin = plugin, plugin_language = "protoc-gen-firebase_rules", plugin_options = ["bazel"], + gen_cc = True ) firestore_rules_library( diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 166c354..e1e2564 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -1,13 +1,33 @@ -protobuf_commit = "099d99759101c295244c24d8954ec85b8ac65ce3" - -protobuf_sha256 = "c0ab1b088e220c1d56446f34001f0178e590270efdef1c46a77da4b9faa9d7b0" - +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") def protobuf_rules_gen_repositories(): if "com_google_protobuf" not in native.existing_rules(): - native.http_archive( + http_archive( + name = "rules_python", + sha256 = "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.3.0/rules_python-0.3.0.tar.gz", + ) + http_archive( + name = "bazel_skylib", + sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c", + urls = [ + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz", + ], + ) + http_archive( + name = "zlib", + build_file = "@com_google_protobuf//:third_party/zlib.BUILD", + sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", + strip_prefix = "zlib-1.2.11", + urls = [ + "https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz", + "https://zlib.net/zlib-1.2.11.tar.gz", + ], + ) + http_archive( name = "com_google_protobuf", - sha256 = protobuf_sha256, - strip_prefix = "protobuf-" + protobuf_commit, - url = "https://github.com/google/protobuf/archive/" + protobuf_commit + ".tar.gz", + sha256 = "528927e398f4e290001886894dac17c5c6a2e5548f3fb68004cfb01af901b53a", + strip_prefix = "protobuf-3.17.3", + url = "https://github.com/google/protobuf/archive/v3.17.3.zip", )