Skip to content

chore: Migrate from bloop-frontend to scala-cli for compilation - #722

Merged
oyvindberg merged 4 commits into
masterfrom
pr/scala-cli
Sep 28, 2025
Merged

chore: Migrate from bloop-frontend to scala-cli for compilation#722
oyvindberg merged 4 commits into
masterfrom
pr/scala-cli

Conversation

@oyvindberg

@oyvindberg oyvindberg commented Sep 28, 2025

Copy link
Copy Markdown
Collaborator

Summary

Replace bloop-frontend with scala-cli for compiling generated Scala.js code, enabling cross-compilation to Scala 3.

Motivation

We need to cross-compile the converter to Scala 3, but we're facing dependency issues:

  • Historical context: We used bloop-frontend for historical reasons as a lightweight compilation solution
  • Scala 3 blocker: bloop-frontend doesn't exist for Scala 3
  • Bloop-rifle alternative: While bloop-rifle exists for Scala 3, it doesn't support Scala 2.12
  • Solution: Migrate to scala-cli which is called through command line

Benefits

  1. Cross-compilation ready: Enables the converter to work with Scala 3
  2. Dramatically simpler dependency graph: Removes complex bloop dependencies
  3. Better maintained: scala-cli is actively developed and well-supported
  4. Consistent tooling: Uses a modern, standard tool in the Scala ecosystem

Important Note

This change does NOT affect the SBT plugin, which continues to use the Scala compiler through SBT's own infrastructure.

Changes

  • Removed BloopCompiler.scala and its dependencies
  • Added ScalaCliCompiler.scala with equivalent functionality
  • Downloads scala-cli binary automatically for the target platform
  • Generates build directives for scala-cli instead of bloop config
  • Added comprehensive tests for different OS/arch combinations

Implementation Details

The ScalaCliCompiler:

  • Downloads the appropriate scala-cli binary for the current platform
  • Generates a temporary build.scala file with scala-cli directives
  • Compiles the generated Scala.js code using scala-cli's built-in compilation
  • Properly handles dependencies through classpath configuration
  • Provides improved logging with pattern matching on output levels

Testing

Added tests covering:

  • Binary download for all supported platforms (macOS, Linux, Windows)
  • Architecture normalization (amd64 → x86_64, arm64 → aarch64)
  • Executable permission verification
  • Binary format validation

Migration Path

This is a drop-in replacement - no changes required to existing code using the compiler interface.

Use java.io.File.pathSeparator instead of hardcoded ':' to properly
handle classpath on Windows (which uses ';' as separator)
Scala-cli creates .bsp (Build Server Protocol) directories that should
not be included in test comparisons, similar to .scala-build directories
@oyvindberg
oyvindberg merged commit bd86bea into master Sep 28, 2025
4 checks passed
@oyvindberg
oyvindberg deleted the pr/scala-cli branch September 28, 2025 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant