diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 1be1c8c6..eeaa3ace 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -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: diff --git a/dotnet/repositories.bzl b/dotnet/repositories.bzl index 0a387d8f..6cbdbea9 100644 --- a/dotnet/repositories.bzl +++ b/dotnet/repositories.bzl @@ -45,6 +45,7 @@ filegroup( data = glob([ "host/**/*", "sdk/**/*", + "shared/Microsoft.AspNetCore.App/**/*", "shared/Microsoft.NETCore.App/**/*", ]), visibility = ["//visibility:public"], diff --git a/e2e/web_sdk/.bazelrc b/e2e/web_sdk/.bazelrc new file mode 100644 index 00000000..c444361a --- /dev/null +++ b/e2e/web_sdk/.bazelrc @@ -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 diff --git a/e2e/web_sdk/.bazelversion b/e2e/web_sdk/.bazelversion new file mode 100644 index 00000000..2bf50aaf --- /dev/null +++ b/e2e/web_sdk/.bazelversion @@ -0,0 +1 @@ +8.3.0 diff --git a/e2e/web_sdk/BUILD.bazel b/e2e/web_sdk/BUILD.bazel new file mode 100644 index 00000000..e69de29b diff --git a/e2e/web_sdk/MODULE.bazel b/e2e/web_sdk/MODULE.bazel new file mode 100644 index 00000000..695c7e76 --- /dev/null +++ b/e2e/web_sdk/MODULE.bazel @@ -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") diff --git a/e2e/web_sdk/basic_csharp/BUILD.bazel b/e2e/web_sdk/basic_csharp/BUILD.bazel new file mode 100644 index 00000000..b7503238 --- /dev/null +++ b/e2e/web_sdk/basic_csharp/BUILD.bazel @@ -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 = [], +) diff --git a/e2e/web_sdk/basic_csharp/hello.cs b/e2e/web_sdk/basic_csharp/hello.cs new file mode 100644 index 00000000..c6f4e099 --- /dev/null +++ b/e2e/web_sdk/basic_csharp/hello.cs @@ -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 ) + ); + } + } +} diff --git a/e2e/web_sdk/basic_csharp/lib.cs b/e2e/web_sdk/basic_csharp/lib.cs new file mode 100644 index 00000000..8883a136 --- /dev/null +++ b/e2e/web_sdk/basic_csharp/lib.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Lib { + public static class Stuff { + public static IEnumerable WhereNot( this IEnumerable @this, Func fn ) + => @this.Where( t => !fn( t ) ); + + public static IEnumerable 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; + } +} diff --git a/e2e/web_sdk/basic_csharp/libtest.cs b/e2e/web_sdk/basic_csharp/libtest.cs new file mode 100644 index 00000000..a075e3d6 --- /dev/null +++ b/e2e/web_sdk/basic_csharp/libtest.cs @@ -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()); + } +} + diff --git a/e2e/web_sdk/basic_fsharp/BUILD.bazel b/e2e/web_sdk/basic_fsharp/BUILD.bazel new file mode 100644 index 00000000..f753493a --- /dev/null +++ b/e2e/web_sdk/basic_fsharp/BUILD.bazel @@ -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", + ], +) diff --git a/e2e/web_sdk/basic_fsharp/hello.fs b/e2e/web_sdk/basic_fsharp/hello.fs new file mode 100644 index 00000000..31f209f5 --- /dev/null +++ b/e2e/web_sdk/basic_fsharp/hello.fs @@ -0,0 +1,12 @@ +open System +open System.Linq +open Lib + +[] +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 diff --git a/e2e/web_sdk/basic_fsharp/lib.fs b/e2e/web_sdk/basic_fsharp/lib.fs new file mode 100644 index 00000000..22b7ce91 --- /dev/null +++ b/e2e/web_sdk/basic_fsharp/lib.fs @@ -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 + diff --git a/e2e/web_sdk/basic_fsharp/libtest.fs b/e2e/web_sdk/basic_fsharp/libtest.fs new file mode 100644 index 00000000..5e6e4070 --- /dev/null +++ b/e2e/web_sdk/basic_fsharp/libtest.fs @@ -0,0 +1,15 @@ +module Tests + +open Lib +open NUnit.Framework +open System.Linq + +[] +type LibTests () = + [] + member this.SomeTest() = + CollectionAssert.AreEqual([ 0; 1; 1; 2; 3; 5; 8; 13; 21 ], Stuff.fibonacci |> Seq.take 9) + + [] + member this.CanSeeInternals() = + Assert.AreEqual(42, Stuff.nonPublicMethod()) diff --git a/e2e/web_sdk/dotnet-tools.json b/e2e/web_sdk/dotnet-tools.json new file mode 100644 index 00000000..b5665637 --- /dev/null +++ b/e2e/web_sdk/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "paket": { + "version": "9.0.0", + "commands": [ + "paket" + ] + } + } +} diff --git a/e2e/web_sdk/internal_dev_deps.bzl b/e2e/web_sdk/internal_dev_deps.bzl new file mode 100644 index 00000000..87adeef9 --- /dev/null +++ b/e2e/web_sdk/internal_dev_deps.bzl @@ -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.", +) diff --git a/e2e/web_sdk/paket.dependencies b/e2e/web_sdk/paket.dependencies new file mode 100644 index 00000000..b14462a3 --- /dev/null +++ b/e2e/web_sdk/paket.dependencies @@ -0,0 +1,5 @@ +framework: net9.0 +storage: none +source https://api.nuget.org/v3/index.json + +nuget FSharp.Core 9.0.300 diff --git a/e2e/web_sdk/paket.lock b/e2e/web_sdk/paket.lock new file mode 100644 index 00000000..359a3d39 --- /dev/null +++ b/e2e/web_sdk/paket.lock @@ -0,0 +1,5 @@ +STORAGE: NONE +RESTRICTION: == net9.0 +NUGET + remote: https://api.nuget.org/v3/index.json + FSharp.Core (9.0.300) diff --git a/e2e/web_sdk/paket.main.bzl b/e2e/web_sdk/paket.main.bzl new file mode 100644 index 00000000..4b8939c1 --- /dev/null +++ b/e2e/web_sdk/paket.main.bzl @@ -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": []}, + ], + ) diff --git a/e2e/web_sdk/paket.main_extension.bzl b/e2e/web_sdk/paket.main_extension.bzl new file mode 100644 index 00000000..91f53cc2 --- /dev/null +++ b/e2e/web_sdk/paket.main_extension.bzl @@ -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, +) diff --git a/e2e/web_sdk/update-deps.sh b/e2e/web_sdk/update-deps.sh new file mode 100755 index 00000000..7e16f2e0 --- /dev/null +++ b/e2e/web_sdk/update-deps.sh @@ -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)" +)