From a7f4e4e3909035be909788d059a94b0566ed7bea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dan=C3=ADel=20P=2E=20Purkh=C3=BAs?= Date: Wed, 3 Apr 2024 09:21:29 +0000 Subject: [PATCH] WIP --- docs/README.md | 4 -- docs/defs.md | 48 ++++++++++--------- dotnet/defs.bzl | 11 +---- dotnet/private/providers.bzl | 2 - .../rules/publish_binary/publish_binary.bzl | 5 +- dotnet/private/sdk/gen/README.md | 15 +++++- dotnet/private/sdk/gen/TargetingPacks.fs | 1 - dotnet/private/transitions/tfm_transition.bzl | 2 +- examples/aspnetcore/BUILD.bazel | 1 + tools/runfiles/Runfiles.cs | 2 - 10 files changed, 43 insertions(+), 48 deletions(-) diff --git a/docs/README.md b/docs/README.md index 2e230e25..ab44ba86 100644 --- a/docs/README.md +++ b/docs/README.md @@ -80,10 +80,6 @@ proper IDE support the MSBuild project files need to be manually maintained. NuGet packages are fully supported by the rules in two ways -### NuGet packages with packages.lock.json - -TODO: Write or link to documentation on how to use this - ### NuGet packages with Paket [Paket](https://fsprojects.github.io/Paket/) is a great choice for managing dependencies in .Net diff --git a/docs/defs.md b/docs/defs.md index f008ecd2..50bd0870 100644 --- a/docs/defs.md +++ b/docs/defs.md @@ -81,6 +81,31 @@ nuget_archive(name, version | - | String | optional | "" | + + +## publish_binary + +
+publish_binary(name, binary, project_sdk, roll_forward_behavior, runtime_identifier, self_contained,
+               target_framework)
+
+ +Publish a .Net binary + +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| binary | The .Net binary that is being published | Label | required | | +| project_sdk | The project SDK that is being targeted. See https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview | String | optional | "default" | +| roll_forward_behavior | The roll forward behavior that should be used: https://learn.microsoft.com/en-us/dotnet/core/versions/selection#control-roll-forward-behavior | String | optional | "Minor" | +| runtime_identifier | The runtime identifier that is being targeted. See https://docs.microsoft.com/en-us/dotnet/core/rid-catalog | String | optional | "" | +| self_contained | Whether the binary should be self-contained.

If true, the binary will be published as a self-contained but you need to provide a runtime pack in the runtime_packs attribute. At some point the rules might resolve the runtime pack automatically.

If false, the binary will be published as a non-self-contained. That means that to be able to run the binary you need to have a .Net runtime installed on the host system. | Boolean | optional | False | +| target_framework | The target framework that should be published | String | required | | + + ## csharp_binary @@ -298,26 +323,3 @@ nuget_repo(name, p | packages |

-

| none | - - -## publish_binary - -
-publish_binary(name, binary, target_framework, self_contained, runtime_identifier, kwargs)
-
- - - -**PARAMETERS** - - -| Name | Description | Default Value | -| :------------- | :------------- | :------------- | -| name |

-

| none | -| binary |

-

| none | -| target_framework |

-

| none | -| self_contained |

-

| False | -| runtime_identifier |

-

| None | -| kwargs |

-

| none | - - diff --git a/dotnet/defs.bzl b/dotnet/defs.bzl index efa0dcc9..d9c30dad 100644 --- a/dotnet/defs.bzl +++ b/dotnet/defs.bzl @@ -233,16 +233,7 @@ def fsharp_nunit_test( **kwargs ) -def publish_binary(name, binary, target_framework, self_contained = False, runtime_identifier = None, **kwargs): - _publish_binary( - name = "{}".format(name), - binary = binary, - target_framework = target_framework, - self_contained = self_contained, - runtime_identifier = runtime_identifier, - **kwargs - ) - +publish_binary = _publish_binary import_library = _import_library import_dll = _import_dll nuget_repo = _nuget_repo diff --git a/dotnet/private/providers.bzl b/dotnet/private/providers.bzl index 342fa725..f8931a06 100644 --- a/dotnet/private/providers.bzl +++ b/dotnet/private/providers.bzl @@ -11,8 +11,6 @@ DotnetAssemblyCompileInfo = provider( "internals_visible_to": "list[string]: A list of assemblies that can use the assemblies listed in iref for compilation. See docs/ReferenceAssemblies.md for more info.", "compile_data": "list[File]: Compile data files", "exports": "list[File]", - - # TODO: Maybe this should just be deps? "transitive_refs": "depset[File]: Transitive reference-only assemblies containing only public symbols. Only used when strict deps are off.", "transitive_compile_data": "depset[File]: Transitive compile data files. Only used when strict deps are off.", "transitive_analyzers": "depset[File]: Transitive analyzer dlls. Only used when strict deps are off.", diff --git a/dotnet/private/rules/publish_binary/publish_binary.bzl b/dotnet/private/rules/publish_binary/publish_binary.bzl index 4c43e0d3..99b6f82e 100644 --- a/dotnet/private/rules/publish_binary/publish_binary.bzl +++ b/dotnet/private/rules/publish_binary/publish_binary.bzl @@ -145,10 +145,7 @@ def _generate_depsjson( ) def _publish_binary_impl(ctx): - # repo_mapping_manifest is only available in Bazel 7.0+ - repo_mapping_manifest = None - if ctx.attr.binary[0][DefaultInfo].files_to_run and hasattr(ctx.attr.binary[0][DefaultInfo].files_to_run, "repo_mapping_manifest"): - repo_mapping_manifest = ctx.attr.binary[0][DefaultInfo].files_to_run.repo_mapping_manifest + repo_mapping_manifest = ctx.attr.binary[0][DefaultInfo].files_to_run.repo_mapping_manifest assembly_compile_info = ctx.attr.binary[0][DotnetAssemblyCompileInfo] assembly_runtime_info = ctx.attr.binary[0][DotnetAssemblyRuntimeInfo] diff --git a/dotnet/private/sdk/gen/README.md b/dotnet/private/sdk/gen/README.md index dfc22951..3f5989c1 100644 --- a/dotnet/private/sdk/gen/README.md +++ b/dotnet/private/sdk/gen/README.md @@ -1 +1,14 @@ -TODO: Document how to update the SDK versions +# SDK Generation +This program generates the Bazel targets required for rules_dotnet to work with the upstream .Net SDK. + +It does the following: + +1. Updates the available .Net SDK versions so that the end user of rules_dotnet can choose the SDK version they want to use. +2. Updates the avilable runtime identifiers (RIDs) so that the end user of rules_dotnet can choose the RID they want to when publishing. +3. Updates and creates the Bazel targest for the targeting/runtime/apphost packs that are fetched by rules_dotnet when building. + +## Usage + +To run the program simply run the `update-sdk.sh` script + + diff --git a/dotnet/private/sdk/gen/TargetingPacks.fs b/dotnet/private/sdk/gen/TargetingPacks.fs index f6587449..c5f5a258 100644 --- a/dotnet/private/sdk/gen/TargetingPacks.fs +++ b/dotnet/private/sdk/gen/TargetingPacks.fs @@ -138,7 +138,6 @@ let generateTargetingPacksNugetRepo (targetingPacksFile: string) (outputFolder: sha512 = packageInfo.sha512sri sources = [ NugetHelpers.nugetV3Feed ] netrc = None - // TODO: Look into if the dependencies are needed for targeting packs like NETStandard.Library dependencies = Dictionary() targeting_pack_overrides = packageInfo.overrides framework_list = packageInfo.frameworkList }) diff --git a/dotnet/private/transitions/tfm_transition.bzl b/dotnet/private/transitions/tfm_transition.bzl index 8187943d..d8f7cf69 100644 --- a/dotnet/private/transitions/tfm_transition.bzl +++ b/dotnet/private/transitions/tfm_transition.bzl @@ -62,7 +62,7 @@ def _impl(settings, attr): if hasattr(attr, "runtime_identifier") and attr.runtime_identifier != "": runtime_identifier = attr.runtime_identifier elif runtime_identifier == "base": - # If the runtime_identifier attribute is not set and the incoming value is "base", we will use the platform to determine the rid since upstream target has set the runtime identifier + # If the runtime_identifier attribute is not set and the incoming value is "base", we will use the platform to determine the rid since no upstream target has set the runtime identifier runtime_identifier = _platform_to_rid() return dicts.add({"//dotnet:target_framework": transitioned_tfm}, {"//dotnet:rid": runtime_identifier}, FRAMEWORK_COMPATABILITY_TRANSITION_OUTPUTS[transitioned_tfm], RID_COMPATABILITY_TRANSITION_OUTPUTS[runtime_identifier]) diff --git a/examples/aspnetcore/BUILD.bazel b/examples/aspnetcore/BUILD.bazel index 64ba60fd..f641e26c 100644 --- a/examples/aspnetcore/BUILD.bazel +++ b/examples/aspnetcore/BUILD.bazel @@ -21,6 +21,7 @@ csharp_binary( publish_binary( name = "publish", binary = ":aspnetcore", + project_sdk = "web" self_contained = True, target_framework = "net6.0", ) diff --git a/tools/runfiles/Runfiles.cs b/tools/runfiles/Runfiles.cs index 4fb36767..26ac7440 100644 --- a/tools/runfiles/Runfiles.cs +++ b/tools/runfiles/Runfiles.cs @@ -522,7 +522,6 @@ public override IDictionary GetEnvVars() result.Add("RUNFILES_MANIFEST_FILE", manifestPath); var runfilesDir = findRunfilesDir(manifestPath); result.Add("RUNFILES_DIR", runfilesDir); - // TODO(laszlocsomor): remove JAVA_RUNFILES once the Java launcher can pick up RUNFILES_DIR. result.Add("JAVA_RUNFILES", runfilesDir); return result; } @@ -556,7 +555,6 @@ public override IDictionary GetEnvVars() { var result = new Dictionary(2); result.Add("RUNFILES_DIR", runfilesRoot); - // TODO(laszlocsomor): remove JAVA_RUNFILES once the Java launcher can pick up RUNFILES_DIR. result.Add("JAVA_RUNFILES", runfilesRoot); return result; }