File
Blob: build/wd_cc_binary.bzl
| 1 | """wd_cc_binary definition""" |
| 2 | |
| 3 | load("@rules_cc//cc:cc_binary.bzl", "cc_binary") |
| 4 | |
| 5 | def wd_cc_binary( |
| 6 | name, |
| 7 | linkopts = [], |
| 8 | visibility = None, |
| 9 | deps = [], |
| 10 | target_compatible_with = [], |
| 11 | **kwargs): |
| 12 | """Wrapper for cc_binary that sets common attributes |
| 13 | """ |
| 14 | cc_binary( |
| 15 | name = name, |
| 16 | # -dead_strip is the macOS equivalent of -ffunction-sections, -Wl,--gc-sections. |
| 17 | # -no_exported_symbols is used to not include the exports trie, which significantly reduces |
| 18 | # binary sizes. Unfortunately, the flag and the exports trie are poorly documented. Based |
| 19 | # on analyzing the binary sections with and without the flag, the information being removed |
| 20 | # consists of weak binding info, export binding info and stub bindings as described in |
| 21 | # http://www.newosxbook.com/articles/DYLD.html. The flag itself is described in |
| 22 | # https://www.wwdcnotes.com/notes/wwdc22/110362/. |
| 23 | # The affected sections appear to not be needed for debugging and are only used when |
| 24 | # external code needs to look up bindings in a binary, e.g. when loading a plugin |
| 25 | # (mac-specific feature). In particular, the symbol table is not affected (the name of the |
| 26 | # flag is misleading here). |
| 27 | linkopts = linkopts + select({ |
| 28 | "@//:use_dead_strip": ["-Wl,-dead_strip", "-Wl,-no_exported_symbols"], |
| 29 | "//conditions:default": [""], |
| 30 | }), |
| 31 | target_compatible_with = select({ |
| 32 | "@//build/config:no_build": ["@platforms//:incompatible"], |
| 33 | "//conditions:default": [], |
| 34 | }) + target_compatible_with, |
| 35 | visibility = visibility, |
| 36 | deps = deps, |
| 37 | **kwargs |
| 38 | ) |
| 39 | |
| 40 | pkg = native.package_name().removeprefix("src/") |
| 41 | cross_alias = name + "_cross" |
| 42 | prebuilt_binary_name = name.removesuffix("_bin") |
| 43 | native.alias( |
| 44 | name = cross_alias, |
| 45 | visibility = visibility, |
| 46 | actual = select({ |
| 47 | "@//build/config:prebuilt_binaries_arm64": "@//:bin.arm64/tmp/{}/{}.aarch64-linux-gnu".format(pkg, prebuilt_binary_name), |
| 48 | "//conditions:default": name, |
| 49 | }), |
| 50 | testonly = kwargs.get("testonly", False), |
| 51 | ) |