Skip to content

Commit

Permalink
Fixes for Windows issues found in the course of bazel-contrib/rules_j…
Browse files Browse the repository at this point in the history
…vm_external#1297: 1) Use platform-specific path separators. 2) Add Kotlin standard library jars to the data of tools so that the Windows Java launcher can find them in the runfiles manifest.
  • Loading branch information
ahumesky committed Feb 13, 2025
1 parent 096170f commit 991e4a5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion kotlin/internal/toolchains.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _kotlin_toolchain_impl(ctx):
kotlinbuilder = ctx.attr.kotlinbuilder,
builder_args = [
"--wrapper_script_flag=--main_advice_classpath=%s" % (
":".join([f.path for f in ctx.files.jvm_stdlibs])
ctx.configuration.host_path_separator.join([f.short_path for f in ctx.files.jvm_stdlibs])
),
],
jdeps_merger = ctx.attr.jdeps_merger,
Expand Down
13 changes: 11 additions & 2 deletions src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
load("//src/main/kotlin:bootstrap.bzl", "kt_bootstrap_binary", "kt_bootstrap_library")

_KOTLIN_STDLIBS = [
"//kotlin/compiler:annotations",
"//kotlin/compiler:kotlin-stdlib",
"//kotlin/compiler:kotlin-stdlib-jdk7",
"//kotlin/compiler:kotlin-stdlib-jdk8",
"//kotlin/compiler:kotlinx-coroutines-core-jvm",
"//kotlin/compiler:trove4j",
]

kt_bootstrap_library(
name = "build_lib",
srcs = ["Build.kt"],
Expand Down Expand Up @@ -28,7 +37,7 @@ kt_bootstrap_binary(
"@kotlinx_serialization_core_jvm//jar",
"@kotlinx_serialization_json//jar",
"@kotlinx_serialization_json_jvm//jar",
],
] + _KOTLIN_STDLIBS,
jvm_flags = [
"-D@com_github_jetbrains_kotlinx...serialization-core-jvm=$(rlocationpath @kotlinx_serialization_core_jvm//jar)",
"-D@com_github_jetbrains_kotlinx...serialization-json=$(rlocationpath @kotlinx_serialization_json//jar)",
Expand Down Expand Up @@ -67,7 +76,7 @@ kt_bootstrap_library(

kt_bootstrap_binary(
name = "merge_jdeps",
data = [],
data = _KOTLIN_STDLIBS,
main_class = "io.bazel.kotlin.builder.cmd.MergeJdeps",
shade_rules = "//src/main/kotlin:shade.jarjar",
visibility = ["//src:__subpackages__"],
Expand Down
19 changes: 11 additions & 8 deletions src/main/starlark/core/compile/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ java_import(
deps = [],
)

_KOTLIN_STDLIBS = [
"//kotlin/compiler:annotations",
"//kotlin/compiler:kotlin-stdlib",
"//kotlin/compiler:kotlin-stdlib-jdk7",
"//kotlin/compiler:kotlin-stdlib-jdk8",
"//kotlin/compiler:kotlinx-coroutines-core-jvm",
"//kotlin/compiler:trove4j",
]

java_binary(
name = "kotlinc",
main_class = "org.jetbrains.kotlin.cli.jvm.K2JVMCompiler",
runtime_deps = [":kotlinc_jar"],
data = _KOTLIN_STDLIBS,
)

cli_toolchain(
name = "cli_toolchain",
api_version = versions.KOTLIN_CURRENT_COMPILER_RELEASE.version,
jvm_target = "11",
kotlin_stdlibs = [
"//kotlin/compiler:annotations",
"//kotlin/compiler:kotlin-stdlib",
"//kotlin/compiler:kotlin-stdlib-jdk7",
"//kotlin/compiler:kotlin-stdlib-jdk8",
"//kotlin/compiler:kotlinx-coroutines-core-jvm",
"//kotlin/compiler:trove4j",
],
kotlin_stdlibs = _KOTLIN_STDLIBS,
kotlinc = ":kotlinc",
language_version = versions.KOTLIN_CURRENT_COMPILER_RELEASE.version,
zip = "@bazel_tools//tools/zip:zipper",
Expand Down
2 changes: 1 addition & 1 deletion src/main/starlark/core/compile/cli/compile.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def compile_kotlin_for_jvm(

# Set the stdlib for the compiler to run on.
args = actions.args().add("--wrapper_script_flag=--main_advice_classpath=%s" % (
":".join([f.path for f in toolchain_info.kotlin_stdlib.transitive_compile_time_jars.to_list()])
path_separator.join([f.short_path for f in toolchain_info.kotlin_stdlib.transitive_compile_time_jars.to_list()])
))
args.add("-d", class_jar)
args.add("-jdk-home", toolchain_info.java_runtime.java_home)
Expand Down

0 comments on commit 991e4a5

Please sign in to comment.