Skip to content

Commit ebb2259

Browse files
committed
Moved some .net things into dotnet_common
1 parent bc967b9 commit ebb2259

2 files changed

Lines changed: 81 additions & 24 deletions

File tree

prelude/decls/dotnet_common.bzl

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is dual-licensed under either the MIT license found in the
4+
# LICENSE-MIT file in the root directory of this source tree or the Apache
5+
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
6+
# of this source tree. You may select, at your option, one of the
7+
# above-listed licenses.
8+
9+
# TODO(cjhopman): This was generated by scripts/hacks/rules_shim_with_docs.py,
10+
# but should be manually edited going forward. There may be some errors in
11+
# the generated docs, and so those should be verified to be accurate and
12+
# well-formatted (and then delete this TODO)
13+
14+
FrameworkVersion = ["net35", "net40", "net45", "net46"]
15+
16+
def _srcs_arg():
17+
return {
18+
"srcs": attrs.list(attrs.one_of(attrs.source(), attrs.tuple(attrs.source(), attrs.list(attrs.arg()))), default = [], doc = """
19+
The set of C, C++, Objective-C, Objective-C++, or assembly source files
20+
to be preprocessed, compiled, and assembled by this
21+
rule. We determine which stages to run on each input source based on its file extension. See the
22+
[GCC documentation](https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html) for more detail on how file extensions are interpreted. Each element can be either a string
23+
specifying a source file (e.g. `''`) or a tuple of
24+
a string specifying a source file and a list of compilation flags
25+
(e.g. `('', ['-Wall', '-Werror'])` ). In the latter case the specified flags will be used in addition to the rule's other
26+
flags when preprocessing and compiling that file (if applicable).
27+
"""),
28+
}
29+
30+
def _resources_arg():
31+
return {
32+
"resources": attrs.dict(key = attrs.string(), value = attrs.source(), sorted = False, default = {}, doc = """
33+
Resources that should be embedded within the built DLL. The format
34+
is the name of the resource once mapped into the DLL as the key, and
35+
the value being the resource that should be merged. This allows
36+
non-unique keys to be identified quickly.
37+
"""),
38+
}
39+
40+
def _framework_ver_arg():
41+
return {
42+
"framework_ver": attrs.enum(FrameworkVersion, doc = """
43+
The version of the .Net framework that this library targets. This is
44+
one of 'net35', 'net40', 'net45' and 'net46'.
45+
"""),
46+
}
47+
48+
def _deps_arg():
49+
return {
50+
"deps": attrs.list(attrs.one_of(attrs.dep(), attrs.string()), default = [], doc = """
51+
The set of targets or system-provided assemblies to rely on. Any
52+
values that are targets must be either csharp\\_library or `prebuilt_dotnet_library`
53+
instances.
54+
"""),
55+
}
56+
57+
def _compiler_flags_arg():
58+
return {
59+
"compiler_flags": attrs.list(attrs.string(), default = [], doc = """
60+
The set of additional compiler flags to pass to the compiler.
61+
"""),
62+
}
63+
64+
def _add_hermetic_arguments_arg():
65+
return {"add_hermetic_arguments": attrs.bool(default = True)}
66+
67+
dotnet_common = struct(
68+
srcs_arg = _srcs_arg,
69+
resources_arg = _resources_arg,
70+
framework_ver_arg = _framework_ver_arg,
71+
deps_arg = _deps_arg,
72+
compiler_flags_arg = _compiler_flags_arg,
73+
add_hermetic_arguments_arg = _add_hermetic_arguments_arg,
74+
)

prelude/decls/dotnet_rules.bzl

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
# well-formatted (and then delete this TODO)
1313

1414
load(":common.bzl", "buck", "prelude_rule")
15-
16-
FrameworkVersion = ["net35", "net40", "net45", "net46"]
15+
load(":dotnet_common.bzl", "dotnet_common")
1716

1817
csharp_library = prelude_rule(
1918
name = "csharp_library",
@@ -57,29 +56,13 @@ csharp_library = prelude_rule(
5756
the dll exactly. When this is not set, the dll will be named after
5857
the short name of the target.
5958
"""),
60-
"srcs": attrs.list(attrs.source(), default = [], doc = """
61-
The collection of source files to compile.
62-
"""),
63-
"resources": attrs.dict(key = attrs.string(), value = attrs.source(), sorted = False, default = {}, doc = """
64-
Resources that should be embedded within the built DLL. The format
65-
is the name of the resource once mapped into the DLL as the key, and
66-
the value being the resource that should be merged. This allows
67-
non-unique keys to be identified quickly.
68-
"""),
69-
"framework_ver": attrs.enum(FrameworkVersion, doc = """
70-
The version of the .Net framework that this library targets. This is
71-
one of 'net35', 'net40', 'net45' and 'net46'.
72-
"""),
73-
"deps": attrs.list(attrs.one_of(attrs.dep(), attrs.string()), default = [], doc = """
74-
The set of targets or system-provided assemblies to rely on. Any
75-
values that are targets must be either csharp\\_library or `prebuilt_dotnet_library`
76-
instances.
77-
"""),
78-
"compiler_flags": attrs.list(attrs.string(), default = [], doc = """
79-
The set of additional compiler flags to pass to the compiler.
80-
"""),
81-
"add_hermetic_arguments": attrs.bool(default = True),
8259
} |
60+
dotnet_common.srcs_arg() |
61+
dotnet_common.resources_arg() |
62+
dotnet_common.framework_ver_arg() |
63+
dotnet_common.deps_arg() |
64+
dotnet_common.compiler_flags_arg() |
65+
dotnet_common.add_hermetic_arguments_arg() |
8366
buck.licenses_arg() |
8467
buck.labels_arg() |
8568
buck.contacts_arg()

0 commit comments

Comments
 (0)