rules_dotnet
rules_dotnet copied to clipboard
Is there an equivalent to dotnet publish?
Using dotnet publish
it is possible to generate a folder with a DLL and all of its dependencies.
Is there an equivalent in rules_dotnet
?
@njlr There is no such support at the moment in these rules. Can I ask what the exact use case you have is?
For example to deploy an AWS Lambda it is necessary to build a .zip
that contains the .NET library and any dependencies.
This can be done outside Bazel with dotnet publish
and an appropriate zip
command on the publish
folder in bin
.
I do something similar for docker where I use a filegroup to gather the runfiles.
load("@io_bazel_rules_docker//container:container.bzl", "container_image")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
def dotnet_lambda_image(name, bin, **kwargs):
pkg_tar(
name = "%s_app_layer" % name,
srcs = [bin],
include_runfiles = True,
mode = "0755",
package_dir = "/var/task",
)
bin_label = Label(bin)
container_image(
name = name,
base = "@dotnet_lambda_base//image",
entrypoint = [
"/bootstrap.sh",
"%s" % bin_label.name,
],
env = {
"DOTNET_ROOT": "/var/lang/bin",
},
tars = ["%s_app_layer" % name],
**kwargs
)
You can possibly do something similar using https://github.com/bazelbuild/rules_pkg to construct the zip file.
I went with using containers and AWS lambda instead of the ZIP since I already had the whole container building workflow setup in our repo
Thanks for your help.
Unfortunately I ran into 2 issues:
-
pkg_zip
does not have aninclude_runfiles
argument - using
pkg_tar
, the set of runfiles seems to be too big, e.g.System.Collections.dll
should not be included as that is provided by AWS Lambda
@njlr Sorry, I forgot to respond to you and was going through the issues now.
Regarding the runfiles list being too large then I think I'll try to find a way to have 2 different fsharp/csharp_binary
rules where one behaves like dotnet publish -r <os-arch>
which would include the runtime and the other one would not include the runtime.
I don't think I'll add it to the master
branch but the next
branch since we are actively working on all kinds of improvements there.
Thanks @purkhusid.
I was thinking a design like this could work well:
fsharp_library(
name = "foo",
srcs = [
"Library.fs",
],
)
dotnet_publish(
name = "foo_pub",
lib = ":foo",
)
There is now an publish_binary
rule on the next
branch that can publish self contained and framework dependent binaries.
Examples are in the examples
folder.