GithubHelp home page GithubHelp logo

iainmerrick / rules_dotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bazelbuild/rules_dotnet

0.0 2.0 0.0 47 KB

.NET rules for Bazel

License: Apache License 2.0

Python 99.15% Smarty 0.85%

rules_dotnet's Introduction

C# Rules

Rules

WARNING: Theses rules are not compatible with sandboxing.

Overview

This is a minimal viable set of C# bindings for building csharp code with mono. It's still pretty rough but it works as a proof of concept that could grow into something more. If windows support ever happens for Bazel then this might become especially valuable.

Setup

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

git_repository(
    name = "io_bazel_rules_dotnet",
    remote = "https://github.com/bazelbuild/rules_dotnet.git",
    tag = "0.0.3",
)

load(
    "@io_bazel_rules_dotnet//dotnet:csharp.bzl",
    "csharp_repositories",
    "nuget_package",
)

csharp_repositories(use_local_mono = True)

nuget_package(
  name = "some_name",
  package = "Some.Package",
  version = "0.1.2",
)

The csharp_repositories rule fetches external dependencies, namely the mono repository, the nuget binary, and the nunit binary. Setting the environment variable RULES_DOTNET_USE_LOCAL_MONO=1 or the rule argument use_local_mono to True will use your installed mono framework instead of downloading one. If you are on OS X you can set use_local_mono to False and mono will be downloaded for you by bazel.

Support for downloading mono on Linux is coming soon.

Examples

csharp_library

csharp_library(
    name = "MyLib",
    srcs = ["MyLib.cs"],
    deps = ["//my/dependency:SomeLib"],
)

csharp_binary

csharp_binary(
    name = "MyApp",
    main = "MyApp", # optional name of the main class.
    srcs = ["MyApp.cs"],
    deps = ["//my/dependency:MyLib"],
)

csharp_nunit_test

csharp_nunit_test(
    name = "MyApp",
    srcs = ["MyApp.cs"],
    deps = ["//my/dependency:MyLib"],
)

nuget_package

In the WORKSPACE file for your project record a nuget dependency like so. This is a repository rule so it will not work unless it is in a workspace file.

nuget_package(
    name="ndesk_options", # referenced via path @ndesk_options//:dylibs
    package="NDesk.Options",
    version="0.2.1",
)

new_nuget_package

This repository rule accepts either a BUILD file label or build_file_content string. Typically the build content will include dll_import rules that expose the correct set of libraries to the project. For example:

new_nuget_package(
  name = "nuget_grpc",
  package = "Grpc",
  version = "1.0.0",
  build_file_content =
"""
load("@io_bazel_rules_dotnet//dotnet:csharp.bzl", "dll_import")
dll_import(
  name = "system_interactive_async",
  srcs = glob(["System.Interactive.Async.3.0.0/lib/net45/**/*.dll"]),
  visibility = ["//visibility:public"],
)
dll_import(
  name = "core",
  srcs = glob(["Grpc.Core.1.0.0/lib/net45/**/*.dll"]),
  visibility = ["//visibility:public"],
)
"""
)

The structure of the nuget_grpc external workspace can be examined once downloaded and extracted via cd $(bazel info output_base)/external/nuget_grpc.

dll_import

Add a collection of dotnet assembly dll's to be used as a dependency.

dll_import(
    name="some_lib",
    srcs=[
      "Some.dll"
      "Some.Other.dll",
    ]
)

Things still missing:

  • Handle .resx files correctly.
  • .Net Modules
  • Conditionally building documentation.
  • Pulling Mono in through a mono.WORKSPACE file.
    • Still need to implement this for linux.
  • Multiple target framework support for nuget packages.

Future nice to haves:

  • nuget_packages repository rule that will handle multiple different nuget packages in one rule.
  • Building csproj and sln files for VS and MonoDevelop.
  • Windows .NET framwork support

csharp_library

csharp_library(name, srcs, deps, warn=4, csc)

Builds a C# .NET library and its corresponding documentation.

Attributes
name

Name, required

Unique name for this rule

srcs

List of Labels; required

Csharp .cs or .resx files.

deps

List of Labels; optional

Dependencies for this rule.

warn

Int; optional; default is 4

Compiler warn level for this library. (Defaults to 4.)

csc

string; optional

Override the default csharp compiler.

Note: This attribute may removed in future versions.

csharp_binary

csharp_binary(name, srcs, deps, main_class, warn=4, csc)

Builds a C# .NET binary.

Attributes
name

Name, required

Unique name for this rule

srcs

List of Labels; required

Csharp .cs or .resx files.

deps

List of Labels; optional

Dependencies for this rule.

main_class

String; optional

Name of class with main() method to use as entry point.

warn

Int; optional; default is 4

Compiler warn level for this binary. (Defaults to 4.)

csc

string; optional

Override the default csharp compiler.

Note: This attribute may removed in future versions.

csharp_nunit_test

csharp_nunit_test(name, srcs, deps, warn=4, csc)

Builds a C# .NET test binary that uses the NUnit unit testing framework.

Attributes
name

Name, required

Unique name for this rule

srcs

List of Labels; required

Csharp .cs or .resx files.

deps

List of Labels; optional

Dependencies for this rule.

warn

Int; optional; default is 4

Compiler warn level for this test. (Defaults to 4.)

csc

string; optional

Override the default csharp compiler.

Note: This attribute may removed in future versions.

nuget_package

nuget_package(name, package, version, package_sources)

A repository_rule that adds a nuget package dependency for the Workspace.

Attributes
name

Name, required

Unique name for this rule

package

String, Required

Name of the nuget package.

version

String, Required

Version of the nuget package to install.

package\_sources

List of strings, optional

Sources to pull nuget packages from. Either url or path.

dll_import(name, srcs)

A repository_rule that adds a nuget package dependency for the Workspace.

Attributes
name

Name, required

Unique name for this rule

srcs

Labels, required

List of dotnet dll assemblies to use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.