bazelbuild / rules_scala

Scala rules for Bazel
Apache License 2.0
363 stars 275 forks source link

name 'scala_config' is not defined #1490

Closed kolotyluk closed 1 year ago

kolotyluk commented 1 year ago

When I follow the README at https://github.com/bazelbuild/rules_scala I get the following results

hello-world % bazel build hello-world-scala
ERROR: /Users/eric.kolotyluk/git/autonomous-iam/poc/concurrency-laboratory/WORKSPACES/hello-world/WORKSPACE.bazel:26:1: name 'scala_config' is not defined (did you mean 'xcode_config'?)
ERROR: Error computing the main repository mapping: Encountered error while reading extension file 'scala_config.bzl': no such package '@io_bazel_rules_scala//': error loading package 'external': Could not load //external package
Loading: 

Which suggests to me, it's related to my WORKSPACE.bazel file

scala_config(scala_version = "3.2.2")                               # https://www.scala-lang.org/download/all.html
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
scala_config()

Am I doing something wrong here?

If I am doing something wrong here, I will post on Stack Overflow, but if there is something lacking in the documentation, we can settle it here.

liucijus commented 1 year ago

@kolotyluk, in your WORKSPACE, make sure you load scala_config before it is actually used

kolotyluk commented 1 year ago

Now I see the problem... I simply did a copy/paste without really paying attention. The actual documentation reads

# Stores Scala version and other configuration
# 2.12 is a default version, other versions can be use by passing them explicitly:
# scala_config(scala_version = "2.11.12")
load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
scala_config()

When it would be better to read

load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
# Stores Scala version and other configuration
# 2.12 is a default version, other versions can be use by passing them explicitly:
# scala_config(scala_version = "2.11.12")
scala_config()

Changing my WORKSPACE.bazel to

load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
# Stores Scala version and other configuration
# 2.12 is a default version, other versions can be use by passing them explicitly:
scala_config(scala_version = "3.2.2")                               # https://www.scala-lang.org/download/all.html

resolves that problem... but leads to different problems

hello-world % bazel build hello-world-scala
ERROR: Traceback (most recent call last):
        File "/Users/eric.kolotyluk/git/autonomous-iam/poc/concurrency-laboratory/WORKSPACES/hello-world/WORKSPACE.bazel", line 37, column 40, in <toplevel>
                rules_scala_toolchain_deps_repositories(fetch_sources = True)
        File "/private/var/tmp/_bazel_eric.kolotyluk/7fcca268af0986a7b0005b8a8b78f542/external/io_bazel_rules_scala/scala/private/macros/scala_repositories.bzl", line 66, column 17, in rules_scala_toolchain_deps_repositories
                repositories(
        File "/private/var/tmp/_bazel_eric.kolotyluk/7fcca268af0986a7b0005b8a8b78f542/external/io_bazel_rules_scala/third_party/repositories/repositories.bzl", line 54, column 72, in repositories
                repository_scala_version = scala_version_by_major_scala_version[SCALA_MAJOR_VERSION]
Error: key "3.2" not found in dictionary
ERROR: Error computing the main repository mapping: Encountered error while reading extension file 'proto/repositories.bzl': no such package '@rules_proto//proto': error loading package 'external': Could not load //external package
Loading: 

Maybe Scala 3.x is not supported yet? I will report this in a separate issue.

liucijus commented 1 year ago

Maybe Scala 3.x is not supported yet? I will report this in a separate issue.

3.2 should be supported on master. Please note that Scala artifacts for version (3.2.2) are not defined in Rules Scala, they need to be provided by your WORKSPACE. You can use external loader like rules_jvm_external

liucijus commented 1 year ago

When it would be better to read

load("@io_bazel_rules_scala//:scala_config.bzl", "scala_config")
# Stores Scala version and other configuration
# 2.12 is a default version, other versions can be use by passing them explicitly:
# scala_config(scala_version = "2.11.12")
scala_config()

A PR to improve the README would be appreciated!

kolotyluk commented 1 year ago

PR https://github.com/bazelbuild/rules_scala/pull/1494

kolotyluk commented 1 year ago

I am still struggling with getting my documentation PR to work...

Doing the CLA from Firefox does not work, but hopefully now my CLA is correct...