diff --git a/rules/private/phases/phase_semanticdb.bzl b/rules/private/phases/phase_semanticdb.bzl index 3d2d7f87..de0a0862 100644 --- a/rules/private/phases/phase_semanticdb.bzl +++ b/rules/private/phases/phase_semanticdb.bzl @@ -42,13 +42,13 @@ def phase_semanticdb(ctx, g): arguments.add("--compiler_option=-P:semanticdb:failures:error") arguments.add_all( [outputs[0]], - format_each = "--compiler_option=-P:semanticdb:targetroot:%s", + format_each = "--compiler_option_referencing_path=-P:semanticdb:targetroot:%s", map_each = _semanticdb_directory_from_file, ) else: arguments.add_all( [outputs[0]], - format_each = "--compiler_option=-semanticdb-target:%s", + format_each = "--compiler_option_referencing_path=-semanticdb-target:%s", map_each = _semanticdb_directory_from_file, ) diff --git a/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala b/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala index bc52a046..4fa5ffb2 100644 --- a/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala +++ b/src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala @@ -17,6 +17,18 @@ class CommonArguments private ( val compilerBridge: Path, val compilerClasspath: List[Path], val compilerOptions: List[String], + + /** + * With [[https://bazel.build/remote/multiplex#multiplex_sandboxing multiplex sandboxing]], Bazel generates a separate + * sandbox directory for each worker invocation, which means the paths to build artifacts won't be known until the + * execution phase. However, compiler options are usually generated during the analysis phase. + * + * Some compiler options (currently, only those regarding SemanticDB) reference paths to build artifacts and need to + * be adjusted to be relative to the sandbox directory. It's more performant for those options to be passed in a + * separate list so we don't have to scan through every compiler option and potentially modify it. In our experience, + * this resulted in a ~10% worker speedup. + */ + val compilerOptionsReferencingPaths: List[String], val classpath: List[Path], val debug: Boolean, val javaCompilerOptions: List[String], @@ -95,6 +107,11 @@ object CommonArguments { .help("Compiler option") .action(ArgumentsImpl.append) .metavar("option") + parser + .addArgument("--compiler_option_referencing_path") + .help("Compiler option referencing the paths to build artifact(s)") + .action(ArgumentsImpl.append) + .metavar("option") parser .addArgument("--classpath") .help("Compilation classpath") @@ -195,9 +212,14 @@ object CommonArguments { analyses = analyses, compilerBridge = SandboxUtil.getSandboxPath(workDir, namespace.get[Path]("compiler_bridge")), compilerClasspath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("compiler_classpath")), - compilerOptions = adjustCompilerOptions( + compilerOptions = Option(namespace.getList[String]("compiler_option")) + .map(_.asScala.toList) + .getOrElse(List.empty), + compilerOptionsReferencingPaths = adjustCompilerOptions( workDir, - Option(namespace.getList[String]("compiler_option")).map(_.asScala.toList).getOrElse(List.empty), + Option(namespace.getList[String]("compiler_option_referencing_path")) + .map(_.asScala.toList) + .getOrElse(List.empty), ), classpath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("classpath")), debug = namespace.getBoolean("debug"), diff --git a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala index c0313bf7..d7f375c3 100644 --- a/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala +++ b/src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala @@ -216,7 +216,7 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] { .withScalacOptions( Array.concat( workRequest.plugins.map(p => s"-Xplugin:$p").toArray, - workRequest.compilerOptions.toArray, + (workRequest.compilerOptions ++ workRequest.compilerOptionsReferencingPaths).toArray, ), )