Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

next-assembly-info-files #316

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions dotnet/private/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ DotnetAssemblyInfo = provider(
"irefs": "list[File]: Reference-only assemblies containing public and internal symbols. See docs/ReferenceAssemblies.md for more info.",
"analyzers": "list[File]: Analyzer dlls",
"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.",
"files": "list[File]: All files in the assembly",
"data": "list[File]: Runtime data files",
"compile_data": "list[File]: Compile data files",
"exports": "list[File]",
Expand Down Expand Up @@ -61,3 +62,24 @@ DotnetPublishBinaryInfo = provider(
"self_contained": "bool: True if the binary is self-contained",
},
)

DotnetCompileInfo = provider(
doc = "Information about how a .Net target is to be compiled",
fields = {
"label": "Label: The label of the target",
"sources": "list[File]: sources to be compiled",
"deps": "list[DotnetCompileDepVariantInfo]: The direct dependencies of the target",
"transitive_deps": "depset[DotnetCompileDepVariantInfo]: The transitive dependencies of the target",
},
)

DotnetCompileDepVariantInfo = provider(
doc = "A wrapper provider for a compilation dependency. The dependency can be a project " +
"dependency, in which case the `dotnet_compile_info` will be populated" +
"or a NuGet dependency, in which case `dotnet_assembly_info` will be populated.",
fields = {
"label": "Label: The label of the dependency",
"dotnet_compile_info": "DotnetCompileInfo: The DotnetCompileInfo of a dependency",
"dotnet_assembly_info": "DotnetAssemblyInfo: The NuGet info of a dependency",
},
)
11 changes: 9 additions & 2 deletions dotnet/private/rules/common/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
Base rule for building .Net binaries
"""

load("//dotnet/private:providers.bzl", "DotnetBinaryInfo")
load("//dotnet/private:providers.bzl", "DotnetBinaryInfo", "DotnetAssemblyInfo", "NuGetInfo", "DotnetCompileInfo", "DotnetCompileDepVariantInfo")

load(
"//dotnet/private:common.bzl",
"generate_depsjson",
"generate_runtimeconfig",
"is_core_framework",
"is_standard_framework",
)
load(
"//dotnet/private/rules/common:compile_info.bzl",
"gather_compile_info"
)
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path")
Expand Down Expand Up @@ -160,4 +165,6 @@ def build_binary(ctx, compile_action):
app_host = app_host,
)

return [default_info, dotnet_binary_info, result]
dotnet_compile_info = gather_compile_info(ctx)

return [default_info, dotnet_binary_info, dotnet_compile_info, result]
44 changes: 44 additions & 0 deletions dotnet/private/rules/common/compile_info.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
load("//dotnet/private:providers.bzl", "DotnetBinaryInfo", "DotnetAssemblyInfo", "NuGetInfo", "DotnetCompileInfo", "DotnetCompileDepVariantInfo")

load(
"//dotnet/private:common.bzl",
"generate_depsjson",
"generate_runtimeconfig",
"is_core_framework",
"is_standard_framework",
)
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path")


def gather_compile_info(ctx):
direct_deps = []
transitive_deps = []

for dep in ctx.attr.deps:
if DotnetCompileInfo in dep:
variant = DotnetCompileDepVariantInfo(
label = dep.label,
dotnet_compile_info = dep[DotnetCompileInfo],
dotnet_assembly_info = None,
)

direct_deps.append(variant)
transitive_deps.append(depset(dep[DotnetCompileInfo].deps, transitive = [ dep[DotnetCompileInfo].transitive_deps ]))

if NuGetInfo in dep and DotnetAssemblyInfo in dep:
variant = DotnetCompileDepVariantInfo(
label = dep.label,
dotnet_compile_info = None,
dotnet_assembly_info = dep[DotnetAssemblyInfo],
)

direct_deps.append(variant)

return DotnetCompileInfo(
label = ctx.label,
sources = ctx.files.srcs,
deps = direct_deps,
transitive_deps = depset([], transitive = transitive_deps),
)
8 changes: 8 additions & 0 deletions dotnet/private/rules/common/library.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"Common implementation for building .Net libraries"

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//dotnet/private:providers.bzl", "DotnetCompileInfo")
load(
"//dotnet/private/rules/common:compile_info.bzl",
"gather_compile_info"
)

def build_library(ctx, compile_action):
"""Builds a .Net library from a compilation action
Expand Down Expand Up @@ -33,4 +38,7 @@ def build_library(ctx, compile_action):
),
))

dotnet_compile_info = gather_compile_info(ctx)
result.append(dotnet_compile_info)

return result
1 change: 1 addition & 0 deletions dotnet/private/rules/csharp/actions/csharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def AssemblyAction(
irefs = [out_iref] if out_iref else [out_ref],
analyzers = [],
internals_visible_to = internals_visible_to or [],
files = [],
data = data,
compile_data = compile_data,
native = [],
Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/fsharp/actions/fsharp_assembly.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def AssemblyAction(
irefs = [out_dll],
analyzers = [],
internals_visible_to = internals_visible_to or [],
files = srcs,
data = data,
compile_data = compile_data,
native = [],
Expand Down
2 changes: 1 addition & 1 deletion dotnet/private/rules/fsharp/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _library_impl(ctx):

fsharp_library = rule(
_library_impl,
doc = "Compile a F# DLL",
doc = "Compile an F# DLL",
attrs = FSHARP_LIBRARY_COMMON_ATTRS,
executable = False,
toolchains = ["@rules_dotnet//dotnet:toolchain_type"],
Expand Down
6 changes: 6 additions & 0 deletions dotnet/private/rules/nuget/imports.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def _import_library(ctx):
irefs = ctx.files.refs,
analyzers = ctx.files.analyzers,
native = ctx.files.native,
files = ctx.files.files,
data = ctx.files.data,
compile_data = [],
exports = [],
Expand Down Expand Up @@ -95,6 +96,10 @@ import_library = rule(
doc = "Other DLLs that this DLL depends on.",
providers = [DotnetAssemblyInfo],
),
"files": attr.label_list(
doc = "All files in the package",
allow_files = True,
),
"data": attr.label_list(
doc = "Other files that this DLL depends on at runtime",
allow_files = True,
Expand Down Expand Up @@ -123,6 +128,7 @@ def _import_dll(ctx):
irefs = [],
analyzers = [],
native = [],
files = [],
data = [],
compile_data = [],
exports = [],
Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/nuget/nuget_archive.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ load("@rules_dotnet//dotnet/private/rules/nuget:nuget_archive.bzl", "tfm_filegro
_create_framework_select("libs", groups.get("lib")) or "filegroup(name = \"libs\", srcs = [])",
_create_framework_select("refs", groups.get("ref")) or _create_framework_select("refs", groups.get("lib")) or "filegroup(name = \"refs\", srcs = [])",
"filegroup(name = \"analyzers\", srcs = [%s])" % ",".join(["\n \"%s\"" % a for a in groups.get("analyzers")["dotnet"]]),
"filegroup(name = \"files\", srcs = glob([\"**\"]))",
"filegroup(name = \"data\", srcs = [])",
_create_rid_native_select("native", groups.get("runtimes")) or "filegroup(name = \"native\", srcs = [])",
"filegroup(name = \"content_files\", srcs = [%s])" % ",".join(["\n \"%s\"" % a for a in groups.get("contentFiles")["any"]]),
Expand Down
1 change: 1 addition & 0 deletions dotnet/private/rules/nuget/template.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package(default_visibility = ["//visibility:public"])
import_library(
name = "{VERSION}",
analyzers = ["@{PREFIX}.{NAME_LOWER}.v{VERSION}//:analyzers"],
files = ["@{PREFIX}.{NAME_LOWER}.v{VERSION}//:files"],
data = ["@{PREFIX}.{NAME_LOWER}.v{VERSION}//:data"],
library_name = "{NAME}",
libs = ["@{PREFIX}.{NAME_LOWER}.v{VERSION}//:libs"],
Expand Down