Skip to content

Commit 4b4d832

Browse files
authored
Upgrade to Bazel 8 (#479)
* Build everything with Bazel 7 and 8 * Simplified `publish_binary` runfiles handling. This might be a breaking change for some users if they are e.g. not using `include_runfiles` in `pkg_tar`
1 parent d47a333 commit 4b4d832

36 files changed

+230
-244
lines changed

.bazelci/presubmit.yml

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,67 @@ buildifier:
33
version: 7.1.0
44

55
matrix:
6-
platform: ["windows", "ubuntu2004", "rbe_ubuntu1604", "macos", "macos_arm64", "ubuntu2004_arm64", "windows_arm64"]
7-
working_directory: ["", "examples"]
8-
strict_deps: ["--@rules_dotnet//dotnet/settings:strict_deps=true", "--@rules_dotnet//dotnet/settings:strict_deps=false"]
9-
flag_combo: [["--enable_bzlmod", "--@rules_dotnet//dotnet/settings:strict_deps=true"], ["--enable_bzlmod", "--@rules_dotnet//dotnet/settings:strict_deps=false"]]
6+
bazel: ["7.x", "8.x"]
7+
platform:
8+
[
9+
"windows",
10+
"ubuntu2004",
11+
"rbe_ubuntu1604",
12+
"macos",
13+
"macos_arm64",
14+
"ubuntu2004_arm64",
15+
"windows_arm64",
16+
]
17+
flag_combo:
18+
[
19+
["--@rules_dotnet//dotnet/settings:strict_deps=true"],
20+
["--@rules_dotnet//dotnet/settings:strict_deps=false"],
21+
]
1022
e2e_working_directory: ["e2e/net8.0", "e2e/net9.0"]
1123

1224
tasks:
1325
test_all:
1426
name: Build and test
27+
bazel: ${{ bazel }}
1528
platform: ${{ platform }}
16-
working_directory: ${{ working_directory }}
29+
working_directory: ""
1730
include_json_profile:
1831
- build
1932
- test
2033
build_targets:
2134
- "//..."
35+
- "-//docs/..."
2236
test_targets:
2337
- "//..."
38+
- "-//docs/..."
2439
build_flags: ${{ flag_combo }}
2540
test_flags: ${{ flag_combo }}
41+
examples:
42+
name: Build and test
43+
bazel: ${{ bazel }}
44+
platform: ${{ platform }}
45+
working_directory: "examples"
46+
include_json_profile:
47+
- build
48+
- test
49+
build_targets:
50+
- "//..."
51+
test_targets:
52+
- "//..."
53+
build_flags: ${{ flag_combo }}
54+
test_flags: ${{ flag_combo }}
55+
docs:
56+
name: Docs
57+
bazel: 8.x
58+
platform: ubuntu2004
59+
working_directory: ""
60+
build_targets:
61+
- "//docs/..."
62+
test_targets:
63+
- "//docs/..."
2664
e2e:
2765
name: ${{ e2e_working_directory }}
66+
bazel: ${{ bazel }}
2867
platform: ${{ platform }}
2968
working_directory: ${{ e2e_working_directory }}
3069
include_json_profile:

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.1.1
1+
8.1.1

.bcr/presubmit.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
bcr_test_module:
22
module_path: "e2e/smoke"
33
matrix:
4-
platform: ["windows", "ubuntu1804", "macos", "macos_arm64", "ubuntu2004_arm64", "windows_arm64"]
5-
bazel: ["7.x"]
4+
platform:
5+
[
6+
"windows",
7+
"ubuntu1804",
8+
"macos",
9+
"macos_arm64",
10+
"ubuntu2004_arm64",
11+
"windows_arm64",
12+
]
13+
bazel: ["7.x", "8.x"]
614
tasks:
715
run_tests:
816
name: "Run smoke test"

MODULE.bazel

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ bazel_dep(name = "platforms", version = "0.0.10")
3333
bazel_dep(name = "aspect_bazel_lib", version = "2.9.1")
3434

3535
# Dev dependencies
36-
bazel_dep(name = "stardoc", version = "0.7.1", dev_dependency = True)
37-
bazel_dep(name = "rules_pkg", version = "1.0.1", dev_dependency = True)
38-
bazel_dep(name = "gazelle", version = "0.39.1", dev_dependency = True, repo_name = "bazel_gazelle")
36+
bazel_dep(name = "stardoc", version = "0.8.0", dev_dependency = True)
37+
bazel_dep(name = "rules_pkg", version = "1.1.0", dev_dependency = True)
38+
bazel_dep(name = "gazelle", version = "0.42.0", dev_dependency = True, repo_name = "bazel_gazelle")
3939
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.7.1", dev_dependency = True)
40-
bazel_dep(name = "rules_cc", version = "0.0.12", dev_dependency = True)
41-
bazel_dep(name = "rules_testing", version = "0.6.0", dev_dependency = True)
40+
bazel_dep(name = "rules_cc", version = "0.1.1", dev_dependency = True)
41+
bazel_dep(name = "rules_testing", version = "0.7.0", dev_dependency = True)
42+
bazel_dep(name = "bazel_ci_rules", version = "1.0.0", dev_dependency = True)
4243
bazel_dep(name = "dotnet_test_resources_other_repo", version = "", dev_dependency = True)
4344
local_path_override(
4445
module_name = "dotnet_test_resources_other_repo",
@@ -47,3 +48,6 @@ local_path_override(
4748

4849
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)
4950
use_repo(rules_dotnet_dev_nuget_packages_extension, "paket.rules_dotnet_dev_nuget_packages")
51+
52+
internal_dev_deps = use_extension("//dotnet:internal_dev_deps.bzl", "internal_dev_deps", dev_dependency = True)
53+
use_repo(internal_dev_deps, "buildkite_config")

WORKSPACE

Lines changed: 0 additions & 1 deletion
This file was deleted.

WORKSPACE.bzlmod

Lines changed: 0 additions & 20 deletions
This file was deleted.

docs/csharp_nunit_test.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/defs.md

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/fsharp_nunit_test.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dotnet/internal_dev_deps.bzl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""Module extension for internal dev_dependency=True setup."""
2+
3+
load("@bazel_ci_rules//:rbe_repo.bzl", "rbe_preconfig")
4+
5+
def _internal_dev_deps_impl(mctx):
6+
_ = mctx # @unused
7+
8+
rbe_preconfig(
9+
name = "buildkite_config",
10+
toolchain = "ubuntu1804-bazel-java11",
11+
)
12+
13+
internal_dev_deps = module_extension(
14+
implementation = _internal_dev_deps_impl,
15+
doc = "This extension creates internal rules_dotnet dev dependencies.",
16+
)

dotnet/private/rules/publish_binary/publish_binary.bzl

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Rules for compiling F# binaries.
44

55
load("@bazel_skylib//lib:paths.bzl", "paths")
66
load("@bazel_skylib//lib:shell.bzl", "shell")
7-
load("//dotnet/private:common.bzl", "generate_depsjson", "generate_runtimeconfig", "to_rlocation_path")
7+
load("//dotnet/private:common.bzl", "generate_depsjson", "generate_runtimeconfig")
88
load("//dotnet/private:providers.bzl", "DotnetAssemblyCompileInfo", "DotnetAssemblyRuntimeInfo", "DotnetBinaryInfo")
99
load("//dotnet/private/transitions:default_transition.bzl", "default_transition")
1010
load("//dotnet/private/transitions:tfm_transition.bzl", "tfm_transition")
@@ -27,7 +27,7 @@ def _get_assembly_files(assembly_info, transitive_runtime_deps):
2727
data += dep.data
2828
return (libs, native, data, appsetting_files)
2929

30-
def _copy_to_publish(ctx, runtime_identifier, runtime_pack_info, binary_info, assembly_info, transitive_runtime_deps, repo_mapping_manifest):
30+
def _copy_to_publish(ctx, runtime_identifier, runtime_pack_info, binary_info, assembly_info, transitive_runtime_deps):
3131
is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo])
3232
inputs = [binary_info.dll]
3333
main_dll_copy = ctx.actions.declare_file(
@@ -63,23 +63,15 @@ def _copy_to_publish(ctx, runtime_identifier, runtime_pack_info, binary_info, as
6363
# the runfiles lib. End users should not expect files in the `data` attribute
6464
# to be resolvable by relative paths. They need to use the runfiles lib.
6565
#
66-
# Since we want the published binary and all it's files to be easily extracted
67-
# into e.g. a tar/zip/docker we manually create the runfiles structure because
68-
# there are many sharp edges with extracting runfiles from Bazel. By manually
69-
# creating the runfiles structure the runfiles are just normal files in the
70-
# DefaultInfo provider and can thus be easily forwarded to filegroups/tars/containers.
66+
# The end-user will have to use rules that also pull the runfiles. For examples if
67+
# they use rules_pkg they have to use `include_runfiles` on the pkt_tar rule.
7168
#
7269
# The runfiles library follows the spec and tries to find a `<DLL>.runfiles` directory
7370
# next to the the DLL based on argv0 of the running process if
7471
# RUNFILES_DIR/RUNFILES_MANIFEST_FILE/RUNFILES_MANIFEST_ONLY is not set).
72+
runfiles = []
7573
for file in data:
76-
inputs.append(file)
77-
manifest_path = to_rlocation_path(ctx, file)
78-
output = ctx.actions.declare_file(
79-
"{}/publish/{}/{}.runfiles/{}".format(ctx.label.name, runtime_identifier, paths.replace_extension(binary_info.dll.basename, ""), manifest_path),
80-
)
81-
outputs.append(output)
82-
_copy_file(script_body, file, output, is_windows = is_windows)
74+
runfiles.append(file)
8375

8476
for file in appsetting_files:
8577
inputs.append(file)
@@ -89,16 +81,6 @@ def _copy_to_publish(ctx, runtime_identifier, runtime_pack_info, binary_info, as
8981
outputs.append(output)
9082
_copy_file(script_body, file, output, is_windows = is_windows)
9183

92-
# The repo mapping manifest is not part of the runfiles by default so we
93-
# copy it to the runfiles directory manually.
94-
if repo_mapping_manifest:
95-
inputs.append(repo_mapping_manifest)
96-
output = ctx.actions.declare_file(
97-
"{}/publish/{}/{}.runfiles/_repo_mapping".format(ctx.label.name, runtime_identifier, paths.replace_extension(binary_info.dll.basename, "")),
98-
)
99-
outputs.append(output)
100-
_copy_file(script_body, repo_mapping_manifest, output, is_windows = is_windows)
101-
10284
# In case the publish is self-contained there needs to be a runtime pack available
10385
# with the runtime dependencies that are required for the targeted runtime.
10486
# The runtime pack contents should always be copied to the root of the publish folder
@@ -129,7 +111,7 @@ def _copy_to_publish(ctx, runtime_identifier, runtime_pack_info, binary_info, as
129111
tools = [copy_script],
130112
)
131113

132-
return (main_dll_copy, outputs)
114+
return (main_dll_copy, outputs, runfiles)
133115

134116
def _create_shim_exe(ctx, apphost_pack_info, dll):
135117
windows_constraint = ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]
@@ -171,8 +153,6 @@ def _generate_depsjson(
171153
)
172154

173155
def _publish_binary_impl(ctx):
174-
repo_mapping_manifest = ctx.attr.binary[0][DefaultInfo].files_to_run.repo_mapping_manifest
175-
176156
assembly_compile_info = ctx.attr.binary[0][DotnetAssemblyCompileInfo]
177157
assembly_runtime_info = ctx.attr.binary[0][DotnetAssemblyRuntimeInfo]
178158
binary_info = ctx.attr.binary[0][DotnetBinaryInfo]
@@ -184,14 +164,13 @@ def _publish_binary_impl(ctx):
184164
runtime_identifier = ctx.attr.runtime_identifier if ctx.attr.runtime_identifier else binary_info.runtime_pack_info.runtime_identifier
185165
roll_forward_behavior = ctx.attr.roll_forward_behavior
186166

187-
(main_dll, runfiles) = _copy_to_publish(
167+
(main_dll, outputs, runfiles) = _copy_to_publish(
188168
ctx,
189169
runtime_identifier,
190170
runtime_pack_info,
191171
binary_info,
192172
assembly_runtime_info,
193173
transitive_runtime_deps,
194-
repo_mapping_manifest,
195174
)
196175

197176
apphost_shim = _create_shim_exe(ctx, binary_info.apphost_pack_info, main_dll)
@@ -225,8 +204,8 @@ def _publish_binary_impl(ctx):
225204
return [
226205
DefaultInfo(
227206
executable = apphost_shim,
228-
files = depset([apphost_shim, main_dll, runtimeconfig, depsjson] + runfiles),
229-
runfiles = ctx.runfiles(files = [apphost_shim, main_dll, runtimeconfig, depsjson] + runfiles),
207+
files = depset([apphost_shim, main_dll, runtimeconfig, depsjson] + outputs),
208+
runfiles = ctx.runfiles(files = [apphost_shim, main_dll, runtimeconfig, depsjson] + outputs + runfiles),
230209
),
231210
]
232211

dotnet/private/tests/publish/cross_publish/test.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@
22

33
set -euo pipefail
44

5-
if [[ $# -ne 3 ]]; then
5+
if [[ $# -lt 3 ]]; then
66
echo >&2 "Usage: $0 /path/to/binary expected_file_type expected_arch"
77
exit 1
88
fi
99

1010
binary="$1"
1111
expected_file_type="$2"
12-
expected_arch="$3"
12+
expected_arches="${@:3}"
1313

1414
out="$(file "$(readlink "${binary}")")"
1515

16-
if [[ "${out}" != *"${expected_file_type}"* || "${out}" != *"${expected_arch}"* ]]; then
17-
echo >&2 "Wrong file type: ${out}"
18-
exit 1
19-
fi
16+
# Loop over all expected arches and check if the output contains any of them
17+
for expected_arch in ${expected_arches}; do
18+
if [[ "${out}" == *"${expected_arch}"* ]]; then
19+
if [[ "${out}" == *"${expected_file_type}"* ]]; then
20+
exit 0
21+
fi
22+
fi
23+
done
24+
25+
echo >&2 "Wrong file type: ${out}"
26+
exit 1
27+

dotnet/private/tests/publish/cross_publish/tests.bzl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ load(
66
)
77

88
permutations = [
9-
("linux-x64", "'ELF 64-bit'", "'x86-64'"),
10-
("linux-arm64", "'ELF 64-bit'", "'aarch64'"),
11-
("osx-x64", "'Mach-O'", "'x86_64'"),
12-
("osx-arm64", "'Mach-O'", "'arm64'"),
13-
("win-x64", "'PE32+'", "'x86-64'"),
14-
("win-arm64", "'PE32+'", "'Aarch64'"),
15-
("linux-musl-x64", "'ELF 64-bit'", "'x86-64'"),
16-
("linux-musl-arm64", "'ELF 64-bit'", "'aarch64'"),
9+
("linux-x64", "'ELF 64-bit'", ["'x86-64'"]),
10+
("linux-arm64", "'ELF 64-bit'", ["'aarch64'"]),
11+
("osx-x64", "'Mach-O'", ["'x86_64'"]),
12+
("osx-arm64", "'Mach-O'", ["'arm64'"]),
13+
("win-x64", "'PE32+'", ["'x86-64'"]),
14+
# The `file` command returns different output when run on Linux/Windows
15+
("win-arm64", "'PE32+'", ["'Aarch64'", "'ARM64'"]),
16+
("linux-musl-x64", "'ELF 64-bit'", ["'x86-64'"]),
17+
("linux-musl-arm64", "'ELF 64-bit'", ["'aarch64'"]),
1718
# The permutations below are to verify that if we use a higher level rid like `fedora-x64` or `alpine-x64`
1819
# then we will find the closes rid that matches and has the runtime/apphost packs
19-
("fedora-x64", "'ELF 64-bit'", "'x86-64'"),
20-
("ubuntu.20.04-x64", "'ELF 64-bit'", "'x86-64'"),
21-
("alpine-x64", "'ELF 64-bit'", "'x86-64'"),
22-
("fedora-arm64", "'ELF 64-bit'", "'aarch64'"),
23-
("ubuntu.20.04-arm64", "'ELF 64-bit'", "'aarch64'"),
24-
("alpine-arm64", "'ELF 64-bit'", "'aarch64'"),
20+
("fedora-x64", "'ELF 64-bit'", ["'x86-64'"]),
21+
("ubuntu.20.04-x64", "'ELF 64-bit'", ["'x86-64'"]),
22+
("alpine-x64", "'ELF 64-bit'", ["'x86-64'"]),
23+
("fedora-arm64", "'ELF 64-bit'", ["'aarch64'"]),
24+
("ubuntu.20.04-arm64", "'ELF 64-bit'", ["'aarch64'"]),
25+
("alpine-arm64", "'ELF 64-bit'", ["'aarch64'"]),
2526
]
2627

2728
# buildifier: disable=unnamed-macro
@@ -41,8 +42,7 @@ def tests():
4142
args = [
4243
"$(rootpath :cross_publish_{})".format(rid),
4344
expected_file_type,
44-
expected_arch,
45-
],
45+
] + expected_arch,
4646
data = [
4747
":cross_publish_{}".format(rid),
4848
],

0 commit comments

Comments
 (0)