Skip to content

Commit

Permalink
Remove dependency on Aspect's bazel-lib (#409)
Browse files Browse the repository at this point in the history
  • Loading branch information
purkhusid authored Jan 22, 2024
1 parent 311e019 commit 1226189
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ 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
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")
1 change: 0 additions & 1 deletion dotnet/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ bzl_library(
deps = [
":providers",
":semver",
"@aspect_bazel_lib//lib:paths",
"@bazel_skylib//lib:sets",
],
)
Expand Down
39 changes: 36 additions & 3 deletions dotnet/private/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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
10 changes: 5 additions & 5 deletions dotnet/private/rules/common/binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -12,6 +11,7 @@ load(
"generate_runtimeconfig",
"is_core_framework",
"is_standard_framework",
"to_rlocation_path",
)
load("//dotnet/private:providers.bzl", "DotnetBinaryInfo")

Expand Down Expand Up @@ -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,
)
Expand All @@ -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,
)
Expand Down
5 changes: 2 additions & 3 deletions dotnet/private/rules/publish_binary/publish_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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),
)
Expand Down
7 changes: 0 additions & 7 deletions dotnet/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 1226189

Please sign in to comment.