diff --git a/MODULE.bazel b/MODULE.bazel index 36a06b4b..cda0703c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -20,7 +20,6 @@ rules_dotnet_nuget_packages_extension = use_extension("//dotnet:paket.rules_dotn use_repo(rules_dotnet_nuget_packages_extension, "paket.rules_dotnet_nuget_packages") bazel_dep(name = "bazel_skylib", version = "1.4.2") -bazel_dep(name = "aspect_bazel_lib", version = "1.34.5") bazel_dep(name = "platforms", version = "0.0.7") # Dev dependencies @@ -28,6 +27,7 @@ bazel_dep(name = "rules_pkg", version = "0.9.1", dev_dependency = True) bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle") bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.2", dev_dependency = True) bazel_dep(name = "rules_cc", version = "0.0.9", dev_dependency = True) +bazel_dep(name = "aspect_bazel_lib", version = "1.34.5", dev_dependency = True) rules_dotnet_dev_nuget_packages_extension = use_extension("//dotnet:paket.rules_dotnet_dev_nuget_packages_extension.bzl", "rules_dotnet_dev_nuget_packages_extension", dev_dependency = True) use_repo(rules_dotnet_dev_nuget_packages_extension, "paket.rules_dotnet_dev_nuget_packages") diff --git a/dotnet/private/BUILD.bazel b/dotnet/private/BUILD.bazel index 86b23cb9..b0d5b831 100644 --- a/dotnet/private/BUILD.bazel +++ b/dotnet/private/BUILD.bazel @@ -95,7 +95,6 @@ bzl_library( deps = [ ":providers", ":semver", - "@aspect_bazel_lib//lib:paths", "@bazel_skylib//lib:sets", ], ) diff --git a/dotnet/private/common.bzl b/dotnet/private/common.bzl index 74f207c8..83a5d5ac 100644 --- a/dotnet/private/common.bzl +++ b/dotnet/private/common.bzl @@ -2,7 +2,6 @@ Rules for compatability resolution of dependencies for .NET frameworks. """ -load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path") load("@bazel_skylib//lib:sets.bzl", "sets") load( "//dotnet/private:providers.bzl", @@ -529,8 +528,8 @@ def generate_depsjson( library_fragment["hashPath"] = "{}.{}.nupkg.sha512".format(runtime_dep.name.lower(), runtime_dep.version) target_fragment = { - "runtime": {dll.basename if not use_relative_paths else to_manifest_path(ctx, dll): {} for dll in runtime_dep.libs}, - "native": {native_file.basename if not use_relative_paths else to_manifest_path(ctx, native_file): {} for native_file in runtime_dep.native}, + "runtime": {dll.basename if not use_relative_paths else to_rlocation_path(ctx, dll): {} for dll in runtime_dep.libs}, + "native": {native_file.basename if not use_relative_paths else to_rlocation_path(ctx, native_file): {} for native_file in runtime_dep.native}, "dependencies": runtime_dep.direct_deps_depsjson_fragment, } @@ -571,3 +570,37 @@ def generate_runtimeconfig(target_framework, project_sdk, is_self_contained, too base["runtimeOptions"]["frameworks"] = frameworks return base + +def to_rlocation_path(ctx, file): + """The rlocation path for a `File` + + This produces the same value as the `rlocationpath` predefined source/output path variable. + + From https://bazel.build/reference/be/make-variables#predefined_genrule_variables: + + > `rlocationpath`: The path a built binary can pass to the `Rlocation` function of a runfiles + > library to find a dependency at runtime, either in the runfiles directory (if available) + > or using the runfiles manifest. + + > This is similar to root path (a.k.a. [short_path](https://bazel.build/rules/lib/File#short_path)) + > in that it does not contain configuration prefixes, but differs in that it always starts with the + > name of the repository. + + > The rlocation path of a `File` in an external repository repo will start with `repo/`, followed by the + > repository-relative path. + + > Passing this path to a binary and resolving it to a file system path using the runfiles libraries + > is the preferred approach to find dependencies at runtime. Compared to root path, it has the + > advantage that it works on all platforms and even if the runfiles directory is not available. + + Args: + ctx: starlark rule execution context + file: a `File` object + + Returns: + The rlocationpath for the `File` + """ + if file.short_path.startswith("../"): + return file.short_path[3:] + else: + return ctx.workspace_name + "/" + file.short_path diff --git a/dotnet/private/rules/common/binary.bzl b/dotnet/private/rules/common/binary.bzl index 365ad9c8..bef8f1be 100644 --- a/dotnet/private/rules/common/binary.bzl +++ b/dotnet/private/rules/common/binary.bzl @@ -2,7 +2,6 @@ Base rule for building .Net binaries """ -load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path") load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo") load( @@ -12,6 +11,7 @@ load( "generate_runtimeconfig", "is_core_framework", "is_standard_framework", + "to_rlocation_path", ) load("//dotnet/private:providers.bzl", "DotnetBinaryInfo") @@ -42,8 +42,8 @@ def _create_launcher(ctx, runfiles, executable): template = ctx.file._launcher_bat, output = launcher, substitutions = { - "TEMPLATED_dotnet": to_manifest_path(ctx, runtime.files_to_run.executable), - "TEMPLATED_executable": to_manifest_path(ctx, executable), + "TEMPLATED_dotnet": to_rlocation_path(ctx, runtime.files_to_run.executable), + "TEMPLATED_executable": to_rlocation_path(ctx, executable), }, is_executable = True, ) @@ -52,8 +52,8 @@ def _create_launcher(ctx, runfiles, executable): template = ctx.file._launcher_sh, output = launcher, substitutions = { - "TEMPLATED_dotnet": to_manifest_path(ctx, runtime.files_to_run.executable), - "TEMPLATED_executable": to_manifest_path(ctx, executable), + "TEMPLATED_dotnet": to_rlocation_path(ctx, runtime.files_to_run.executable), + "TEMPLATED_executable": to_rlocation_path(ctx, executable), }, is_executable = True, ) diff --git a/dotnet/private/rules/publish_binary/publish_binary.bzl b/dotnet/private/rules/publish_binary/publish_binary.bzl index bbad154f..e22e2aae 100644 --- a/dotnet/private/rules/publish_binary/publish_binary.bzl +++ b/dotnet/private/rules/publish_binary/publish_binary.bzl @@ -2,9 +2,8 @@ Rules for compiling F# binaries. """ -load("@aspect_bazel_lib//lib:paths.bzl", "to_manifest_path") load("@bazel_skylib//lib:shell.bzl", "shell") -load("//dotnet/private:common.bzl", "generate_depsjson", "generate_runtimeconfig") +load("//dotnet/private:common.bzl", "generate_depsjson", "generate_runtimeconfig", "to_rlocation_path") load("//dotnet/private:providers.bzl", "DotnetAssemblyCompileInfo", "DotnetAssemblyRuntimeInfo", "DotnetBinaryInfo", "DotnetPublishBinaryInfo") load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition") @@ -162,7 +161,7 @@ def _copy_to_publish(ctx, runtime_identifier, publish_binary_info, binary_info, # RUNFILES_DIR/RUNFILES_MANIFEST_FILE/RUNFILES_MANIFEST_ONLY is not set). for file in data: inputs.append(file) - manifest_path = to_manifest_path(ctx, file) + manifest_path = to_rlocation_path(ctx, file) output = ctx.actions.declare_file( "{}/publish/{}/{}.runfiles/{}".format(ctx.label.name, runtime_identifier, binary_info.app_host.basename, manifest_path), ) diff --git a/dotnet/repositories.bzl b/dotnet/repositories.bzl index 21048c78..af3c2a01 100644 --- a/dotnet/repositories.bzl +++ b/dotnet/repositories.bzl @@ -29,13 +29,6 @@ def rules_dotnet_dependencies(): ], ) - http_archive( - name = "aspect_bazel_lib", - sha256 = "ee95bbc80f9ca219b93a8cc49fa19a2d4aa8649ddc9024f46abcdd33935753ca", - strip_prefix = "bazel-lib-1.29.2", - url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.29.2/bazel-lib-v1.29.2.tar.gz", - ) - http_archive( name = "platforms", urls = [