toolchain files: reduce the number of files in the sandbox
We already know which headers are necessary, so it's wasteful to put the full zig_sdk to every sandbox. This reduces the number of files in `external/zig_sdk` from 15k to 4k or 6k, depending on the action.
This commit is contained in:
parent
0e48fc3cb4
commit
65a8d7c4bb
|
@ -319,11 +319,64 @@ def declare_files(os):
|
|||
else:
|
||||
native.exports_files(["zig"], visibility = ["//visibility:public"])
|
||||
filegroup(name = "lib/std", srcs = native.glob(["lib/std/**"]))
|
||||
|
||||
lazy_filegroups = {}
|
||||
|
||||
for target_config in target_structs():
|
||||
all_includes = [native.glob(["lib/{}/**".format(i)]) for i in target_config.includes]
|
||||
all_includes.append(getattr(target_config, "compiler_extra_includes", []))
|
||||
|
||||
cxx_tool_label = ":" + zig_tool_path(os).format(
|
||||
zig_tool = "c++",
|
||||
zigtarget = target_config.zigtarget,
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "{}_includes".format(target_config.zigtarget),
|
||||
srcs = _flatten(all_includes),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "{}_compiler_files".format(target_config.zigtarget),
|
||||
srcs = [
|
||||
":zig",
|
||||
":{}_includes".format(target_config.zigtarget),
|
||||
cxx_tool_label,
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "{}_linker_files".format(target_config.zigtarget),
|
||||
srcs = [
|
||||
":zig",
|
||||
":{}_includes".format(target_config.zigtarget),
|
||||
cxx_tool_label,
|
||||
] + native.glob([
|
||||
"lib/libc/{}/**".format(target_config.libc),
|
||||
"lib/libcxx/**",
|
||||
"lib/libcxxabi/**",
|
||||
"lib/libunwind/**",
|
||||
"lib/compiler_rt/**",
|
||||
"lib/std/**",
|
||||
"lib/*.zig",
|
||||
"lib/*.h",
|
||||
]),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "{}_all_files".format(target_config.zigtarget),
|
||||
srcs = [
|
||||
":{}_linker_files".format(target_config.zigtarget),
|
||||
":{}_compiler_files".format(target_config.zigtarget),
|
||||
],
|
||||
)
|
||||
|
||||
for d in _DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
|
||||
d = "lib/" + d
|
||||
if d not in lazy_filegroups:
|
||||
lazy_filegroups[d] = filegroup(name = d, srcs = native.glob([d + "/**"]))
|
||||
|
||||
def _flatten(iterable):
|
||||
result = []
|
||||
for element in iterable:
|
||||
result += element
|
||||
return result
|
||||
|
|
|
@ -60,10 +60,10 @@ def declare_cc_toolchains(os, zig_sdk_path):
|
|||
name = zigtarget + "_cc",
|
||||
toolchain_identifier = zigtarget + "-toolchain",
|
||||
toolchain_config = ":%s_cc_config" % zigtarget,
|
||||
all_files = "@zig_sdk//:all",
|
||||
ar_files = "@zig_sdk//:all",
|
||||
compiler_files = "@zig_sdk//:all",
|
||||
linker_files = "@zig_sdk//:all",
|
||||
all_files = "@zig_sdk//:%s_all_files" % zigtarget,
|
||||
ar_files = "@zig_sdk//:zig",
|
||||
compiler_files = "@zig_sdk//:%s_compiler_files" % zigtarget,
|
||||
linker_files = "@zig_sdk//:%s_linker_files" % zigtarget,
|
||||
dwp_files = "@zig_sdk//:empty",
|
||||
objcopy_files = "@zig_sdk//:empty",
|
||||
strip_files = "@zig_sdk//:empty",
|
||||
|
|
|
@ -41,8 +41,6 @@ def target_structs():
|
|||
return ret
|
||||
|
||||
def _target_darwin(gocpu, zigcpu):
|
||||
min_os = "10"
|
||||
if zigcpu == "aarch64":
|
||||
min_os = "11"
|
||||
return struct(
|
||||
gotarget = "darwin_{}".format(gocpu),
|
||||
|
@ -53,9 +51,11 @@ def _target_darwin(gocpu, zigcpu):
|
|||
"libc/include/{}-macos.{}-none".format(zigcpu, min_os),
|
||||
"libc/include/any-macos.{}-any".format(min_os),
|
||||
"libc/include/any-macos-any",
|
||||
"include",
|
||||
],
|
||||
dynamic_library_linkopts = ["-Wl,-undefined=dynamic_lookup"],
|
||||
copts = [],
|
||||
libc = "darwin",
|
||||
bazel_target_cpu = "darwin",
|
||||
constraint_values = [
|
||||
"@platforms//os:macos",
|
||||
|
@ -69,11 +69,14 @@ def _target_windows(gocpu, zigcpu):
|
|||
gotarget = "windows_{}".format(gocpu),
|
||||
zigtarget = "{}-windows-gnu".format(zigcpu),
|
||||
includes = [
|
||||
"libc/mingw",
|
||||
"libunwind/include",
|
||||
"libc/include/any-windows-any",
|
||||
"include",
|
||||
],
|
||||
dynamic_library_linkopts = [],
|
||||
copts = [],
|
||||
libc = "mingw",
|
||||
bazel_target_cpu = "x64_windows",
|
||||
constraint_values = [
|
||||
"@platforms//os:windows",
|
||||
|
@ -100,12 +103,14 @@ def _target_linux_gnu(gocpu, zigcpu, glibc_version):
|
|||
(["libc/include/x86-linux-any"] if zigcpu == "x86_64" else []) +
|
||||
(["libc/include/{}-linux-any".format(zigcpu)] if zigcpu != "x86_64" else []) + [
|
||||
"libc/include/any-linux-any",
|
||||
"include",
|
||||
],
|
||||
toplevel_include = ["glibc-hacks"] if fcntl_hack else [],
|
||||
compiler_extra_includes = ["glibc-hacks/glibchack-fcntl.h"] if fcntl_hack else [],
|
||||
linker_version_scripts = ["glibc-hacks/fcntl.map"] if fcntl_hack else [],
|
||||
dynamic_library_linkopts = [],
|
||||
copts = [],
|
||||
libc = "glibc",
|
||||
bazel_target_cpu = "k8",
|
||||
constraint_values = [
|
||||
"@platforms//os:linux",
|
||||
|
@ -127,9 +132,11 @@ def _target_linux_musl(gocpu, zigcpu):
|
|||
(["libc/include/x86-linux-any"] if zigcpu == "x86_64" else []) +
|
||||
(["libc/include/{}-linux-any".format(zigcpu)] if zigcpu != "x86_64" else []) + [
|
||||
"libc/include/any-linux-any",
|
||||
"include",
|
||||
],
|
||||
dynamic_library_linkopts = [],
|
||||
copts = ["-D_LIBCPP_HAS_MUSL_LIBC", "-D_LIBCPP_HAS_THREAD_API_PTHREAD"],
|
||||
libc = "musl",
|
||||
bazel_target_cpu = "k8",
|
||||
constraint_values = [
|
||||
"@platforms//os:linux",
|
||||
|
|
Loading…
Reference in New Issue