Skip to content

Commit 4c3d093

Browse files
authored
Merge pull request #12109 from deannagarcia/cherrypickOSX
Cherrypick osx static linking fix
2 parents af7f9d5 + 964a7f0 commit 4c3d093

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ cc_binary(
179179
linkopts = LINK_OPTS,
180180
features = select({
181181
# This isn't possible on mac because there is no static library for lcrt0.o
182-
"@platforms//os:osx": [],
182+
"//build_defs:config_osx": [],
183183
# When cross-compiling we need to statically link all C++ libraries.
184184
"//conditions:default": ["fully_static_link"],
185185
}),

build_defs/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Internal Starlark definitions for Protobuf.
22

3+
load("@bazel_skylib//lib:selects.bzl", "selects")
34
load("@rules_cc//cc:defs.bzl", starlark_cc_proto_library = "cc_proto_library")
45
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
56
load(":cc_proto_blacklist_test.bzl", "cc_proto_blacklist_test")
@@ -83,6 +84,25 @@ config_setting(
8384
},
8485
)
8586

87+
config_setting(
88+
name = "config_osx_aarch64",
89+
values = {"cpu": "osx-aarch_64"},
90+
)
91+
92+
config_setting(
93+
name = "config_osx_x86_64",
94+
values = {"cpu": "osx-aarch_64"},
95+
)
96+
97+
selects.config_setting_group(
98+
name = "config_osx",
99+
match_any = [
100+
"@platforms//os:osx",
101+
":config_osx_aarch64",
102+
":config_osx_x86_64",
103+
]
104+
)
105+
86106
# Internal testing:
87107

88108
starlark_cc_proto_library(

toolchain/cc_toolchain_config.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def _impl(ctx):
9898
flags = [
9999
"-B" + ctx.attr.linker_path,
100100
"-lstdc++",
101+
"-lm",
101102
"--target=" + ctx.attr.target_full_name,
102103
] + ctx.attr.extra_linker_flags,
103104
),

0 commit comments

Comments
 (0)