Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/bazel_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Contains job corresponding to bazel build.

name: Bazel Build

on:
workflow_dispatch:
pull_request:
push:
branches:
# Push events on develop branch
- develop

jobs:
bazel_build_app:
name: Build Binary with Bazel
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-18.04]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up JDK 9
uses: actions/setup-java@v1
with:
java-version: 9

- name: Set up Bazel
uses: abhinavsingh/setup-bazel@v3
with:
version: 4.0.0

# Note that caching only works on non-forks.
- name: Build Oppia Proto API
run: |
bazel build -- //:android_protos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest instead building //... (to make sure everything builds).

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
11 changes: 8 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ public, importable API should be defined here (and all such libraries should be
nowhere else).
"""

load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_java//java:defs.bzl", "java_lite_proto_library", "java_proto_library")

buildifier(
name = "buildifier",
)

package_group(
name = "api_visibility",
packages = [
Expand All @@ -30,9 +35,9 @@ proto_library(
name = "android_protos",
visibility = ["//visibility:public"],
deps = [
"//proto/v1/api:android_proto",
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
"//proto/v1/api:android_proto",
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
],
)

Expand Down
46 changes: 46 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,56 @@
The top-level WORKSPACE definition for the Oppia proto API Bazel workspace.
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//repo:deps.bzl", "initializeDepsForWorkspace")

initializeDepsForWorkspace()

load("//repo:toolchains.bzl", "initializeToolchainsForWorkspace")

initializeToolchainsForWorkspace()

# buildifier is written in Go and hence needs rules_go to be built.
# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
http_archive(
name = "io_bazel_rules_go",
sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
urls = [
Copy link
Author

@anandwana001 anandwana001 Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenHenning Didn't add to deps.bzl as the urls here are array, should we update the _DEPENDENCY_VERSIONS to accept URLs as an array or should we keep these here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The multiple URLs are for redundancy. I suggest just picking whichever URL is closest to the existing URLs for parity, but yes we need to use deps.bzl since that will be consumed by users of the proto library (otherwise it may not build).

"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.17.2")

http_archive(
name = "bazel_gazelle",
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

# If you use WORKSPACE.bazel, use the following line instead of the bare gazelle_dependencies():
# gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE.bazel")
gazelle_dependencies()

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3",
strip_prefix = "buildtools-4.2.2",
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/4.2.2.tar.gz",
],
)
8 changes: 4 additions & 4 deletions proto/v1/api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ load("@rules_proto//proto:defs.bzl", "proto_library")
proto_library(
name = "android_proto",
srcs = ["android.proto"],
visibility = ["//:api_visibility"],
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
import_prefix = "org/oppia/proto/v1/api", # Make directory prefix match declared package.
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
visibility = ["//:api_visibility"],
deps = [
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
"//proto/v1/structure:structure_proto",
"//proto/v1/versions:versions_proto",
],
)
4 changes: 2 additions & 2 deletions proto/v1/structure/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ proto_library(
"state.proto",
"topic_summary.proto",
],
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
import_prefix = "org/oppia/proto/v1/structure", # Make directory prefix match declared package.
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
visibility = [
"//:api_visibility",
"//:proto_impl_visibility",
],
deps = [
"//proto/v1/versions:versions_proto",
"//proto/v1/versions:versions_proto",
],
)
4 changes: 2 additions & 2 deletions proto/v1/versions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ proto_library(
"api_versions.proto",
"structure_versions.proto",
],
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
import_prefix = "org/oppia/proto/v1/versions", # Make directory prefix match declared package.
strip_import_prefix = "", # Strip the default file prefix so that it may be redefined.
visibility = [
"//:api_visibility",
"//:proto_impl_visibility",
],
deps = [
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:descriptor_proto",
],
)
113 changes: 57 additions & 56 deletions repo/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,81 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Note to developers: Please keep this dict sorted by key to make it easier to find dependencies.
_DEPENDENCY_VERSIONS = {
"rules_python": {
"sha": "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b",
"url": "https://github.com/bazelbuild/rules_python/releases/download/{0}/rules_python-{0}.tar.gz",
"version": "0.3.0",
},
"com_google_protobuf": {
"sha": "c6003e1d2e7fefa78a3039f19f383b4f3a61e81be8c19356f85b6461998ad3db",
"strip_prefix": "protobuf-{0}",
"url": "https://github.com/protocolbuffers/protobuf/archive/v{0}.tar.gz",
"version": "3.17.3",
},
"rules_proto": {
# Note that rules_proto doesn't have any shipped versions, so the workspace needs to pin to a
# specific commit hash.
"sha": "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
"strip_prefix": "rules_proto-{0}",
"url": "https://github.com/bazelbuild/rules_proto/archive/{0}.tar.gz",
"version": "97d8af4dc474595af3900dd85cb3a29ad28cc313",
},
"rules_java": {
"sha": "220b87d8cfabd22d1c6d8e3cdb4249abd4c93dcc152e0667db061fb1b957ee68",
"url": "https://github.com/bazelbuild/rules_java/releases/download/{0}/rules_java-{0}.tar.gz",
"version": "0.1.1",
},
"rules_python": {
"sha": "934c9ceb552e84577b0faf1e5a2f0450314985b4d8712b2b70717dc679fdc01b",
"url": "https://github.com/bazelbuild/rules_python/releases/download/{0}/rules_python-{0}.tar.gz",
"version": "0.3.0",
},
"com_google_protobuf": {
"sha": "c6003e1d2e7fefa78a3039f19f383b4f3a61e81be8c19356f85b6461998ad3db",
"strip_prefix": "protobuf-{0}",
"url": "https://github.com/protocolbuffers/protobuf/archive/v{0}.tar.gz",
"version": "3.17.3",
},
"rules_proto": {
# Note that rules_proto doesn't have any shipped versions, so the workspace needs to pin to a
# specific commit hash.
"sha": "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
"strip_prefix": "rules_proto-{0}",
"url": "https://github.com/bazelbuild/rules_proto/archive/{0}.tar.gz",
"version": "97d8af4dc474595af3900dd85cb3a29ad28cc313",
},
"rules_java": {
"sha": "220b87d8cfabd22d1c6d8e3cdb4249abd4c93dcc152e0667db061fb1b957ee68",
"url": "https://github.com/bazelbuild/rules_java/releases/download/{0}/rules_java-{0}.tar.gz",
"version": "0.1.1",
},
}

def _setUpHttpArchiveDependency(name):
metadata = _DEPENDENCY_VERSIONS[name]
sha = metadata["sha"]
strip_prefix = metadata.get("strip_prefix")
url = metadata["url"]
version = metadata["version"]
metadata = _DEPENDENCY_VERSIONS[name]
sha = metadata["sha"]
strip_prefix = metadata.get("strip_prefix")
url = metadata["url"]
version = metadata["version"]

formatted_strip_prefix = strip_prefix.format(version) if not (strip_prefix == None) else None
formatted_strip_prefix = strip_prefix.format(version) if not (strip_prefix == None) else None

http_archive(
name = name,
urls = [url.format(version)],
sha256 = sha,
strip_prefix = formatted_strip_prefix,
)
http_archive(
name = name,
urls = [url.format(version)],
sha256 = sha,
strip_prefix = formatted_strip_prefix,
)

def _setUpPython():
_setUpHttpArchiveDependency(name = "rules_python")
_setUpHttpArchiveDependency(name = "rules_python")

def _setUpProtobuf():
_setUpHttpArchiveDependency(name = "com_google_protobuf")
_setUpHttpArchiveDependency(name = "com_google_protobuf")

def _setUpRulesProto():
_setUpHttpArchiveDependency(name = "rules_proto")
_setUpHttpArchiveDependency(name = "rules_proto")

def _setUpRulesJava():
_setUpHttpArchiveDependency(name = "rules_java")
_setUpHttpArchiveDependency(name = "rules_java")

def initializeDepsForWorkspace():
"""
Loads the dependencies needed to be able to build the Oppia proto API project.
"""
Loads the dependencies needed to be able to build the Oppia proto API project.

Note that this must be called after loading in this deps file, for example:
Note that this must be called after loading in this deps file, for example:

load("//repo:deps.bzl", "initializeDepsForWorkspace")
initializeDepsForWorkspace()
load("//repo:deps.bzl", "initializeDepsForWorkspace")
initializeDepsForWorkspace()

Note also that toolchains may need to be set up after loading this dependencies (see
toolchains.bzl).
"""
# Set up Python (as a prerequisite dependency for Protobuf).
_setUpPython()
Note also that toolchains may need to be set up after loading this dependencies (see
toolchains.bzl).
"""

# Set up proto & its toolchain.
_setUpProtobuf()
# Set up Python (as a prerequisite dependency for Protobuf).
_setUpPython()

# Set up rules_proto to allow defining proto libraries.
_setUpRulesProto()
# Set up proto & its toolchain.
_setUpProtobuf()

# Set up rules_java to enable the Java proto & Java proto lite rules.
_setUpRulesJava()
# Set up rules_proto to allow defining proto libraries.
_setUpRulesProto()

# Set up rules_java to enable the Java proto & Java proto lite rules.
_setUpRulesJava()
27 changes: 14 additions & 13 deletions repo/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")

def initializeToolchainsForWorkspace():
"""
Initializes the toolchains needed to be able to build the Oppia proto API project.
"""
Initializes the toolchains needed to be able to build the Oppia proto API project.

Note that this must be called after loading in this toolchains file, for example:
Note that this must be called after loading in this toolchains file, for example:

load("//repo:toolchains.bzl", "initializeToolchainsForWorkspace")
initializeToolchainsForWorkspace()
load("//repo:toolchains.bzl", "initializeToolchainsForWorkspace")
initializeToolchainsForWorkspace()

Note also that this can't be called until the dependencies themselves are loaded (see deps.bzl).
"""
# Set up the toolchains for rules_proto.
rules_proto_dependencies()
rules_proto_toolchains()
Note also that this can't be called until the dependencies themselves are loaded (see deps.bzl).
"""

# Set up the toolchains for rules_java.
rules_java_dependencies()
rules_java_toolchains()
# Set up the toolchains for rules_proto.
rules_proto_dependencies()
rules_proto_toolchains()

# Set up the toolchains for rules_java.
rules_java_dependencies()
rules_java_toolchains()