Skip to content

Instantly share code, notes, and snippets.

@muller
Last active May 18, 2022 01:04
Show Gist options
  • Save muller/728f3d4c45ec593f1fde4fce19d686ea to your computer and use it in GitHub Desktop.
Save muller/728f3d4c45ec593f1fde4fce19d686ea to your computer and use it in GitHub Desktop.
$ git clone this gist
bazel build ...
node bazel-genfiles/index.js
Build label: 0.5.3-homebrew
Build target: bazel-out/darwin_x86_64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Sun Aug 6 12:54:10 2017 (1502024050)
Build timestamp: 1502024050
Build timestamp as int: 1502024050
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_library", "scala_binary")
scala_library(
name = "sjsir",
srcs = ["Test.scala"],
deps = ["@scalajs//:library"],
data = ["@scalajs//:compiler"],
scalacopts = ["-Xplugin:external/scalajs/lib/scalajs-compiler_2.11.11-0.6.19.jar"],
#scalacopts = ["-Xplugin:$(location @scalajs//:compiler)"], ??? location doesn't seems to be working
)
scala_binary(
name = "linker",
srcs = ["ScalaJsLinker.scala"],
deps = [
"@scalajs_ir//jar",
"@scalajs_tools//jar",
],
main_class = "webapp.ScalaJsLinker",
)
genrule(
name = "index",
tools = [":linker"],
srcs = [":sjsir", "@scalajs//:library"],
cmd = "./$(location :linker) $(location :sjsir) $(location @scalajs//:library) webapp.Test init $@",
outs = ["index.js"],
)
filegroup(
name = "compiler",
srcs = glob(["lib/scalajs-compiler_2.11.11-0.6.19.jar"]),
visibility = ["//visibility:public"],
)
filegroup(
name = "library",
srcs = glob(["lib/scalajs-library_2.11-0.6.19.jar"]),
visibility = ["//visibility:public"],
)
package webapp
import java.io.File
import org.scalajs.core.tools.io._
import org.scalajs.core.tools.linker.{ModuleInitializer, StandardLinker}
import org.scalajs.core.tools.logging.ScalaConsoleLogger
object ScalaJsLinker extends App {
val in = IRFileCache.IRContainer.fromJar(new File(args(0)))
val lib = IRFileCache.IRContainer.fromJar(new File(args(1)))
val sjsirFiles = new IRFileCache().newCache.cached(Seq(in, lib))
StandardLinker(StandardLinker.Config())
.link(sjsirFiles, Seq(ModuleInitializer.mainMethod(args(2), args(3))), WritableFileVirtualJSFile(new File(args(4))), new ScalaConsoleLogger)
}
package webapp
object Test {
def init(): Unit = {
println("Oi!")
}
}
git_repository(
name = "io_bazel_rules_scala",
remote = "https://github.com/bazelbuild/rules_scala.git",
commit = "1947a197f849738d926e609584cfda4ecf669bd9",
)
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
scala_repositories()
new_http_archive(
name = "scalajs",
url = "https://www.scala-js.org/files/scalajs_2.11-0.6.19.tgz",
build_file = "scalajs.BUILD",
strip_prefix = "scalajs_2.11-0.6.19",
)
maven_jar(name = "scalajs_ir", artifact = "org.scala-js:scalajs-ir_2.11:0.6.19")
maven_jar(name = "scalajs_tools", artifact = "org.scala-js:scalajs-tools_2.11:0.6.19")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment