Skip to content

Commit

Permalink
Fix Bazel build and add a GitHub action to exercise the build on diff…
Browse files Browse the repository at this point in the history
…erent platforms (#43)

* feat: http_archive

* feat: gen_cc

* feat: actions

* feat: platforms configurations

* fix: nitpicks

* fix: actions
  • Loading branch information
kimurayu45z authored Aug 30, 2021
1 parent d413219 commit 860e791
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 10 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/binary.yml
Original file line number Diff line number Diff line change
@@ -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
43 changes: 43 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
1 change: 0 additions & 1 deletion bazel/BUILD
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

3 changes: 2 additions & 1 deletion bazel/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
36 changes: 28 additions & 8 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
@@ -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",
)

0 comments on commit 860e791

Please sign in to comment.