From 89a9ae8bf4eb18198a3cfd31ec43c289b3846397 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Fri, 25 Apr 2025 17:18:09 +0200 Subject: [PATCH 1/2] Bazel: update `rules_kotlin` to 2.1.3 --- MODULE.bazel | 2 +- .../rules_kotlin/2.1.3-codeql.1/MODULE.bazel | 35 +++++++++++++++++++ .../codeql_add_language_version_option.patch | 32 +++++++++++++++++ .../patches/codeql_do_not_emit_jdeps.patch | 16 +++++++++ .../rules_kotlin/2.1.3-codeql.1/source.json | 9 +++++ .../modules/rules_kotlin/metadata.json | 1 + 6 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/MODULE.bazel create mode 100644 misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_add_language_version_option.patch create mode 100644 misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_do_not_emit_jdeps.patch create mode 100644 misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/source.json diff --git a/MODULE.bazel b/MODULE.bazel index ae00bca4390d..7e8e36b53092 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -24,7 +24,7 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "absl") bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json") bazel_dep(name = "fmt", version = "10.0.0") -bazel_dep(name = "rules_kotlin", version = "2.0.0-codeql.1") +bazel_dep(name = "rules_kotlin", version = "2.1.3-codeql.1") bazel_dep(name = "gazelle", version = "0.40.0") bazel_dep(name = "rules_dotnet", version = "0.17.4") bazel_dep(name = "googletest", version = "1.14.0.bcr.1") diff --git a/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/MODULE.bazel b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/MODULE.bazel new file mode 100644 index 000000000000..41bef52cf9f6 --- /dev/null +++ b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/MODULE.bazel @@ -0,0 +1,35 @@ +module( + name = "rules_kotlin", + version = "2.1.3-codeql.1", + compatibility_level = 1, + repo_name = "rules_kotlin", +) + +bazel_dep(name = "platforms", version = "0.0.11") +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "rules_java", version = "7.2.0") +bazel_dep(name = "rules_python", version = "0.23.1") +bazel_dep(name = "rules_cc", version = "0.0.8") +bazel_dep(name = "rules_android", version = "0.1.1") + +rules_kotlin_extensions = use_extension( + "//src/main/starlark/core/repositories:bzlmod_setup.bzl", + "rules_kotlin_extensions", +) +use_repo( + rules_kotlin_extensions, + "com_github_google_ksp", + "com_github_jetbrains_kotlin", + "com_github_pinterest_ktlint", + "kotlinx_serialization_core_jvm", + "kotlinx_serialization_json", + "kotlinx_serialization_json_jvm", +) + +register_toolchains("//kotlin/internal:default_toolchain") + +# TODO(bencodes) We should be able to remove this once rules_android has rolled out official Bzlmod support +remote_android_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "remote_android_tools_extensions") +use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools") + +bazel_dep(name = "rules_proto", version = "5.3.0-21.7") diff --git a/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_add_language_version_option.patch b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_add_language_version_option.patch new file mode 100644 index 000000000000..b0bf85d4faef --- /dev/null +++ b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_add_language_version_option.patch @@ -0,0 +1,32 @@ +diff --git a/src/main/starlark/core/options/opts.kotlinc.bzl b/src/main/starlark/core/options/opts.kotlinc.bzl +index 76df826..ef2d6ca 100644 +--- a/src/main/starlark/core/options/opts.kotlinc.bzl ++++ b/src/main/starlark/core/options/opts.kotlinc.bzl +@@ -33,6 +33,11 @@ def _map_jdk_release_to_flag(version): + return None + return ["-Xjdk-release=%s" % version] + ++def _map_language_version_to_flag(version): ++ if not version: ++ return None ++ return ["-language-version=%s" % version, "-api-version=%s" % version] ++ + _KOPTS_ALL = { + "warn": struct( + args = dict( +@@ -429,6 +434,15 @@ _KOPTS_ALL = { + value_to_flag = None, + map_value_to_flag = _map_jdk_release_to_flag, + ), ++ "language_version": struct( ++ args = dict( ++ default = "1.9", ++ doc = "-language-version", ++ ), ++ type = attr.string, ++ value_to_flag = None, ++ map_value_to_flag = _map_language_version_to_flag, ++ ), + } + + def _merge(key, rule_defined): diff --git a/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_do_not_emit_jdeps.patch b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_do_not_emit_jdeps.patch new file mode 100644 index 000000000000..380c837d06a4 --- /dev/null +++ b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/patches/codeql_do_not_emit_jdeps.patch @@ -0,0 +1,16 @@ +Emitting jdeps is broken for the 2.0.0 kotlin extractor, and we don't need those files. +Patching it here rather than passing `--@rules_kotlin//kotlin/settings:jvm_emit_jdeps=false` +allows us to not have to specify that option (and therefore pull in `rules_kotlin`) in `semmle-code`. +diff --git a/kotlin/settings/BUILD.bazel b/kotlin/settings/BUILD.bazel +index 2c93c11..f352b80 100644 +--- a/kotlin/settings/BUILD.bazel ++++ b/kotlin/settings/BUILD.bazel +@@ -25,7 +25,7 @@ release_archive( + # Flag that controls the emission of jdeps files during kotlin jvm compilation. + bool_flag( + name = "jvm_emit_jdeps", +- build_setting_default = True, # Upstream default behavior ++ build_setting_default = False, + visibility = ["//visibility:public"], + ) + diff --git a/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/source.json b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/source.json new file mode 100644 index 000000000000..8abac8eb4bd1 --- /dev/null +++ b/misc/bazel/registry/modules/rules_kotlin/2.1.3-codeql.1/source.json @@ -0,0 +1,9 @@ +{ + "integrity": "sha256-4USKVrJGJAeyaI3qht9cN1s2oJkb1HjC3dlMlxaBJeI=", + "url": "https://github.com/bazelbuild/rules_kotlin/releases/download/v2.1.3/rules_kotlin-v2.1.3.tar.gz", + "patches": { + "codeql_do_not_emit_jdeps.patch": "sha256-1ir4Aio1SICxnj1wafQ0GefT/m7bwn2n+SQwq19V3A8=", + "codeql_add_language_version_option.patch": "sha256-F7RthnrO6kJlCNcQ76L1Utqll2OwyeFZ/HmT82NwgB4=" + }, + "patch_strip": 1 +} diff --git a/misc/bazel/registry/modules/rules_kotlin/metadata.json b/misc/bazel/registry/modules/rules_kotlin/metadata.json index ac259b2e729a..3e11b7df8202 100644 --- a/misc/bazel/registry/modules/rules_kotlin/metadata.json +++ b/misc/bazel/registry/modules/rules_kotlin/metadata.json @@ -21,6 +21,7 @@ "github:bazelbuild/rules_kotlin" ], "versions": [ + "2.1.3-codeql.1", "2.0.0-codeql.1" ], "yanked_versions": {} From 4ac104060ec07b47dc7a752cc22d73432c9b1f17 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 28 Apr 2025 10:22:11 +0200 Subject: [PATCH 2/2] Bazel: remove `2.0.0` `rules_kotlin` patching --- .../rules_kotlin/2.0.0-codeql.1/MODULE.bazel | 35 ------------------- .../codeql_add_language_version_option.patch | 34 ------------------ .../patches/codeql_do_not_emit_jdeps.patch | 16 --------- .../rules_kotlin/2.0.0-codeql.1/source.json | 9 ----- .../modules/rules_kotlin/metadata.json | 3 +- 5 files changed, 1 insertion(+), 96 deletions(-) delete mode 100644 misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/MODULE.bazel delete mode 100644 misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_add_language_version_option.patch delete mode 100644 misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_do_not_emit_jdeps.patch delete mode 100644 misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/source.json diff --git a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/MODULE.bazel b/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/MODULE.bazel deleted file mode 100644 index 6c11301e2340..000000000000 --- a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/MODULE.bazel +++ /dev/null @@ -1,35 +0,0 @@ -module( - name = "rules_kotlin", - version = "2.0.0-codeql.1", - compatibility_level = 1, - repo_name = "rules_kotlin", -) - -bazel_dep(name = "platforms", version = "0.0.10") -bazel_dep(name = "bazel_skylib", version = "1.7.1") -bazel_dep(name = "rules_java", version = "7.2.0") -bazel_dep(name = "rules_python", version = "0.23.1") -bazel_dep(name = "rules_cc", version = "0.0.8") -bazel_dep(name = "rules_android", version = "0.1.1") - -rules_kotlin_extensions = use_extension( - "//src/main/starlark/core/repositories:bzlmod_setup.bzl", - "rules_kotlin_extensions", -) -use_repo( - rules_kotlin_extensions, - "com_github_google_ksp", - "com_github_jetbrains_kotlin", - "com_github_pinterest_ktlint", - "kotlinx_serialization_core_jvm", - "kotlinx_serialization_json", - "kotlinx_serialization_json_jvm", -) - -register_toolchains("//kotlin/internal:default_toolchain") - -# TODO(bencodes) We should be able to remove this once rules_android has rolled out official Bzlmod support -remote_android_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "remote_android_tools_extensions") -use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools") - -bazel_dep(name = "rules_proto", version = "5.3.0-21.7") diff --git a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_add_language_version_option.patch b/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_add_language_version_option.patch deleted file mode 100644 index d5716daba07b..000000000000 --- a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_add_language_version_option.patch +++ /dev/null @@ -1,34 +0,0 @@ -We need to build different extractor variants with different -language-version options, which is not allowed -in current kotlin_rules -diff --git a/src/main/starlark/core/options/opts.kotlinc.bzl b/src/main/starlark/core/options/opts.kotlinc.bzl -index 5e1461b..b93e6aa 100644 ---- a/src/main/starlark/core/options/opts.kotlinc.bzl -+++ b/src/main/starlark/core/options/opts.kotlinc.bzl -@@ -33,6 +33,11 @@ def _map_jdk_release_to_flag(version): - return None - return ["-Xjdk-release=%s" % version] - -+def _map_language_version_to_flag(version): -+ if not version: -+ return None -+ return ["-language-version=%s" % version, "-api-version=%s" % version] -+ - _KOPTS_ALL = { - "warn": struct( - args = dict( -@@ -417,6 +422,15 @@ _KOPTS_ALL = { - value_to_flag = None, - map_value_to_flag = _map_jdk_release_to_flag, - ), -+ "language_version": struct( -+ args = dict( -+ default = "1.9", -+ doc = "-language-version", -+ ), -+ type = attr.string, -+ value_to_flag = None, -+ map_value_to_flag = _map_language_version_to_flag, -+ ), - } - - # Filters out options that are not available in current compiler release \ No newline at end of file diff --git a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_do_not_emit_jdeps.patch b/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_do_not_emit_jdeps.patch deleted file mode 100644 index 380c837d06a4..000000000000 --- a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/patches/codeql_do_not_emit_jdeps.patch +++ /dev/null @@ -1,16 +0,0 @@ -Emitting jdeps is broken for the 2.0.0 kotlin extractor, and we don't need those files. -Patching it here rather than passing `--@rules_kotlin//kotlin/settings:jvm_emit_jdeps=false` -allows us to not have to specify that option (and therefore pull in `rules_kotlin`) in `semmle-code`. -diff --git a/kotlin/settings/BUILD.bazel b/kotlin/settings/BUILD.bazel -index 2c93c11..f352b80 100644 ---- a/kotlin/settings/BUILD.bazel -+++ b/kotlin/settings/BUILD.bazel -@@ -25,7 +25,7 @@ release_archive( - # Flag that controls the emission of jdeps files during kotlin jvm compilation. - bool_flag( - name = "jvm_emit_jdeps", -- build_setting_default = True, # Upstream default behavior -+ build_setting_default = False, - visibility = ["//visibility:public"], - ) - diff --git a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/source.json b/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/source.json deleted file mode 100644 index 96d828e3455a..000000000000 --- a/misc/bazel/registry/modules/rules_kotlin/2.0.0-codeql.1/source.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "integrity": "sha256-2JcjzJ67t72y66yhr30jg+B0YVZDz5ejZrdYp2t9xEM=", - "url": "https://github.com/bazelbuild/rules_kotlin/releases/download/v2.0.0/rules_kotlin-v2.0.0.tar.gz", - "patches": { - "codeql_do_not_emit_jdeps.patch": "sha256-1ir4Aio1SICxnj1wafQ0GefT/m7bwn2n+SQwq19V3A8=", - "codeql_add_language_version_option.patch": "sha256-t8Fm0bYZ4Q4vTqcoXZjyK4WPEoAafjE4whJLNnrnRbg=" - }, - "patch_strip": 1 -} diff --git a/misc/bazel/registry/modules/rules_kotlin/metadata.json b/misc/bazel/registry/modules/rules_kotlin/metadata.json index 3e11b7df8202..dace87c72d1c 100644 --- a/misc/bazel/registry/modules/rules_kotlin/metadata.json +++ b/misc/bazel/registry/modules/rules_kotlin/metadata.json @@ -21,8 +21,7 @@ "github:bazelbuild/rules_kotlin" ], "versions": [ - "2.1.3-codeql.1", - "2.0.0-codeql.1" + "2.1.3-codeql.1" ], "yanked_versions": {} }