Skip to content

Commit 666c686

Browse files
authored
[bazel] Codesign debugserver on macOS (#91789)
This tool doesn't work unless it's signed with the entitlements used here. We should probably consider using the macos_command_line_application rule from rules_apple which manages this more flexibly for us, but for now this works. This uses apple_genrule as opposed to genrule since the former encodes the Xcode environment info into the action so it is correctly invalidated if that changes.
1 parent f32f6d1 commit 666c686

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

utils/bazel/WORKSPACE

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ maybe(
5656
name = "vulkan_sdk",
5757
)
5858

59+
http_archive(
60+
name = "build_bazel_apple_support",
61+
sha256 = "c4bb2b7367c484382300aee75be598b92f847896fb31bbd22f3a2346adf66a80",
62+
url = "https://github.com/bazelbuild/apple_support/releases/download/1.15.1/apple_support.1.15.1.tar.gz",
63+
)
64+
65+
load(
66+
"@build_bazel_apple_support//lib:repositories.bzl",
67+
"apple_support_dependencies",
68+
)
69+
70+
apple_support_dependencies()
71+
5972
# llvm libc math tests reply on `mpfr`.
6073
# The availability of `mpfr` is controlled by a flag and can be either `disable`, `system` or `external`.
6174
# Continuous integration uses `system` to speed up the build process (see .bazelrc).

utils/bazel/llvm-project-overlay/lldb/BUILD.bazel

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
load("@bazel_skylib//lib:selects.bzl", "selects")
66
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
77
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
8+
load("@build_bazel_apple_support//rules:apple_genrule.bzl", "apple_genrule")
89
load("//:vars.bzl", "LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH", "LLVM_VERSION_SUFFIX", "PACKAGE_VERSION")
910
load("//lldb/source/Plugins:plugin_config.bzl", "DEFAULT_PLUGINS", "DEFAULT_SCRIPT_PLUGINS", "OBJCPP_COPTS")
1011
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")
@@ -800,24 +801,20 @@ gentbl_cc_library(
800801
deps = ["//llvm:OptParserTdFiles"],
801802
)
802803

804+
alias(
805+
name = "gdb-server",
806+
actual = select({
807+
"@platforms//os:macos": ":debugserver",
808+
"//conditions:default": ":lldb-server",
809+
}),
810+
)
811+
803812
cc_binary(
804813
name = "lldb",
805814
srcs = glob([
806815
"tools/driver/*.cpp",
807816
"tools/driver/*.h",
808817
]),
809-
data = [
810-
":lldb-argdumper",
811-
] + select({
812-
"@platforms//os:macos": [
813-
":debugserver",
814-
":lldb-server",
815-
],
816-
"@platforms//os:linux": [
817-
":lldb-server",
818-
],
819-
"//conditions:default": [],
820-
}),
821818
deps = [
822819
":APIHeaders",
823820
":Host",
@@ -896,7 +893,7 @@ expand_template(
896893
)
897894

898895
cc_binary(
899-
name = "debugserver",
896+
name = "debugserver_unsigned",
900897
srcs = [
901898
"tools/debugserver/source/debugserver.cpp",
902899
":debugserver_version_gen",
@@ -914,6 +911,21 @@ cc_binary(
914911
],
915912
)
916913

914+
apple_genrule(
915+
name = "debugserver_signed",
916+
srcs = [":debugserver_unsigned"],
917+
outs = ["debugserver"],
918+
cmd = "cp $(SRCS) $(OUTS) && xcrun codesign -f -s - --entitlements $(location tools/debugserver/resources/debugserver-macosx-entitlements.plist) $(OUTS)",
919+
tags = ["nobuildkite"],
920+
target_compatible_with = select({
921+
"@platforms//os:macos": [],
922+
"//conditions:default": ["@platforms//:incompatible"],
923+
}),
924+
tools = [
925+
"tools/debugserver/resources/debugserver-macosx-entitlements.plist",
926+
],
927+
)
928+
917929
cc_binary(
918930
name = "lldb-argdumper",
919931
srcs = glob(["tools/argdumper/*.cpp"]),

0 commit comments

Comments
 (0)