Skip to content

bazelbuild/rules_dotnet

master
Switch branches/tags
Code

Latest commit

Fixes #287, the value of the size argument in 'strncat' is too large, might lead to a buffer overflow
0b7ae93

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time

.Net Rules for Bazel

Gitpod ready-to-code

Build status

Bazel CI
Build status

Documentation

The full documentation is here.

Overview

This is a minimal viable set of C#/F# bindings for building C#/F# code with Core

Caveats

Bazel creates long paths. Therefore it is recommended to increase the length limit using newer version of Windows. Please see here.

However, some Windows programs do not handle long path names. Most notably - Microsoft C compiler (cl.exe). Therefore TMP env variable should be set to something short (like X:\ or c:\TEMP).

Bazel and dotnet_rules rely on symbolic linking. On Windows it, typically, requires elevated permissions. However, newer versions of Windows have a workaround.

Setup

  • The rules take full advantage of Bazel platforms and toolchains

  • When building any project the platform has to be specified. For example:

        bazel build --host_platform=@io_bazel_rules_dotnet//dotnet/toolchain:linux_amd64_6.0.101 --platforms=@io_bazel_rules_dotnet//dotnet/toolchain:linux_amd64_6.0.101 //...
  • The platform specification has the form of //dotnet/toolchain:. The available values are listed in dotnet/platform/list.bzl in variables DOTNET_OS_ARCH and DOTNET_CORE_FRAMEWORKS. Typically the --host_platform and --platforms values are set in .bazelrc file.

  • Add the following to your WORKSPACE file to add the external repositories:

    # A newer version should be fine
    load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
    git_repository(
        name = "io_bazel_rules_dotnet",
        remote = "https://github.com/bazelbuild/rules_dotnet",
        branch = "master",
    )
    
    load("@io_bazel_rules_dotnet//dotnet:deps.bzl", "dotnet_repositories")
    dotnet_repositories()
    
    load(
        "@io_bazel_rules_dotnet//dotnet:defs.bzl",
        "dotnet_register_toolchains",
        "dotnet_repositories_nugets",
    )
    
    dotnet_register_toolchains()
    dotnet_repositories_nugets()

    The dotnet_repositories rule fetches external dependencies which have to be defined before loading any other file of rules_dotnet. dotnet_repositories_nugets loads nuget packages required by test rules.

    The dotnet_register_toolchains configures toolchains.

  • Add a file named BUILD.bazel in the root directory of your project. In general, you need one of these files in every directory with dotnet code.

    At the top of the file used rules should be imported:

      load("@io_bazel_rules_dotnet//dotnet:defs.bzl", "csharp_library", "csharp_binary")
  • See nuget2bazel for using nuget dependencies.

  • See examples folder for examples.