Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ matrix:
["--@rules_dotnet//dotnet/settings:strict_deps=true"],
["--@rules_dotnet//dotnet/settings:strict_deps=false"],
]
e2e_working_directory: ["e2e/net8.0", "e2e/net9.0"]
e2e_working_directory: ["e2e/net8.0", "e2e/net9.0", "e2e/web_sdk"]

tasks:
test_all:
Expand Down
1 change: 1 addition & 0 deletions dotnet/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ filegroup(
data = glob([
"host/**/*",
"sdk/**/*",
"shared/Microsoft.AspNetCore.App/**/*",
"shared/Microsoft.NETCore.App/**/*",
]),
visibility = ["//visibility:public"],
Expand Down
6 changes: 6 additions & 0 deletions e2e/web_sdk/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
startup --windows_enable_symlinks
common --enable_runfiles
common --incompatible_strict_action_env

# Disable bzlmod lock file since it's not stable enough yet
common --lockfile_mode=off
1 change: 1 addition & 0 deletions e2e/web_sdk/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.3.0
Empty file added e2e/web_sdk/BUILD.bazel
Empty file.
29 changes: 29 additions & 0 deletions e2e/web_sdk/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"rules_dotnet examples"

module(
name = "e2e_web_sdk",
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "rules_dotnet", version = "0.0.0")
local_path_override(
module_name = "rules_dotnet",
path = "../..",
)

dotnet = use_extension("@rules_dotnet//dotnet:extensions.bzl", "dotnet")
dotnet.toolchain(dotnet_version = "9.0.300")
use_repo(dotnet, "dotnet_toolchains")

register_toolchains("@dotnet_toolchains//:all")

main_extension = use_extension("//:paket.main_extension.bzl", "main_extension")
use_repo(main_extension, "paket.main")

# Only needed to make the Bazel CI RBE config work. Not needed for using rules_dotnet.
bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True)
bazel_dep(name = "platforms", version = "0.0.10", dev_dependency = True)

internal_dev_deps = use_extension("//:internal_dev_deps.bzl", "internal_dev_deps", dev_dependency = True)
use_repo(internal_dev_deps, "buildkite_config")
36 changes: 36 additions & 0 deletions e2e/web_sdk/basic_csharp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load(
"@rules_dotnet//dotnet:defs.bzl",
"csharp_binary",
"csharp_library",
"csharp_nunit_test",
)

# bazel run //examples:hello
csharp_binary(
name = "hello",
srcs = ["hello.cs"],
project_sdk = "web",
target_frameworks = ["net9.0"],
deps = [
":lib",
],
)

csharp_nunit_test(
name = "lib_test",
srcs = ["libtest.cs"],
project_sdk = "web",
target_frameworks = ["net9.0"],
deps = [
":lib",
],
)

csharp_library(
name = "lib",
srcs = ["lib.cs"],
internals_visible_to = ["lib_test"],
project_sdk = "web",
target_frameworks = ["net9.0"],
deps = [],
)
22 changes: 22 additions & 0 deletions e2e/web_sdk/basic_csharp/hello.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Linq;
using static Lib.Stuff;

namespace Hello {
public static class Program {
public static void Main() {
Console.WriteLine( "Hello, world!" );
Console.WriteLine( "Some numbers for you:" );
Console.Write( "\t" );

// silly code
Console.WriteLine(
Fibonacci( 0, 1 )
.WhereNot( IsEven )
.Take( 10 )
.Select( x => x.ToString() )
.Aggregate( (x, y) => x + ", " + y )
);
}
}
}
23 changes: 23 additions & 0 deletions e2e/web_sdk/basic_csharp/lib.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace Lib {
public static class Stuff {
public static IEnumerable<T> WhereNot<T>( this IEnumerable<T> @this, Func<T, bool> fn )
=> @this.Where( t => !fn( t ) );

public static IEnumerable<int> Fibonacci( int x0, int x1 ) {
while (true) {
yield return x0;
var next = x0 + x1;
x0 = x1;
x1 = next;
}
}

public static bool IsEven( int x ) => x%2 == 0;

internal static int NonPublicMethod() => 42;
}
}
20 changes: 20 additions & 0 deletions e2e/web_sdk/basic_csharp/libtest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Lib;
using NUnit.Framework;
using System.Linq;

[TestFixture]
public sealed class LibTests {
[Test]
public void SomeTest() {
CollectionAssert.AreEqual(
new [] { 0, 1, 1, 2, 3, 5, 8, 13, 21 },
Stuff.Fibonacci( 0, 1 ).Take( 9 )
);
}

[Test]
public void CanSeeInternals() {
Assert.AreEqual(42, Stuff.NonPublicMethod());
}
}

39 changes: 39 additions & 0 deletions e2e/web_sdk/basic_fsharp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
load(
"@rules_dotnet//dotnet:defs.bzl",
"fsharp_binary",
"fsharp_library",
"fsharp_nunit_test",
)

fsharp_binary(
name = "hello",
srcs = ["hello.fs"],
project_sdk = "web",
target_frameworks = ["net9.0"],
deps = [
":lib",
"@paket.main//fsharp.core",
],
)

fsharp_nunit_test(
name = "lib_test",
srcs = ["libtest.fs"],
project_sdk = "web",
target_frameworks = ["net9.0"],
deps = [
":lib",
"@paket.main//fsharp.core",
],
)

fsharp_library(
name = "lib",
srcs = ["lib.fs"],
internals_visible_to = ["lib_test"],
project_sdk = "web",
target_frameworks = ["net9.0"],
deps = [
"@paket.main//fsharp.core",
],
)
12 changes: 12 additions & 0 deletions e2e/web_sdk/basic_fsharp/hello.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
open System
open System.Linq
open Lib

[<EntryPoint>]
let main args =
Console.WriteLine( "Hello, world!" );
Console.WriteLine( "Some numbers for you:" );

Stuff.fibonacci |> Seq.take 10 |> Seq.iter (fun i -> Console.WriteLine(i))

0
10 changes: 10 additions & 0 deletions e2e/web_sdk/basic_fsharp/lib.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Lib
module Stuff =
let rec fibonacci =
Seq.unfold
(fun (n0, n1) ->
Some(n0, (n1, n0 + n1)))
(0,1)

let internal nonPublicMethod () = 42

15 changes: 15 additions & 0 deletions e2e/web_sdk/basic_fsharp/libtest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Tests

open Lib
open NUnit.Framework
open System.Linq

[<TestFixture>]
type LibTests () =
[<Test>]
member this.SomeTest() =
CollectionAssert.AreEqual([ 0; 1; 1; 2; 3; 5; 8; 13; 21 ], Stuff.fibonacci |> Seq.take 9)

[<Test>]
member this.CanSeeInternals() =
Assert.AreEqual(42, Stuff.nonPublicMethod())
12 changes: 12 additions & 0 deletions e2e/web_sdk/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"paket": {
"version": "9.0.0",
"commands": [
"paket"
]
}
}
}
16 changes: 16 additions & 0 deletions e2e/web_sdk/internal_dev_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Module extension for internal dev_dependency=True setup."""

load("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")

def _internal_dev_deps_impl(mctx):
_ = mctx # @unused

rbe_preconfig(
name = "buildkite_config",
toolchain = "ubuntu1804-bazel-java11",
)

internal_dev_deps = module_extension(
implementation = _internal_dev_deps_impl,
doc = "This extension creates internal rules_dotnet dev dependencies.",
)
5 changes: 5 additions & 0 deletions e2e/web_sdk/paket.dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
framework: net9.0
storage: none
source https://api.nuget.org/v3/index.json

nuget FSharp.Core 9.0.300
5 changes: 5 additions & 0 deletions e2e/web_sdk/paket.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
STORAGE: NONE
RESTRICTION: == net9.0
NUGET
remote: https://api.nuget.org/v3/index.json
FSharp.Core (9.0.300)
12 changes: 12 additions & 0 deletions e2e/web_sdk/paket.main.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"GENERATED"

load("@rules_dotnet//dotnet:defs.bzl", "nuget_repo")

def main():
"main"
nuget_repo(
name = "paket.main",
packages = [
{"name": "FSharp.Core", "id": "FSharp.Core", "version": "9.0.300", "sha512": "sha512-VmGyQ5hzaEvOHR2NnSlGHeGJzDH8j/GAil0pVAVxFv1YhQO6/OSLab7MWN5adsB7GYWsDVhU4YiSMDy+rA/2EQ==", "sources": ["https://api.nuget.org/v3/index.json"], "dependencies": {"net11": [], "net20": [], "net30": [], "net35": [], "net40": [], "net403": [], "net45": [], "net451": [], "net452": [], "net46": [], "net461": [], "net462": [], "net47": [], "net471": [], "net472": [], "net48": [], "net5.0": [], "net6.0": [], "net7.0": [], "net8.0": [], "net9.0": [], "netcoreapp1.0": [], "netcoreapp1.1": [], "netcoreapp2.0": [], "netcoreapp2.1": [], "netcoreapp2.2": [], "netcoreapp3.0": [], "netcoreapp3.1": [], "netstandard": [], "netstandard1.0": [], "netstandard1.1": [], "netstandard1.2": [], "netstandard1.3": [], "netstandard1.4": [], "netstandard1.5": [], "netstandard1.6": [], "netstandard2.0": [], "netstandard2.1": []}, "targeting_pack_overrides": [], "framework_list": []},
],
)
11 changes: 11 additions & 0 deletions e2e/web_sdk/paket.main_extension.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"Generated"

load(":paket.main.bzl", _main = "main")

def _main_impl(module_ctx):
_main()
return module_ctx.extension_metadata(reproducible = True)

main_extension = module_extension(
implementation = _main_impl,
)
9 changes: 9 additions & 0 deletions e2e/web_sdk/update-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /usr/bin/env bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

(
cd "$SCRIPT_DIR" || exit 1
(dotnet tool restore && dotnet paket install)
bazel run @rules_dotnet//tools/paket2bazel -- --dependencies-file "$(pwd)"/paket.dependencies --output-folder "$(pwd)"
)