From 925643133f322c7a0e27bf3b4457bd7248947079 Mon Sep 17 00:00:00 2001 From: AutomatedTester Date: Fri, 15 May 2026 17:54:44 +0100 Subject: [PATCH 1/3] [dotnet] include snupkg files when packaging things up --- dotnet/private/nuget_pack.bzl | 5 +++++ dotnet/private/nuget_push.bzl | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/dotnet/private/nuget_pack.bzl b/dotnet/private/nuget_pack.bzl index 67e7b2e6d5294..76b2ed92f8fac 100644 --- a/dotnet/private/nuget_pack.bzl +++ b/dotnet/private/nuget_pack.bzl @@ -1,6 +1,7 @@ load("@rules_dotnet//dotnet/private:common.bzl", "is_debug") load("@rules_dotnet//dotnet/private:providers.bzl", "DotnetAssemblyRuntimeInfo") load(":dotnet_utils.bzl", "dotnet_preamble") +load(":providers.bzl", "NugetPackageInfo") _CSPROJ_TEMPLATE = """\ @@ -134,6 +135,10 @@ def nuget_pack_impl(ctx): files = depset([pkg, symbols_pkg]), runfiles = ctx.runfiles(files = [pkg, symbols_pkg]), ), + NugetPackageInfo( + package = pkg, + symbols = symbols_pkg, + ), ] nuget_pack = rule( diff --git a/dotnet/private/nuget_push.bzl b/dotnet/private/nuget_push.bzl index 9bc2510c6997a..b2226be1d5e56 100644 --- a/dotnet/private/nuget_push.bzl +++ b/dotnet/private/nuget_push.bzl @@ -38,6 +38,8 @@ def _create_unix_script(ctx, dotnet, nupkg_files): """Create bash script for Unix/macOS/Linux.""" push_commands = [] for nupkg in nupkg_files: + if nupkg.basename.endswith(".snupkg"): + continue nupkg_runfiles_path = _to_runfiles_path(nupkg.short_path) push_commands.append( '"$DOTNET" nuget push "$RUNFILES_DIR/{nupkg}" --api-key "$NUGET_API_KEY" --source "$NUGET_SOURCE" --skip-duplicate'.format(nupkg = nupkg_runfiles_path), @@ -77,6 +79,8 @@ def _create_windows_script(ctx, dotnet, nupkg_files): """Create batch script for Windows.""" push_commands = [] for nupkg in nupkg_files: + if nupkg.basename.endswith(".snupkg"): + continue nupkg_runfiles_path = _to_runfiles_path(nupkg.short_path).replace("/", "\\") push_commands.append( '"%%DOTNET%%" nuget push "%%~dp0%s" --api-key "%%NUGET_API_KEY%%" --source "%%NUGET_SOURCE%%" --skip-duplicate' % nupkg_runfiles_path, @@ -107,7 +111,7 @@ nuget_push = rule( "packages": attr.label_list( doc = "The nupkg files to push", mandatory = True, - allow_files = [".nupkg"], + allow_files = [".nupkg", ".snupkg"], ), "_windows_constraint": attr.label( default = "@platforms//os:windows", From f32994cacb8bd5ba112c5a6282b5e04d744aa1f3 Mon Sep 17 00:00:00 2001 From: AutomatedTester Date: Fri, 15 May 2026 18:58:43 +0100 Subject: [PATCH 2/3] Handle sourcelink for builds --- dotnet/defs.bzl | 2 ++ dotnet/src/support/BUILD.bazel | 4 ++-- dotnet/src/webdriver/BUILD.bazel | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dotnet/defs.bzl b/dotnet/defs.bzl index 21eafd37b5452..c7ba6967535fc 100644 --- a/dotnet/defs.bzl +++ b/dotnet/defs.bzl @@ -9,6 +9,7 @@ load("//dotnet/private:nuget_pack.bzl", _nuget_pack = "nuget_pack") load("//dotnet/private:nuget_package.bzl", _nuget_package = "nuget_package") load("//dotnet/private:nuget_push.bzl", _nuget_push = "nuget_push") load("//dotnet/private:paket_deps.bzl", _paket_deps = "paket_deps") +load("//dotnet/private:sourcelink.bzl", _csharp_sourcelink_library = "csharp_sourcelink_library") def devtools_version_targets(): targets = [] @@ -18,6 +19,7 @@ def devtools_version_targets(): csharp_binary = _csharp_binary csharp_library = _csharp_library +csharp_sourcelink_library = _csharp_sourcelink_library csharp_test = _csharp_test dotnet_format = _dotnet_format dotnet_nunit_test_suite = _dotnet_nunit_test_suite diff --git a/dotnet/src/support/BUILD.bazel b/dotnet/src/support/BUILD.bazel index 214d4ca33f227..5327c80153295 100644 --- a/dotnet/src/support/BUILD.bazel +++ b/dotnet/src/support/BUILD.bazel @@ -1,6 +1,6 @@ load( "//dotnet:defs.bzl", - "csharp_library", + "csharp_sourcelink_library", "generated_assembly_info", "nuget_pack", "nuget_package", @@ -26,7 +26,7 @@ generated_assembly_info( version = ASSEMBLY_VERSION, ) -csharp_library( +csharp_sourcelink_library( name = "support", srcs = glob([ "**/*.cs", diff --git a/dotnet/src/webdriver/BUILD.bazel b/dotnet/src/webdriver/BUILD.bazel index 13d35973a9562..3eb9ed6cd4eb4 100644 --- a/dotnet/src/webdriver/BUILD.bazel +++ b/dotnet/src/webdriver/BUILD.bazel @@ -1,5 +1,5 @@ load("//common:defs.bzl", "copy_file") -load("//dotnet:defs.bzl", "csharp_library", "devtools_version_targets", "generated_assembly_info", "generated_resource_utilities", "nuget_pack", "nuget_package") +load("//dotnet:defs.bzl", "csharp_sourcelink_library", "devtools_version_targets", "generated_assembly_info", "generated_resource_utilities", "nuget_pack", "nuget_package") load( "//dotnet:version.bzl", "ASSEMBLY_COMPANY", @@ -41,7 +41,7 @@ generated_resource_utilities( }, ) -csharp_library( +csharp_sourcelink_library( name = "webdriver-net462", srcs = [ ":assembly-info", @@ -72,7 +72,7 @@ csharp_library( ], ) -csharp_library( +csharp_sourcelink_library( name = "webdriver-netstandard2.0", srcs = [ ":assembly-info", @@ -104,7 +104,7 @@ csharp_library( ], ) -csharp_library( +csharp_sourcelink_library( name = "webdriver-net8.0", srcs = [ ":assembly-info", From d6d1ae699ff9aafaf54c42fe9878866ec08630ec Mon Sep 17 00:00:00 2001 From: AutomatedTester Date: Fri, 15 May 2026 18:59:13 +0100 Subject: [PATCH 3/3] include the sourcelink work --- dotnet/private/sourcelink.bzl | 93 +++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 dotnet/private/sourcelink.bzl diff --git a/dotnet/private/sourcelink.bzl b/dotnet/private/sourcelink.bzl new file mode 100644 index 0000000000000..1fb655fa9eca0 --- /dev/null +++ b/dotnet/private/sourcelink.bzl @@ -0,0 +1,93 @@ +"""C# library rule with SourceLink metadata embedded in PDB files.""" + +load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") +load("@rules_dotnet//dotnet/private:common.bzl", "is_debug") +load("@rules_dotnet//dotnet/private/rules/common:attrs.bzl", "CSHARP_LIBRARY_COMMON_ATTRS") +load("@rules_dotnet//dotnet/private/rules/common:library.bzl", "build_library") +load("@rules_dotnet//dotnet/private/rules/csharp/actions:csharp_assembly.bzl", "AssemblyAction") +load("@rules_dotnet//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition") + +def _generate_sourcelink_json(ctx): + output = ctx.actions.declare_file(ctx.label.name + "_sourcelink.json") + ctx.actions.run_shell( + inputs = [ctx.version_file], + outputs = [output], + command = """ +COMMIT=$(grep "^STABLE_GIT_REVISION " "{status}" | cut -d' ' -f2 | tr -d '*') +[ -z "$COMMIT" ] && COMMIT=HEAD +printf '{{"documents":{{"*":"{repo}/raw/%s/*"}}}}\\n' "$COMMIT" > "{output}" +""".format( + status = ctx.version_file.path, + repo = ctx.attr.repo_url.rstrip("/"), + output = output.path, + ), + mnemonic = "GenSourcelinkJson", + progress_message = "Generating sourcelink.json for " + str(ctx.label), + ) + return output + +def _compile_action(ctx, tfm): + toolchain = ctx.toolchains["@rules_dotnet//dotnet:toolchain_type"] + is_windows = ctx.target_platform_has_constraint( + ctx.attr._windows_constraint[platform_common.ConstraintValueInfo], + ) + sourcelink_json = _generate_sourcelink_json(ctx) + return AssemblyAction( + ctx.actions, + ctx.executable._compiler_wrapper_bat if is_windows else ctx.executable._compiler_wrapper_sh, + label = ctx.label, + additionalfiles = ctx.files.additionalfiles, + debug = is_debug(ctx), + defines = ctx.attr.defines, + deps = ctx.attr.deps, + exports = ctx.attr.exports, + targeting_pack = ctx.attr._targeting_pack[0], + internals_visible_to = ctx.attr.internals_visible_to, + keyfile = ctx.file.keyfile, + langversion = ctx.attr.langversion, + resources = ctx.files.resources, + srcs = ctx.files.srcs, + data = ctx.files.data, + appsetting_files = [], + compile_data = ctx.files.compile_data + [sourcelink_json], + out = ctx.attr.out, + target = "library", + target_name = ctx.attr.name, + target_framework = tfm, + toolchain = toolchain, + strict_deps = toolchain.strict_deps[BuildSettingInfo].value, + generate_documentation_file = ctx.attr.generate_documentation_file, + include_host_model_dll = False, + treat_warnings_as_errors = ctx.attr.treat_warnings_as_errors, + warnings_as_errors = ctx.attr.warnings_as_errors, + warnings_not_as_errors = ctx.attr.warnings_not_as_errors, + warning_level = ctx.attr.warning_level, + nowarn = ctx.attr.nowarn, + project_sdk = ctx.attr.project_sdk, + allow_unsafe_blocks = ctx.attr.allow_unsafe_blocks, + nullable = ctx.attr.nullable, + run_analyzers = ctx.attr.run_analyzers, + is_analyzer = ctx.attr.is_analyzer, + is_language_specific_analyzer = ctx.attr.is_language_specific_analyzer, + analyzer_configs = ctx.files.analyzer_configs, + compiler_options = ctx.attr.compiler_options + ["/sourcelink:" + sourcelink_json.path], + is_windows = is_windows, + ) + +def _csharp_sourcelink_library_impl(ctx): + return build_library(ctx, _compile_action) + +_SOURCELINK_ATTRS = dict(CSHARP_LIBRARY_COMMON_ATTRS) +_SOURCELINK_ATTRS["repo_url"] = attr.string( + doc = "Source repository URL for SourceLink metadata (e.g. https://github.com/owner/repo).", + default = "https://github.com/SeleniumHQ/selenium", +) + +csharp_sourcelink_library = rule( + _csharp_sourcelink_library_impl, + doc = "Compile a C# DLL with SourceLink metadata embedded in the PDB.", + attrs = _SOURCELINK_ATTRS, + executable = False, + toolchains = ["@rules_dotnet//dotnet:toolchain_type"], + cfg = tfm_transition, +)