diff --git a/prelude/java/java_toolchain.bzl b/prelude/java/java_toolchain.bzl index 7428af94f792..b1579454073a 100644 --- a/prelude/java/java_toolchain.bzl +++ b/prelude/java/java_toolchain.bzl @@ -35,6 +35,7 @@ JavaToolchainInfo = provider( "javacd_debug_port", "javacd_debug_target", "javacd_jvm_args", + "javacd_worker", "java_for_tests", "javac", "javac_protocol", diff --git a/prelude/java/javacd_jar_creator.bzl b/prelude/java/javacd_jar_creator.bzl index 9bf76a7c0786..c4d2dfe98e82 100644 --- a/prelude/java/javacd_jar_creator.bzl +++ b/prelude/java/javacd_jar_creator.bzl @@ -194,10 +194,12 @@ def create_jar_artifact_javacd( qualified_name, java = java_toolchain.java[RunInfo], compiler = java_toolchain.javac[DefaultInfo].default_outputs[0], + worker = java_toolchain.javacd_worker[RunInfo], debug_port = java_toolchain.javacd_debug_port, debug_target = java_toolchain.javacd_debug_target, extra_jvm_args = java_toolchain.javacd_jvm_args, ) + args = cmd_args() args.add( "--action-id", @@ -253,7 +255,7 @@ def create_jar_artifact_javacd( dep_files["classpath_jars"] = classpath_jars_tag actions.run( - cmd_args(exe, args), + args, env = { "BUCK_EVENT_PIPE": event_pipe_out.as_output(), "JAVACD_ABSOLUTE_PATHS_ARE_RELATIVE_TO_CWD": "1", @@ -261,6 +263,7 @@ def create_jar_artifact_javacd( category = "{}javacd_jar".format(category_prefix), identifier = actions_identifier or "", dep_files = dep_files, + exe = exe, ) library_classpath_jars_tag = actions.artifact_tag() diff --git a/prelude/jvm/cd_jar_creator_util.bzl b/prelude/jvm/cd_jar_creator_util.bzl index 369d363f8499..1016f61393bb 100644 --- a/prelude/jvm/cd_jar_creator_util.bzl +++ b/prelude/jvm/cd_jar_creator_util.bzl @@ -378,15 +378,26 @@ def prepare_cd_exe( qualified_name: str.type, java: RunInfo.type, compiler: "artifact", + worker: RunInfo.type, debug_port: [int.type, None], debug_target: ["label", None], - extra_jvm_args: [str.type]) -> cmd_args.type: - debug_args = [] + extra_jvm_args: [str.type]) -> [WorkerRunInfo.type, RunInfo.type]: + jvm_args = extra_jvm_args + ["-XX:-MaxFDLimit"] if debug_port and qualified_name.startswith(base_qualified_name(debug_target)): + # Do not use a worker when debugging is enabled debug_args = ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address={}".format(debug_port)] - jvm_args = extra_jvm_args + ["-XX:-MaxFDLimit"] - - return cmd_args([java, debug_args, jvm_args, "-jar", compiler]) + return cmd_args([java, debug_args, jvm_args, "-jar", compiler]) + else: + worker_run_info = WorkerRunInfo( + # Specifies the command to compile using a non-worker process, on RE or if workers are disabled + exe = cmd_args([java, jvm_args, "-jar", compiler]), + worker = WorkerInfo( + # Specifies the command to initialize a new worker process. + # This is used for local execution if `build.use_persistent_workers=True` + exe = worker, + ), + ) + return worker_run_info # If there's additional compiled srcs, we need to merge them in and if the # caller specified an output artifact we need to make sure the jar is in that diff --git a/prelude/kotlin/kotlin_toolchain.bzl b/prelude/kotlin/kotlin_toolchain.bzl index eb181bb74728..cc45c5375069 100644 --- a/prelude/kotlin/kotlin_toolchain.bzl +++ b/prelude/kotlin/kotlin_toolchain.bzl @@ -21,6 +21,7 @@ KotlinToolchainInfo = provider( "kotlincd_debug_port", "kotlincd_debug_target", "kotlincd_jvm_args", + "kotlincd_worker", "kotlin_stdlib", "kotlin_home_libraries", "kosabi_stubs_gen_plugin", diff --git a/prelude/kotlin/kotlincd_jar_creator.bzl b/prelude/kotlin/kotlincd_jar_creator.bzl index b18fa3d7fc18..386b7f87f7ec 100644 --- a/prelude/kotlin/kotlincd_jar_creator.bzl +++ b/prelude/kotlin/kotlincd_jar_creator.bzl @@ -223,10 +223,12 @@ def create_jar_artifact_kotlincd( qualified_name, java = java_toolchain.java[RunInfo], compiler = kotlin_toolchain.kotlinc[DefaultInfo].default_outputs[0], + worker = kotlin_toolchain.kotlincd_worker[RunInfo], debug_port = kotlin_toolchain.kotlincd_debug_port, debug_target = kotlin_toolchain.kotlincd_debug_target, extra_jvm_args = kotlin_toolchain.kotlincd_jvm_args, ) + args = cmd_args() args.add( "--action-id", @@ -277,7 +279,7 @@ def create_jar_artifact_kotlincd( dep_files["classpath_jars"] = classpath_jars_tag actions.run( - cmd_args(exe, args), + args, env = { "BUCK_EVENT_PIPE": event_pipe_out.as_output(), "JAVACD_ABSOLUTE_PATHS_ARE_RELATIVE_TO_CWD": "1", @@ -285,6 +287,7 @@ def create_jar_artifact_kotlincd( category = "{}kotlincd_jar".format(category_prefix), identifier = actions_identifier, dep_files = dep_files, + exe = exe, ) library_classpath_jars_tag = actions.artifact_tag()