Skip to content

Commit 6d9e681

Browse files
committed
Updating .NET build to use new Bazel build rules
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.
1 parent 1c5bdc3 commit 6d9e681

File tree

10 files changed

+304
-356
lines changed

10 files changed

+304
-356
lines changed

WORKSPACE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
2222
closure_repositories()
2323

2424
http_archive(
25-
name = "io_bazel_rules_dotnet",
26-
sha256 = "6c5d7080c61abda66458b51167d20683de220bd486ab37bde5c470acea12de66",
27-
strip_prefix = "rules_dotnet-66b235a05ff23c0c65967453e7722d6d7fa28b1c",
25+
name = "d2l_rules_csharp",
26+
sha256 = "0e688b0f9279855bef3e98657af44c29ac281c510e21919a03ceb69a910ebdf4",
27+
strip_prefix = "rules_csharp-77997bbb79ba4294b1d88ae6f44211df8eb4075e",
2828
urls = [
29-
"https://github.com/jimevans/rules_dotnet/archive/66b235a05ff23c0c65967453e7722d6d7fa28b1c.tar.gz",
29+
"https://github.com/Brightspace/rules_csharp/archive/77997bbb79ba4294b1d88ae6f44211df8eb4075e.tar.gz",
3030
],
3131
)
3232

dotnet/merge-assemblies.bzl

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
load(
2-
"@io_bazel_rules_dotnet//dotnet/private:context.bzl",
3-
"dotnet_context"
4-
)
5-
load(
6-
"@io_bazel_rules_dotnet//dotnet/private:providers.bzl",
7-
"DotnetLibrary",
8-
)
1+
load("@d2l_rules_csharp//csharp/private:common.bzl", "collect_transitive_info")
92

103
def _merged_assembly_impl(ctx):
11-
dotnet = dotnet_context(ctx)
124
name = ctx.label.name
135

146
deps = ctx.attr.deps
157
result = ctx.outputs.out
168

9+
target_framework = ctx.attr.target_framework
10+
1711
args = [
12+
"-ndebug",
1813
"-v4",
1914
"-xmldocs",
2015
"-internalize",
@@ -26,8 +21,9 @@ def _merged_assembly_impl(ctx):
2621

2722
args.append("-out={}".format(ctx.outputs.out.path))
2823
args.append(ctx.attr.src_assembly.files.to_list()[0].path)
29-
for dep in ctx.files.deps:
30-
args.append(ctx.expand_location(dep.path))
24+
(refs, runfiles, native_dlls) = collect_transitive_info(deps, target_framework)
25+
for ref in refs.to_list():
26+
args.append(ref.path)
3127

3228
ctx.actions.run(
3329
executable = ctx.executable.merge_tool,
@@ -36,25 +32,16 @@ def _merged_assembly_impl(ctx):
3632
outputs = [ctx.outputs.out]
3733
)
3834

39-
data = depset()
40-
41-
runfiles = depset(direct = [result], transitive = [d[DotnetLibrary].runfiles for d in deps] + [data])
42-
transitive = depset(direct = deps, transitive = [a[DotnetLibrary].transitive for a in deps])
43-
44-
merged_lib = dotnet.new_library(
45-
dotnet = dotnet,
46-
name = name,
47-
deps = deps,
48-
transitive = transitive,
49-
runfiles = runfiles,
50-
result = result,
35+
runfiles = ctx.runfiles(
36+
files = [ctx.outputs.out],
5137
)
5238

39+
for dep in ctx.files.deps:
40+
runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles)
41+
5342
return [
54-
merged_lib,
5543
DefaultInfo(
56-
files = depset([merged_lib.result]),
57-
runfiles = ctx.runfiles(files = [], transitive_files = merged_lib.runfiles),
44+
runfiles = runfiles,
5845
),
5946
]
6047

@@ -65,13 +52,13 @@ merged_assembly = rule(
6552
"deps": attr.label_list(),
6653
"out": attr.output(mandatory = True),
6754
"keyfile": attr.label(allow_single_file = True),
68-
"dotnet_context_data": attr.label(default = Label("@io_bazel_rules_dotnet//:dotnet_context_data")),
55+
"target_framework": attr.string(mandatory = True),
6956
"merge_tool": attr.label(
7057
executable = True,
7158
cfg = "host",
7259
default = Label("//third_party/dotnet/ilmerge:ilmerge.exe"),
7360
allow_single_file = True
7461
),
7562
},
76-
toolchains = ["@io_bazel_rules_dotnet//dotnet:toolchain_net"],
63+
toolchains = ["//third_party/dotnet/ilmerge:toolchain_type"],
7764
)

dotnet/nuget.bzl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
load(
2-
"@io_bazel_rules_dotnet//dotnet/private:context.bzl",
3-
"dotnet_context"
4-
)
5-
61
def _nuget_package_impl(ctx):
72
args = [
83
"pack",

dotnet/src/support/BUILD.bazel

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@io_bazel_rules_dotnet//dotnet:defs.bzl", "netstandard_library", "net_library")
1+
load("@d2l_rules_csharp//csharp:defs.bzl", "csharp_library")
22
load("//dotnet:nuget.bzl", "nuget_package")
33
load(
44
"//dotnet:selenium-dotnet-version.bzl",
@@ -7,7 +7,7 @@ load(
77
"SUPPORTED_NET_FRAMEWORKS",
88
)
99

10-
[net_library(
10+
[csharp_library(
1111
name = "{}".format(framework),
1212
srcs = glob([
1313
"*.cs",
@@ -16,20 +16,22 @@ load(
1616
"PageObjects/**/*.cs",
1717
"UI/*.cs",
1818
]),
19+
target_frameworks = [
20+
"{}".format(framework),
21+
],
1922
out = "merged/{}/WebDriver.Support.dll".format(framework),
20-
dotnet_context_data = "@io_bazel_rules_dotnet//:net_context_data_{}".format(framework),
2123
visibility = ["//visibility:public"],
2224
deps = [
23-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.core.dll",
24-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.data.dll",
25-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.dll",
26-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.drawing.dll",
27-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.xml.dll",
25+
"@net//:System",
26+
"@net//:System.Core",
27+
"@net//:System.Data",
28+
"@net//:System.Drawing",
29+
"@net//:System.Xml",
2830
"//dotnet/src/webdriver:{}assembly".format(framework),
2931
],
3032
) for framework in SUPPORTED_NET_FRAMEWORKS]
3133

32-
netstandard_library(
34+
csharp_library(
3335
name = "netstandard2.0",
3436
srcs = glob([
3537
"*.cs",
@@ -38,18 +40,17 @@ netstandard_library(
3840
"PageObjects/**/*.cs",
3941
"UI/*.cs",
4042
]),
41-
out = "merged/netstandard2.0/WebDriver.Support.dll",
42-
defines = [
43-
"NETSTANDARD2_0",
43+
target_frameworks = [
44+
"netstandard2.0",
4445
],
46+
out = "merged/netstandard2.0/WebDriver.Support.dll",
4547
visibility = ["//visibility:public"],
4648
deps = [
47-
"//dotnet/src/webdriver:netstandard2.0",
48-
"@io_bazel_rules_dotnet//dotnet/stdlib.netstandard:netstandard.dll",
49+
"//dotnet/src/webdriver:netstandard2.0assembly",
4950
],
5051
)
5152

52-
[net_library(
53+
[csharp_library(
5354
name = "{}-strongnamed".format(framework),
5455
srcs = glob([
5556
"*.cs",
@@ -58,21 +59,23 @@ netstandard_library(
5859
"PageObjects/**/*.cs",
5960
"UI/*.cs",
6061
]),
62+
target_frameworks = [
63+
"{}".format(framework),
64+
],
6165
out = "strongnamed/{}/WebDriver.Support.dll".format(framework),
62-
dotnet_context_data = "@io_bazel_rules_dotnet//:net_context_data_{}".format(framework),
6366
keyfile = "//dotnet:WebDriver.snk",
6467
visibility = ["//visibility:public"],
6568
deps = [
66-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.core.dll",
67-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.data.dll",
68-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.dll",
69-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.drawing.dll",
70-
"@io_bazel_rules_dotnet//dotnet/stdlib.net:system.xml.dll",
69+
"@net//:System",
70+
"@net//:System.Core",
71+
"@net//:System.Data",
72+
"@net//:System.Drawing",
73+
"@net//:System.Xml",
7174
"//dotnet/src/webdriver:{}assembly-strongnamed".format(framework),
7275
],
7376
) for framework in SUPPORTED_NET_FRAMEWORKS]
7477

75-
netstandard_library(
78+
csharp_library(
7679
name = "netstandard2.0-strongnamed",
7780
srcs = glob([
7881
"*.cs",
@@ -81,15 +84,14 @@ netstandard_library(
8184
"PageObjects/**/*.cs",
8285
"UI/*.cs",
8386
]),
84-
out = "strongnamed/netstandard2.0/WebDriver.Support.dll",
85-
defines = [
86-
"NETSTANDARD2_0",
87+
target_frameworks = [
88+
"netstandard2.0",
8789
],
90+
out = "strongnamed/netstandard2.0/WebDriver.Support.dll",
8891
keyfile = "//dotnet:WebDriver.snk",
8992
visibility = ["//visibility:public"],
9093
deps = [
91-
"//dotnet/src/webdriver:netstandard2.0-strongnamed",
92-
"@io_bazel_rules_dotnet//dotnet/stdlib.netstandard:netstandard.dll",
94+
"//dotnet/src/webdriver:netstandard2.0assembly-strongnamed",
9395
],
9496
)
9597

0 commit comments

Comments
 (0)