diff --git a/WORKSPACE b/WORKSPACE index 086182c2..10bf9af5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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( diff --git a/deps/BUILD b/deps/BUILD index e76fcaad..69a3c34b 100644 --- a/deps/BUILD +++ b/deps/BUILD @@ -5,10 +5,9 @@ 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 = [ @@ -16,4 +15,4 @@ scala_binary( "@annex_deps//:org_scala_sbt_librarymanagement_core_3", "@annex_deps//:org_scala_sbt_librarymanagement_coursier_3", ], -) \ No newline at end of file +) diff --git a/deps/scala_deps.bzl b/deps/scala_deps.bzl index 90ae71d2..a9e83354 100644 --- a/deps/scala_deps.bzl +++ b/deps/scala_deps.bzl @@ -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, diff --git a/deps/src/BazelExt.scala b/deps/src/BazelExt.scala index 6f11b301..ab827ba4 100644 --- a/deps/src/BazelExt.scala +++ b/deps/src/BazelExt.scala @@ -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 diff --git a/deps/src/Vars.scala b/deps/src/Vars.scala index 4eafae83..5070652c 100644 --- a/deps/src/Vars.scala +++ b/deps/src/Vars.scala @@ -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() diff --git a/deps/src/templates/BUILD b/deps/src/templates/BUILD deleted file mode 100644 index 2aab196f..00000000 --- a/deps/src/templates/BUILD +++ /dev/null @@ -1,5 +0,0 @@ -filegroup( - name = "jar_artifact_callback", - srcs = ["jar_artifact_callback.bzl"], - visibility = ["//visibility:public"], -) diff --git a/deps/src/templates/jar_artifact_callback.bzl b/deps/src/templates/jar_artifact_callback.bzl deleted file mode 100644 index 93df4cd2..00000000 --- a/deps/src/templates/jar_artifact_callback.bzl +++ /dev/null @@ -1,37 +0,0 @@ -def _jar_artifact_impl(ctx): - jar_name = "%s.jar" % ctx.name - ctx.download( - output = ctx.path("jar/%s" % jar_name), - url = ctx.attr.urls, - executable = False, - ) - build_file_contents = """ -package(default_visibility = ['//visibility:public']) -filegroup( - name = 'jar', - srcs = ['{jar_name}'], - visibility = ['//visibility:public'], -) -alias( - name = "file", - actual = ":jar", - visibility = ["//visibility:public"], -)\n""".format(artifact = ctx.attr.artifact, jar_name = jar_name) - ctx.file(ctx.path("jar/BUILD"), build_file_contents, False) - return None - -jar_artifact = repository_rule( - attrs = { - "artifact": attr.string(mandatory = True), - "urls": attr.string_list(mandatory = True), - }, - implementation = _jar_artifact_impl, -) - -def jar_artifact_callback(hash): - jar_artifact( - artifact = hash["artifact"], - name = hash["name"], - urls = [hash["url"]], - ) - native.bind(name = hash["bind"], actual = hash["actual"]) diff --git a/rules/scala/init.bzl b/rules/scala/init.bzl index 4008504a..8111c4fd 100644 --- a/rules/scala/init.bzl +++ b/rules/scala/init.bzl @@ -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") @@ -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") diff --git a/rules/scala/workspace.bzl b/rules/scala/workspace.bzl index b7f6efa7..2130ae3b 100644 --- a/rules/scala/workspace.bzl +++ b/rules/scala/workspace.bzl @@ -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", @@ -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, diff --git a/rules/scala_proto/3rdparty/workspace.bzl b/rules/scala_proto/3rdparty/workspace.bzl index a93ae79e..83f763d6 100644 --- a/rules/scala_proto/3rdparty/workspace.bzl +++ b/rules/scala_proto/3rdparty/workspace.bzl @@ -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"},