1load(
2    "@nix_config//:config.bzl",
3    "CLANG",
4    "CLANG_LIB",
5    "CLANG_LIB_VERSION",
6    "LLVM",
7    "SDK_UNIVERSAL_APPLE_IOS",
8)
9load("@rules_cc//cc:defs.bzl", "cc_toolchain")
10load("//bazel/toolchain_rules:llvm_cc_toolchain_config.bzl", "llvm_cc_toolchain_config")
11
12llvm_cc_toolchain_config(
13    name = "cc_toolchain_config",
14    archive_flags = [],
15    builtin_executable_objects = [],
16    builtin_framework_directories = [
17        "{}/System/Library/Frameworks".format(SDK_UNIVERSAL_APPLE_IOS),
18    ],
19    builtin_frameworks = [],
20    builtin_include_directories = [
21        "{}/usr/include/c++/v1".format(SDK_UNIVERSAL_APPLE_IOS),
22        "{}/lib/clang/{}/include".format(CLANG_LIB, CLANG_LIB_VERSION),
23        "{}/usr/include".format(SDK_UNIVERSAL_APPLE_IOS),
24    ],
25    builtin_libraries = [],
26    builtin_library_directories = [
27        "{}/usr/lib".format(SDK_UNIVERSAL_APPLE_IOS),
28    ],
29    clang = CLANG,
30    compile_flags = [
31        "-fno-exceptions",
32        "-Werror",
33        "-Wall",
34        "-Wthread-safety",
35        "-Wself-assign",
36    ],
37    dbg_compile_flags = [
38        "-g",
39        "-fstandalone-debug",
40    ],
41    dbg_link_flags = [],
42    fastbuild_compile_flags = [],
43    fastbuild_link_flags = [],
44    link_flags = [
45        "-fatal_warnings",
46        "-arch",
47        "arm64",
48        "-platform_version",
49        "ios",
50        "16.0.0",
51        "16.2",
52        "-headerpad_max_install_names",
53        "-undefined",
54        "dynamic_lookup",
55    ],
56    llvm = LLVM,
57    opt_compile_flags = [
58        "-g0",
59        "-O2",
60        "-D_FORTIFY_SOURCE=1",
61        "-DNDEBUG",
62        "-ffunction-sections",
63        "-fdata-sections",
64    ],
65    opt_link_flags = [
66        "--gc-sections",
67    ],
68    tags = ["manual"],
69    target = "aarch64-apple-ios",
70)
71
72cc_toolchain(
73    name = "cc_toolchain",
74    all_files = "@nix_config//:config.bzl",
75    ar_files = "@nix_config//:config.bzl",
76    as_files = "@nix_config//:config.bzl",
77    compiler_files = "@nix_config//:config.bzl",
78    coverage_files = "@nix_config//:config.bzl",
79    dwp_files = "@nix_config//:config.bzl",
80    linker_files = "@nix_config//:config.bzl",
81    objcopy_files = "@nix_config//:config.bzl",
82    strip_files = "@nix_config//:config.bzl",
83    tags = ["manual"],
84    toolchain_config = "cc_toolchain_config",
85)
86
87toolchain(
88    name = "toolchain",
89    exec_compatible_with = [
90        "@platforms//cpu:x86_64",
91        "@platforms//os:nixos",
92    ],
93    target_compatible_with = [
94        "@platforms//cpu:aarch64",
95        "@platforms//os:ios",
96    ],
97    toolchain = ":cc_toolchain",
98    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
99)
100