Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare deps generator for external use #49

Merged
merged 22 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 0 additions & 22 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,6 @@ http_archive(

load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_install(
name = "annex_deps",
artifacts = [
"com.github.scopt:scopt_3:4.1.0",
"org.scala-sbt:librarymanagement-core_3:2.0.0-M2",
"org.scala-sbt:librarymanagement-coursier_3:2.0.0-alpha8",
],
fetch_sources = True,
maven_install_json = "@rules_scala3//:annex_deps_install.json",
repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
"https://maven-central.storage-download.googleapis.com/maven2",
"https://mirror.bazel.build/repo1.maven.org/maven2",
"https://scala-ci.typesafe.com/artifactory/scala-integration/",
],
)

load("@annex_deps//:defs.bzl", "pinned_maven_install")

pinned_maven_install()

rules_cc_version = "0.0.9"

http_archive(
Expand Down
5 changes: 2 additions & 3 deletions deps/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ scala_binary(
srcs = ["//deps/src:deps"],
args = [
"--project-root=.",
"--scala-version=3.5.1-RC1", #TODO
"--scala-version=3.5.2", #TODO
],
main_class = "rules_scala3.deps.src.Deps",
resources = ["//deps/src/templates:jar_artifact_callback"],
scala = "//scala:bootstrap_3",
visibility = ["//visibility:public"],
deps = [
"@annex_deps//:com_github_scopt_scopt_3",
"@annex_deps//:org_scala_sbt_librarymanagement_core_3",
"@annex_deps//:org_scala_sbt_librarymanagement_coursier_3",
],
)
)
5 changes: 2 additions & 3 deletions deps/scala_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ def scala_deps(
scala_binary(
name = name,
main_class = "rules_scala3.deps.src.Deps",
resources = ["//deps/src/templates:jar_artifact_callback"],
scala = "//scala:bootstrap_3",
scala = "@rules_scala3//scala:bootstrap_3",
visibility = ["//visibility:public"],
srcs = ["//deps/src:deps", src],
srcs = ["@rules_scala3//deps/src:deps", src],
args = [
"--project-root=" + project_root,
"--scala-version=" + scala_version,
Expand Down
39 changes: 38 additions & 1 deletion deps/src/BazelExt.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
package rules_scala3.deps.src

object BazelExt:
private lazy val jarArtifactCallback = String(getClass.getResourceAsStream("/deps/src/templates/jar_artifact_callback.bzl").readAllBytes())
private val jarArtifactCallback =
"def _jar_artifact_impl(ctx):\n" +
" jar_name = \"%s.jar\" % ctx.name\n" +
" ctx.download(\n" +
" output = ctx.path(\"jar/%s\" % jar_name),\n" +
" url = ctx.attr.urls,\n" +
" executable = False,\n" +
" )\n" +
" build_file_contents = \"\"\"\n" +
"package(default_visibility = ['//visibility:public'])\n" +
"filegroup(\n" +
" name = 'jar',\n" +
" srcs = ['{jar_name}'],\n" +
" visibility = ['//visibility:public'],\n" +
")\n" +
"alias(\n" +
" name = \"file\",\n" +
" actual = \":jar\",\n" +
" visibility = [\"//visibility:public\"],\n" +
")\\n\"\"\".format(artifact = ctx.attr.artifact, jar_name = jar_name)\n" +
" ctx.file(ctx.path(\"jar/BUILD\"), build_file_contents, False)\n" +
" return None\n" +
"\n" +
"jar_artifact = repository_rule(\n" +
" attrs = {\n" +
" \"artifact\": attr.string(mandatory = True),\n" +
" \"urls\": attr.string_list(mandatory = True),\n" +
" },\n" +
" implementation = _jar_artifact_impl,\n" +
")\n" +
"\n" +
"def jar_artifact_callback(hash):\n" +
" jar_artifact(\n" +
" artifact = hash[\"artifact\"],\n" +
" name = hash[\"name\"],\n" +
" urls = [hash[\"url\"]],\n" +
" )\n" +
" native.bind(name = hash[\"bind\"], actual = hash[\"actual\"])"

def apply(targets: Vector[Target]): String =
val dependencyLines: String = targets
Expand Down
7 changes: 6 additions & 1 deletion deps/src/Vars.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ object Vars:
help('h', "help").text("Prints this usage text"),
opt[File]('r', "project-root")
.required()
.action((value, vars) => vars.copy(projectRoot = value))
.action((value, vars) => {
val resolvedPath = value.getPath match
case "." => new File(sys.env.getOrElse("BUILD_WORKSPACE_DIRECTORY", ".")).getAbsoluteFile
case _ => value.getAbsoluteFile
vars.copy(projectRoot = resolvedPath)
})
.text("The ABSOLUTE path to the root of the bazel repo"),
opt[String]('s', "scala-version")
.required()
Expand Down
5 changes: 0 additions & 5 deletions deps/src/templates/BUILD

This file was deleted.

37 changes: 0 additions & 37 deletions deps/src/templates/jar_artifact_callback.bzl

This file was deleted.

3 changes: 2 additions & 1 deletion rules/scala/init.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@annex_deps//:defs.bzl", "pinned_maven_install")
load("@bazel_features//:deps.bzl", "bazel_features_deps")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
Expand All @@ -18,8 +19,8 @@ def rules_scala3_init():
protobuf_deps()
rules_proto_dependencies()
rules_proto_toolchains()

bazel_features_deps()

pinned_maven_install()
load_maven_dependencies()
scalafmt_default_config(".scalafmt.conf")
14 changes: 14 additions & 0 deletions rules/scala/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ filegroup(
)
"""

_ANNEX_DEPS_ARTIFACTS = [
"com.github.scopt:scopt_3:4.1.0",
"org.scala-sbt:librarymanagement-core_3:2.0.0-M2",
"org.scala-sbt:librarymanagement-coursier_3:2.0.0-alpha8",
]

repositories = [
"https://repo1.maven.org/maven2",
"https://repo.maven.apache.org/maven2",
Expand All @@ -36,6 +42,14 @@ sbt_version = "2.0.0-M2"
zinc_version = "2.0.0-alpha14"

def scala_repositories():
maven_install(
name = "annex_deps",
artifacts = _ANNEX_DEPS_ARTIFACTS,
fetch_sources = True,
maven_install_json = "@rules_scala3//:annex_deps_install.json",
repositories = repositories,
)

http_archive(
name = "compiler_bridge_2_13",
build_file_content = _SRC_FILEGROUP_BUILD_FILE_CONTENT,
Expand Down
1 change: 0 additions & 1 deletion rules/scala_proto/3rdparty/workspace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def jar_artifact_callback(hash):
)
native.bind(name = hash["bind"], actual = hash["actual"])


def list_dependencies():
return [
{"artifact":"com.google.protobuf:protobuf-java:4.28.2","url":"https://oss.sonatype.org/service/local/repositories/releases/content/com/google/protobuf/protobuf-java/4.28.2/protobuf-java-4.28.2.jar","name":"com_google_protobuf_protobuf_java","actual":"@com_google_protobuf_protobuf_java//jar","bind": "jar/com/google/protobuf/protobuf_java"},
Expand Down
Loading