Skip to content

Commit 60e8255

Browse files
authored
cc: toolchain: add support for aarch64-darwin-llvm [BUILD-563] (#67)
- Adds aarch64-darwin-llvm toolchain - Flips -ffp-contract to off - enables warnings as errors on macos
1 parent b7b94df commit 60e8255

File tree

17 files changed

+262
-36
lines changed

17 files changed

+262
-36
lines changed

WORKSPACE renamed to WORKSPACE.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ http_archive(
4545
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
4646

4747
# If you use WORKSPACE.bazel, use the following line instead of the bare gazelle_dependencies():
48-
# gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE.bazel")
49-
gazelle_dependencies()
48+
gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE.bazel")
5049

5150
http_archive(
5251
name = "com_google_protobuf",

cc/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ config_setting(
5454
visibility = ["//visibility:public"],
5555
)
5656

57+
# Disable warnings as errors with --@rules_swiftnav//cc:warnings_as_errors=false
58+
bool_flag(
59+
name = "warnings_as_errors",
60+
build_setting_default = True,
61+
visibility = ["//visibility:public"],
62+
)
63+
64+
config_setting(
65+
name = "_disable_warnings_as_errors",
66+
flag_values = {":warnings_as_errors": "false"},
67+
visibility = ["//visibility:public"],
68+
)
69+
5770
# Allows us to experiment with building the codebase with different standards.
5871
string_flag(
5972
name = "cxx_standard",

cc/defs.bzl

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def _common_cc_opts(nocopts, pedantic = False):
5151
Label("//cc/constraints:gcc-6"): [copt for copt in GCC6_COPTS if copt not in nocopts],
5252
Label("//cc/constraints:gcc-5"): [copt for copt in GCC5_COPTS if copt not in nocopts],
5353
"//conditions:default": [copt for copt in DEFAULT_COPTS if copt not in nocopts],
54+
}) + select({
55+
Label("//cc:_disable_warnings_as_errors"): [],
56+
"//conditions:default": ["-Werror"],
5457
}) + ["-pedantic"] if pedantic else []
5558

5659
# Options specific to c++ code (exceptions, rtti, etc..)
@@ -72,16 +75,6 @@ def _common_cxx_opts(exceptions = False, rtti = False, standard = None):
7275
def _construct_local_includes(local_includes):
7376
return [construct_local_include(path) for path in local_includes]
7477

75-
# Some options like -Werror are set using toolchain features
76-
# See: https://bazel.build/docs/cc-toolchain-config-reference#features
77-
def _default_features():
78-
return select({
79-
# treat_warnings_as_errors passes the option -fatal-warnings
80-
# to the linker which ld on mac does not understand.
81-
"@platforms//os:macos": [],
82-
"//conditions:default": ["treat_warnings_as_errors"],
83-
})
84-
8578
# Disable building when --//:disable_tests=true or when building on windows
8679
def _test_compatible_with():
8780
return select({
@@ -194,8 +187,6 @@ def swift_c_library(**kwargs):
194187

195188
kwargs["copts"] = copts + c_standard + kwargs.get("copts", [])
196189

197-
kwargs["features"] = _default_features() + kwargs.get("features", [])
198-
199190
kwargs["tags"] = [LIBRARY] + kwargs.get("tags", [])
200191

201192
native.cc_library(**kwargs)
@@ -247,8 +238,6 @@ def swift_cc_library(**kwargs):
247238

248239
kwargs["copts"] = copts + cxxopts + kwargs.get("copts", [])
249240

250-
kwargs["features"] = _default_features() + kwargs.get("features", [])
251-
252241
kwargs["tags"] = [LIBRARY] + kwargs.get("tags", [])
253242

254243
native.cc_library(**kwargs)
@@ -293,8 +282,6 @@ def swift_c_tool_library(**kwargs):
293282

294283
kwargs["copts"] = copts + c_standard + kwargs.get("copts", [])
295284

296-
kwargs["features"] = _default_features() + kwargs.get("features", [])
297-
298285
native.cc_library(**kwargs)
299286

300287
def swift_cc_tool_library(**kwargs):
@@ -340,8 +327,6 @@ def swift_cc_tool_library(**kwargs):
340327

341328
kwargs["copts"] = copts + cxxopts + kwargs.get("copts", [])
342329

343-
kwargs["features"] = _default_features() + kwargs.get("features", [])
344-
345330
native.cc_library(**kwargs)
346331

347332
def swift_c_binary(**kwargs):
@@ -382,8 +367,6 @@ def swift_c_binary(**kwargs):
382367

383368
kwargs["copts"] = copts + c_standard + kwargs.get("copts", [])
384369

385-
kwargs["features"] = _default_features() + kwargs.get("features", [])
386-
387370
kwargs["tags"] = [BINARY] + kwargs.get("tags", [])
388371

389372
native.cc_binary(**kwargs)
@@ -430,8 +413,6 @@ def swift_cc_binary(**kwargs):
430413

431414
kwargs["copts"] = copts + cxxopts + kwargs.get("copts", [])
432415

433-
kwargs["features"] = _default_features() + kwargs.get("features", [])
434-
435416
kwargs["tags"] = [BINARY] + kwargs.get("tags", [])
436417

437418
native.cc_binary(**kwargs)
@@ -473,8 +454,6 @@ def swift_c_tool(**kwargs):
473454

474455
kwargs["copts"] = copts + c_standard + kwargs.get("copts", [])
475456

476-
kwargs["features"] = _default_features() + kwargs.get("features", [])
477-
478457
native.cc_binary(**kwargs)
479458

480459
def swift_cc_tool(**kwargs):
@@ -517,8 +496,6 @@ def swift_cc_tool(**kwargs):
517496

518497
kwargs["copts"] = copts + cxxopts + kwargs.get("copts", [])
519498

520-
kwargs["features"] = _default_features() + kwargs.get("features", [])
521-
522499
native.cc_binary(**kwargs)
523500

524501
def swift_cc_test_library(**kwargs):

cc/repositories.bzl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@
1111
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1212
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
1313

14-
X86_64_LINUX_LLVM = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang%2Bllvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz"
14+
AARCH64_DARWIN_LLVM = "https://github.com/swift-nav/swift-toolchains/releases/download/llvm-14.0.0/clang%2Bllvm-14.0.0-arm64-apple-darwin.tar.gz"
1515

1616
X86_64_DARWIN_LLVM = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang%2Bllvm-14.0.0-x86_64-apple-darwin.tar.xz"
1717

18+
X86_64_LINUX_LLVM = "https://github.com/llvm/llvm-project/releases/download/llvmorg-14.0.0/clang%2Bllvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz"
19+
1820
def swift_cc_toolchain():
1921
maybe(
2022
http_archive,
21-
name = "x86_64-linux-llvm",
23+
name = "aarch64-darwin-llvm",
2224
build_file = Label("//cc/toolchains/llvm:llvm.BUILD.bzl"),
23-
url = X86_64_LINUX_LLVM,
24-
strip_prefix = "clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04",
25-
sha256 = "61582215dafafb7b576ea30cc136be92c877ba1f1c31ddbbd372d6d65622fef5",
25+
url = AARCH64_DARWIN_LLVM,
26+
strip_prefix = "clang+llvm-14.0.0-arm64-apple-darwin",
27+
sha256 = "f826ee92c3fedb92bad2f9f834d96f6b9db3192871bfe434124bca848ba9a2a3",
2628
)
2729

2830
maybe(
@@ -34,6 +36,16 @@ def swift_cc_toolchain():
3436
sha256 = "cf5af0f32d78dcf4413ef6966abbfd5b1445fe80bba57f2ff8a08f77e672b9b3",
3537
)
3638

39+
maybe(
40+
http_archive,
41+
name = "x86_64-linux-llvm",
42+
build_file = Label("//cc/toolchains/llvm:llvm.BUILD.bzl"),
43+
url = X86_64_LINUX_LLVM,
44+
strip_prefix = "clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04",
45+
sha256 = "61582215dafafb7b576ea30cc136be92c877ba1f1c31ddbbd372d6d65622fef5",
46+
)
47+
3748
def register_swift_cc_toolchains():
38-
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-linux:cc-toolchain-x86_64-linux")
49+
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/aarch64-darwin:cc-toolchain-aarch64-darwin")
3950
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-darwin:cc-toolchain-x86_64-darwin")
51+
native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-linux:cc-toolchain-x86_64-linux")
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Copyright (C) 2022 Swift Navigation Inc.
2+
# Contact: Swift Navigation <dev@swift-nav.com>
3+
#
4+
# This source is subject to the license found in the file 'LICENSE' which must
5+
# be be distributed together with this source. All other rights reserved.
6+
#
7+
# THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8+
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9+
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10+
11+
package(default_visibility = ["//visibility:public"])
12+
13+
load("//cc/toolchains/llvm:cc_toolchain_config.bzl", "cc_toolchain_config")
14+
15+
filegroup(
16+
name = "wrappers",
17+
srcs = glob([
18+
"wrappers/**",
19+
]),
20+
visibility = ["//visibility:public"],
21+
)
22+
23+
filegroup(
24+
name = "ar_files",
25+
srcs = [
26+
":wrappers",
27+
"@aarch64-darwin-llvm//:ar",
28+
],
29+
)
30+
31+
filegroup(
32+
name = "as_files",
33+
srcs = [
34+
":wrappers",
35+
"@aarch64-darwin-llvm//:as",
36+
],
37+
)
38+
39+
filegroup(
40+
name = "compiler_files",
41+
srcs = [
42+
":wrappers",
43+
"@aarch64-darwin-llvm//:clang",
44+
"@aarch64-darwin-llvm//:include",
45+
],
46+
)
47+
48+
filegroup(
49+
name = "dwp_files",
50+
srcs = [
51+
":wrappers",
52+
"@aarch64-darwin-llvm//:dwp",
53+
],
54+
)
55+
56+
filegroup(
57+
name = "linker_files",
58+
srcs = [
59+
":wrappers",
60+
"@aarch64-darwin-llvm//:ar",
61+
"@aarch64-darwin-llvm//:clang",
62+
"@aarch64-darwin-llvm//:lib",
63+
],
64+
)
65+
66+
filegroup(
67+
name = "objcopy_files",
68+
srcs = [
69+
":wrappers",
70+
"@aarch64-darwin-llvm//:objcopy",
71+
],
72+
)
73+
74+
filegroup(
75+
name = "strip_files",
76+
srcs = [
77+
":wrappers",
78+
"@aarch64-darwin-llvm//:strip",
79+
],
80+
)
81+
82+
filegroup(
83+
name = "all_files",
84+
srcs = [
85+
"linker_files",
86+
":compiler_files",
87+
"@aarch64-darwin-llvm//:bin",
88+
],
89+
)
90+
91+
cc_toolchain_config(
92+
name = "local-aarch64-darwin",
93+
abi_libc_version = "darwin_aarch64",
94+
abi_version = "darwin_aarch64",
95+
builtin_sysroot = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk",
96+
compiler = "clang",
97+
cxx_builtin_include_directories = [
98+
"%sysroot%/usr/include",
99+
"%sysroot%/System/Library/Frameworks",
100+
],
101+
host_system_name = "darwin-aarch64",
102+
is_darwin = True,
103+
target_cpu = "darwin",
104+
target_libc = "macosx",
105+
target_system_name = "aarch64-apple-macosx",
106+
tool_paths = {
107+
"ar": "/usr/bin/libtool",
108+
"cpp": "wrappers/clang-cpp",
109+
"gcc": "wrappers/clang",
110+
"gcov": "wrappers/llvm-profdata",
111+
"llvm-cov": "wrappers/llvm-cov",
112+
"llvm-profdata": "wrappers/llvm-profdata",
113+
"ld": "/usr/bin/ld",
114+
"nm": "wrappers/llvm-nm",
115+
"objcopy": "wrappers/llvm-objcopy",
116+
"objdump": "wrappers/llvm-objdump",
117+
"strip": "wrappers/llvm-strip",
118+
},
119+
toolchain_identifier = "clang-aarch64-darwin",
120+
toolchain_path_prefix = "external/aarch64-darwin-llvm",
121+
)
122+
123+
cc_toolchain(
124+
name = "cc-clang-aarch64-darwin",
125+
all_files = ":all_files",
126+
ar_files = ":ar_files",
127+
as_files = ":as_files",
128+
compiler_files = ":compiler_files",
129+
dwp_files = ":dwp_files",
130+
linker_files = ":linker_files",
131+
objcopy_files = ":objcopy_files",
132+
strip_files = ":strip_files",
133+
toolchain_config = ":local-aarch64-darwin",
134+
)
135+
136+
toolchain(
137+
name = "cc-toolchain-aarch64-darwin",
138+
exec_compatible_with = [
139+
"@platforms//cpu:aarch64",
140+
"@platforms//os:macos",
141+
],
142+
target_compatible_with = [
143+
"@platforms//cpu:aarch64",
144+
"@platforms//os:macos",
145+
],
146+
target_settings = None,
147+
toolchain = ":cc-clang-aarch64-darwin",
148+
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
149+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wrapper

0 commit comments

Comments
 (0)