Skip to content

Commit

Permalink
Updating .NET build to use new Bazel build rules
Browse files Browse the repository at this point in the history
The rules used for building the .NET binaries can now be found
at https://github.com/Brightspace/rules_csharp. These are not the
"official" Bazel build rules for .NET projects, but they are more
flexible and better suited to the needs of the Selenium project.
Note that they are still somewhat under active development, and
it may be some time before `bazel test` will work with the .NET
portion of Selenium. In the meantime, users can manually use the
NUnit console checked into the `third_party` directory to run
the tests in the .NET test suite.
  • Loading branch information
jimevans committed Oct 17, 2019
1 parent 1c5bdc3 commit 6d9e681
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 356 deletions.
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
closure_repositories()

http_archive(
name = "io_bazel_rules_dotnet",
sha256 = "6c5d7080c61abda66458b51167d20683de220bd486ab37bde5c470acea12de66",
strip_prefix = "rules_dotnet-66b235a05ff23c0c65967453e7722d6d7fa28b1c",
name = "d2l_rules_csharp",
sha256 = "0e688b0f9279855bef3e98657af44c29ac281c510e21919a03ceb69a910ebdf4",
strip_prefix = "rules_csharp-77997bbb79ba4294b1d88ae6f44211df8eb4075e",
urls = [
"https://github.com/jimevans/rules_dotnet/archive/66b235a05ff23c0c65967453e7722d6d7fa28b1c.tar.gz",
"https://github.com/Brightspace/rules_csharp/archive/77997bbb79ba4294b1d88ae6f44211df8eb4075e.tar.gz",
],
)

Expand Down
43 changes: 15 additions & 28 deletions dotnet/merge-assemblies.bzl
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
load(
"@io_bazel_rules_dotnet//dotnet/private:context.bzl",
"dotnet_context"
)
load(
"@io_bazel_rules_dotnet//dotnet/private:providers.bzl",
"DotnetLibrary",
)
load("@d2l_rules_csharp//csharp/private:common.bzl", "collect_transitive_info")

def _merged_assembly_impl(ctx):
dotnet = dotnet_context(ctx)
name = ctx.label.name

deps = ctx.attr.deps
result = ctx.outputs.out

target_framework = ctx.attr.target_framework

args = [
"-ndebug",
"-v4",
"-xmldocs",
"-internalize",
Expand All @@ -26,8 +21,9 @@ def _merged_assembly_impl(ctx):

args.append("-out={}".format(ctx.outputs.out.path))
args.append(ctx.attr.src_assembly.files.to_list()[0].path)
for dep in ctx.files.deps:
args.append(ctx.expand_location(dep.path))
(refs, runfiles, native_dlls) = collect_transitive_info(deps, target_framework)
for ref in refs.to_list():
args.append(ref.path)

ctx.actions.run(
executable = ctx.executable.merge_tool,
Expand All @@ -36,25 +32,16 @@ def _merged_assembly_impl(ctx):
outputs = [ctx.outputs.out]
)

data = depset()

runfiles = depset(direct = [result], transitive = [d[DotnetLibrary].runfiles for d in deps] + [data])
transitive = depset(direct = deps, transitive = [a[DotnetLibrary].transitive for a in deps])

merged_lib = dotnet.new_library(
dotnet = dotnet,
name = name,
deps = deps,
transitive = transitive,
runfiles = runfiles,
result = result,
runfiles = ctx.runfiles(
files = [ctx.outputs.out],
)

for dep in ctx.files.deps:
runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles)

return [
merged_lib,
DefaultInfo(
files = depset([merged_lib.result]),
runfiles = ctx.runfiles(files = [], transitive_files = merged_lib.runfiles),
runfiles = runfiles,
),
]

Expand All @@ -65,13 +52,13 @@ merged_assembly = rule(
"deps": attr.label_list(),
"out": attr.output(mandatory = True),
"keyfile": attr.label(allow_single_file = True),
"dotnet_context_data": attr.label(default = Label("@io_bazel_rules_dotnet//:dotnet_context_data")),
"target_framework": attr.string(mandatory = True),
"merge_tool": attr.label(
executable = True,
cfg = "host",
default = Label("//third_party/dotnet/ilmerge:ilmerge.exe"),
allow_single_file = True
),
},
toolchains = ["@io_bazel_rules_dotnet//dotnet:toolchain_net"],
toolchains = ["//third_party/dotnet/ilmerge:toolchain_type"],
)
5 changes: 0 additions & 5 deletions dotnet/nuget.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
load(
"@io_bazel_rules_dotnet//dotnet/private:context.bzl",
"dotnet_context"
)

def _nuget_package_impl(ctx):
args = [
"pack",
Expand Down
56 changes: 29 additions & 27 deletions dotnet/src/support/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_dotnet//dotnet:defs.bzl", "netstandard_library", "net_library")
load("@d2l_rules_csharp//csharp:defs.bzl", "csharp_library")
load("//dotnet:nuget.bzl", "nuget_package")
load(
"//dotnet:selenium-dotnet-version.bzl",
Expand All @@ -7,7 +7,7 @@ load(
"SUPPORTED_NET_FRAMEWORKS",
)

[net_library(
[csharp_library(
name = "{}".format(framework),
srcs = glob([
"*.cs",
Expand All @@ -16,20 +16,22 @@ load(
"PageObjects/**/*.cs",
"UI/*.cs",
]),
target_frameworks = [
"{}".format(framework),
],
out = "merged/{}/WebDriver.Support.dll".format(framework),
dotnet_context_data = "@io_bazel_rules_dotnet//:net_context_data_{}".format(framework),
visibility = ["//visibility:public"],
deps = [
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.core.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.data.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.drawing.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.xml.dll",
"@net//:System",
"@net//:System.Core",
"@net//:System.Data",
"@net//:System.Drawing",
"@net//:System.Xml",
"//dotnet/src/webdriver:{}assembly".format(framework),
],
) for framework in SUPPORTED_NET_FRAMEWORKS]

netstandard_library(
csharp_library(
name = "netstandard2.0",
srcs = glob([
"*.cs",
Expand All @@ -38,18 +40,17 @@ netstandard_library(
"PageObjects/**/*.cs",
"UI/*.cs",
]),
out = "merged/netstandard2.0/WebDriver.Support.dll",
defines = [
"NETSTANDARD2_0",
target_frameworks = [
"netstandard2.0",
],
out = "merged/netstandard2.0/WebDriver.Support.dll",
visibility = ["//visibility:public"],
deps = [
"//dotnet/src/webdriver:netstandard2.0",
"@io_bazel_rules_dotnet//dotnet/stdlib.netstandard:netstandard.dll",
"//dotnet/src/webdriver:netstandard2.0assembly",
],
)

[net_library(
[csharp_library(
name = "{}-strongnamed".format(framework),
srcs = glob([
"*.cs",
Expand All @@ -58,21 +59,23 @@ netstandard_library(
"PageObjects/**/*.cs",
"UI/*.cs",
]),
target_frameworks = [
"{}".format(framework),
],
out = "strongnamed/{}/WebDriver.Support.dll".format(framework),
dotnet_context_data = "@io_bazel_rules_dotnet//:net_context_data_{}".format(framework),
keyfile = "//dotnet:WebDriver.snk",
visibility = ["//visibility:public"],
deps = [
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.core.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.data.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.drawing.dll",
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.xml.dll",
"@net//:System",
"@net//:System.Core",
"@net//:System.Data",
"@net//:System.Drawing",
"@net//:System.Xml",
"//dotnet/src/webdriver:{}assembly-strongnamed".format(framework),
],
) for framework in SUPPORTED_NET_FRAMEWORKS]

netstandard_library(
csharp_library(
name = "netstandard2.0-strongnamed",
srcs = glob([
"*.cs",
Expand All @@ -81,15 +84,14 @@ netstandard_library(
"PageObjects/**/*.cs",
"UI/*.cs",
]),
out = "strongnamed/netstandard2.0/WebDriver.Support.dll",
defines = [
"NETSTANDARD2_0",
target_frameworks = [
"netstandard2.0",
],
out = "strongnamed/netstandard2.0/WebDriver.Support.dll",
keyfile = "//dotnet:WebDriver.snk",
visibility = ["//visibility:public"],
deps = [
"//dotnet/src/webdriver:netstandard2.0-strongnamed",
"@io_bazel_rules_dotnet//dotnet/stdlib.netstandard:netstandard.dll",
"//dotnet/src/webdriver:netstandard2.0assembly-strongnamed",
],
)

Expand Down
Loading

0 comments on commit 6d9e681

Please sign in to comment.