diff --git a/.github/workflows/bazel_build.yml b/.github/workflows/bazel_build.yml new file mode 100644 index 0000000..c2469e3 --- /dev/null +++ b/.github/workflows/bazel_build.yml @@ -0,0 +1,37 @@ +# 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.2.0 + + - name: Build Oppia Proto API + run: | + bazel build -- //:android_protos diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3752701 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,37 @@ +# Contains job corresponding to lint check of Bazel files. + +name: Lint check + +on: + workflow_dispatch: + pull_request: + push: + branches: + # Push events on develop branch + - develop + +jobs: + lint_check: + name: Lint check + 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.2.0 + + - name: Lint check using Buildifier + run: | + bazel run -- //:buildifier diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac51a05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bazel-* diff --git a/BUILD b/BUILD index 993d07a..7a10cc0 100644 --- a/BUILD +++ b/BUILD @@ -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 = [ @@ -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", ], ) diff --git a/WORKSPACE b/WORKSPACE index b7156f6..1193649 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -6,6 +6,18 @@ load("//repo:deps.bzl", "initializeDepsForWorkspace") initializeDepsForWorkspace() +load("//repo:deps.bzl", "initializeGoDeps") +initializeGoDeps() + +load("//repo:deps.bzl", "initializeBazelGazell") +initializeBazelGazell() + +load("//repo:deps.bzl", "initializeProtobuf") +initializeProtobuf() + +load("//repo:deps.bzl", "initializeBazelBuildTools") +initializeBazelBuildTools() + load("//repo:toolchains.bzl", "initializeToolchainsForWorkspace") initializeToolchainsForWorkspace() diff --git a/proto/v1/api/BUILD b/proto/v1/api/BUILD index 2e4da12..a344059 100644 --- a/proto/v1/api/BUILD +++ b/proto/v1/api/BUILD @@ -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", ], ) diff --git a/proto/v1/structure/BUILD b/proto/v1/structure/BUILD index 44cdea0..3dd66be 100644 --- a/proto/v1/structure/BUILD +++ b/proto/v1/structure/BUILD @@ -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", ], ) diff --git a/proto/v1/versions/BUILD.bazel b/proto/v1/versions/BUILD.bazel index 102377e..51978ac 100644 --- a/proto/v1/versions/BUILD.bazel +++ b/proto/v1/versions/BUILD.bazel @@ -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", ], ) diff --git a/repo/deps.bzl b/repo/deps.bzl index e65d5a8..fe22222 100644 --- a/repo/deps.bzl +++ b/repo/deps.bzl @@ -5,83 +5,127 @@ instructions in the README for more details. """ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") # 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", + }, + "io_bazel_rules_go": { + "sha": "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f", + "url": "https://github.com/bazelbuild/rules_go/releases/download/{0}/rules_go-{0}.zip", + "version": "v0.29.0", + }, + "bazel_gazelle": { + "sha": "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", + "url": "https://github.com/bazelbuild/bazel-gazelle/releases/download/{0}/bazel-gazelle-{0}.tar.gz", + "version": "v0.24.0", + }, + "com_github_bazelbuild_buildtools": { + "sha": "ae34c344514e08c23e90da0e2d6cb700fcd28e80c02e23e4d5715dddcb42f7b3", + "strip_prefix": "buildtools-{0}", + "url": "https://github.com/bazelbuild/buildtools/archive/refs/tags/{0}.tar.gz", + "version": "4.2.2", + }, } 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 _setUpIoBazelRulesGo(): + _setUpHttpArchiveDependency(name ="io_bazel_rules_go") + +def _setUpBazelGazell(): + _setUpHttpArchiveDependency(name ="bazel_gazelle") + +def _setUpBazelBuildTools(): + _setUpHttpArchiveDependency(name ="com_github_bazelbuild_buildtools") 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: + + 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() + + _setUpProtobuf() + + # Set up rules_proto to allow defining proto libraries. + _setUpRulesProto() - Note that this must be called after loading in this deps file, for example: + # Set up rules_java to enable the Java proto & Java proto lite rules. + _setUpRulesJava() - load("//repo:deps.bzl", "initializeDepsForWorkspace") - initializeDepsForWorkspace() + _setUpIoBazelRulesGo() - 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() +def initializeGoDeps(): + go_rules_dependencies() + go_register_toolchains(version = "1.17.2") - # Set up proto & its toolchain. - _setUpProtobuf() +def initializeBazelGazell(): + _setUpBazelGazell() + gazelle_dependencies() - # Set up rules_proto to allow defining proto libraries. - _setUpRulesProto() +def initializeProtobuf(): + protobuf_deps() - # Set up rules_java to enable the Java proto & Java proto lite rules. - _setUpRulesJava() +def initializeBazelBuildTools(): + _setUpBazelBuildTools() diff --git a/repo/toolchains.bzl b/repo/toolchains.bzl index 0d818cf..70ad1bd 100644 --- a/repo/toolchains.bzl +++ b/repo/toolchains.bzl @@ -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()