Skip to content

Commit e0fbe11

Browse files
authored
Merge pull request #439 from sourcegraph/bazel-build
Add Bazel support, fixes #88
2 parents 2c9341c + d7bb45f commit e0fbe11

File tree

36 files changed

+1398
-47
lines changed

36 files changed

+1398
-47
lines changed

.bazelignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
examples/
2+

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5.1.1

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ jobs:
2121
with:
2222
go-version: "^1.13.1"
2323
- run: sbt test
24+
bazel:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v2
28+
- run: yarn global add @bazel/bazelisk
29+
- run: bazel build //... --//semanticdb-javac:enabled=true
30+
- run: bazel run lsif-semanticdb:bazel -- --sourceroot "$PWD"
31+
- run: du -h dump.lsif-typed
32+
- run: bazel build //... --@lsif_java//semanticdb-javac:enabled=true
33+
working-directory: examples/bazel-example
34+
- run: bazel run @lsif_java//lsif-semanticdb:bazel -- --sourceroot "$PWD"
35+
working-directory: examples/bazel-example
36+
- run: du -h dump.lsif-typed
37+
working-directory: examples/bazel-example
2438
check:
2539
runs-on: ubuntu-latest
2640
steps:

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ dump.lsif
5656

5757
./generated
5858
/sources
59+
bazel-bin
60+
bazel-lsif-java
61+
bazel-out
62+
bazel-testlogs

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
golang 1.17.5

WORKSPACE

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
workspace(name = "lsif_java_tests")
2+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3+
4+
##############
5+
# Bazel stdlib
6+
##############
7+
# To update this version, copy-paste instructions from https://github.com/bazelbuild/bazel-skylib/releases
8+
http_archive(
9+
name = "bazel_skylib",
10+
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
11+
urls = [
12+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
13+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
14+
],
15+
)
16+
17+
##########
18+
# Protobuf
19+
##########
20+
# To update this version, copy-paste instructions from https://github.com/bazelbuild/rules_proto/releases
21+
http_archive(
22+
name = "rules_proto",
23+
sha256 = "e017528fd1c91c5a33f15493e3a398181a9e821a804eb7ff5acdd1d2d6c2b18d",
24+
strip_prefix = "rules_proto-4.0.0-3.20.0",
25+
urls = [
26+
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0-3.20.0.tar.gz",
27+
],
28+
)
29+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
30+
rules_proto_dependencies()
31+
rules_proto_toolchains()
32+
33+
##############
34+
# JVM External
35+
##############
36+
# To update this version, copy-paste instructions from https://github.com/bazelbuild/rules_jvm_external/releases
37+
RULES_JVM_EXTERNAL_TAG = "4.2"
38+
RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"
39+
http_archive(
40+
name = "rules_jvm_external",
41+
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
42+
sha256 = RULES_JVM_EXTERNAL_SHA,
43+
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
44+
)
45+
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
46+
rules_jvm_external_deps()
47+
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
48+
rules_jvm_external_setup()
49+
load("@rules_jvm_external//:defs.bzl", "maven_install")
50+
maven_install(
51+
artifacts = [
52+
"com.google.protobuf:protobuf-java:3.15.6",
53+
"com.google.protobuf:protobuf-java-util:3.15.6",
54+
"org.projectlombok:lombok:1.18.22",
55+
],
56+
repositories = [
57+
"https://repo1.maven.org/maven2",
58+
],
59+
)

examples/bazel-example/WORKSPACE

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
# This is an end-to-end example of how to consume lsif-java from an external repository.
3+
workspace(name = "lsif_java_example")
4+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5+
6+
##############
7+
# Bazel stdlib
8+
##############
9+
# To update this version, copy-paste instructions from https://github.com/bazelbuild/bazel-skylib/releases
10+
http_archive(
11+
name = "bazel_skylib",
12+
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
13+
urls = [
14+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
15+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
16+
],
17+
)
18+
19+
##############
20+
# lsif-java
21+
##############
22+
local_repository(
23+
name = "lsif_java",
24+
path = "../.."
25+
)
26+
# TODO: add commented out `http_archive` example once this workspace file is available on GitHub.
27+
28+
##########
29+
# Protobuf
30+
##########
31+
# To update this version, copy-paste instructions from https://github.com/bazelbuild/rules_proto/releases
32+
http_archive(
33+
name = "rules_proto",
34+
sha256 = "e017528fd1c91c5a33f15493e3a398181a9e821a804eb7ff5acdd1d2d6c2b18d",
35+
strip_prefix = "rules_proto-4.0.0-3.20.0",
36+
urls = [
37+
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0-3.20.0.tar.gz",
38+
],
39+
)
40+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
41+
rules_proto_dependencies()
42+
rules_proto_toolchains()
43+
44+
##############
45+
# JVM External
46+
##############
47+
# To update this version, copy-paste instructions from https://github.com/bazelbuild/rules_jvm_external/releases
48+
RULES_JVM_EXTERNAL_TAG = "4.2"
49+
RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"
50+
http_archive(
51+
name = "rules_jvm_external",
52+
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
53+
sha256 = RULES_JVM_EXTERNAL_SHA,
54+
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
55+
)
56+
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
57+
rules_jvm_external_deps()
58+
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
59+
rules_jvm_external_setup()
60+
load("@rules_jvm_external//:defs.bzl", "maven_install")
61+
maven_install(
62+
artifacts = [
63+
"com.google.protobuf:protobuf-java:3.15.6", # Required dependency by lsif-java.
64+
"com.google.protobuf:protobuf-java-util:3.15.6", # Required dependency by lsif-java.
65+
"com.google.guava:guava:31.0-jre", # Not required dependency, only used by tests.
66+
],
67+
repositories = [
68+
"https://repo1.maven.org/maven2",
69+
],
70+
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# We import the custom `java_library` implementation that automatically adds the
2+
# SemanticDB compiler plugin based on the presence of the flag
3+
# `--@lsif_java//semanticdb-javac:enabled=true`. By default, this java_library
4+
# rule works just like the official java_library rule. Feel free to copy-paste
5+
# the `semanticdb:defs.bzl` file and adapt to your needs. This example is only
6+
# for demonstration purposes.
7+
load("@lsif_java//semanticdb-javac:defs.bzl", "java_library")
8+
9+
package(
10+
default_visibility = ["//visibility:public"],
11+
)
12+
13+
java_library(
14+
name = "example",
15+
srcs = ["Example.java"],
16+
deps = [
17+
"@maven//:com_google_guava_guava",
18+
],
19+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package example;
2+
import com.google.common.util.concurrent.Futures;
3+
4+
public class Example {
5+
public static void hello() {
6+
System.out.println(Futures.immediateCancelledFuture());
7+
}
8+
9+
}

lsif-java/src/main/scala/com/sourcegraph/lsif_java/commands/IndexSemanticdbCommand.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ final case class IndexSemanticdbCommand(
3333
@Description(
3434
"Whether to process the SemanticDB files in parallel"
3535
) parallel: Boolean = true,
36+
@Description(
37+
"Whether to infer the location of SemanticDB files based as produced by Bazel"
38+
) bazel: Boolean = true,
3639
@Description("URL to a PackageHub instance")
3740
@Hidden
3841
packagehub: Option[String] = None,

0 commit comments

Comments
 (0)