buildifier
This commit is contained in:
parent
5973131fff
commit
dbff5afa75
11
WORKSPACE
11
WORKSPACE
@ -22,7 +22,6 @@ http_archive(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||||
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
|
||||||
|
|
||||||
@ -32,6 +31,7 @@ go_register_toolchains(version = "1.16")
|
|||||||
|
|
||||||
gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE")
|
gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE")
|
||||||
|
|
||||||
|
# protobuf is required for //:buildifier
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "com_google_protobuf",
|
name = "com_google_protobuf",
|
||||||
sha256 = "bf0e5070b4b99240183b29df78155eee335885e53a8af8683964579c214ad301",
|
sha256 = "bf0e5070b4b99240183b29df78155eee335885e53a8af8683964579c214ad301",
|
||||||
@ -40,6 +40,7 @@ http_archive(
|
|||||||
)
|
)
|
||||||
|
|
||||||
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
|
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
|
||||||
|
|
||||||
protobuf_deps()
|
protobuf_deps()
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
@ -48,10 +49,12 @@ http_archive(
|
|||||||
url = "https://github.com/bazelbuild/buildtools/archive/master.zip",
|
url = "https://github.com/bazelbuild/buildtools/archive/master.zip",
|
||||||
)
|
)
|
||||||
|
|
||||||
load("//toolchain:defs.bzl",
|
load(
|
||||||
zig_register_all_toolchains = "register_all_toolchains",
|
"//toolchain:defs.bzl",
|
||||||
zig_toolchain_repositories = "toolchain_repositories",
|
zig_register_all_toolchains = "register_all_toolchains",
|
||||||
|
zig_toolchain_repositories = "toolchain_repositories",
|
||||||
)
|
)
|
||||||
|
|
||||||
zig_toolchain_repositories()
|
zig_toolchain_repositories()
|
||||||
|
|
||||||
zig_register_all_toolchains()
|
zig_register_all_toolchains()
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
load("@zig-cc-bazel//toolchain:defs.bzl", "zig_build_macro")
|
load("@zig-cc-bazel//toolchain:defs.bzl", "zig_build_macro")
|
||||||
|
|
||||||
package(
|
package(
|
||||||
default_visibility = ["//visibility:public"]
|
default_visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
zig_build_macro(
|
zig_build_macro(
|
||||||
absolute_path={absolute_path},
|
absolute_path = {absolute_path},
|
||||||
zig_include_root={zig_include_root},
|
zig_include_root = {zig_include_root},
|
||||||
)
|
)
|
||||||
|
@ -3,8 +3,7 @@ load(":zig_toolchain.bzl", "zig_cc_toolchain_config")
|
|||||||
|
|
||||||
DEFAULT_TOOL_PATHS = {
|
DEFAULT_TOOL_PATHS = {
|
||||||
"ar": "ar",
|
"ar": "ar",
|
||||||
"gcc": "c++", # https://github.com/bazelbuild/bazel/issues/4644
|
"gcc": "c++", # https://github.com/bazelbuild/bazel/issues/4644
|
||||||
|
|
||||||
"cpp": "/usr/bin/false",
|
"cpp": "/usr/bin/false",
|
||||||
"gcov": "/usr/bin/false",
|
"gcov": "/usr/bin/false",
|
||||||
"nm": "/usr/bin/false",
|
"nm": "/usr/bin/false",
|
||||||
@ -21,77 +20,76 @@ DEFAULT_INCLUDE_DIRECTORIES = [
|
|||||||
# https://github.com/ziglang/zig/blob/0cfa39304b18c6a04689bd789f5dc4d035ec43b0/src/main.zig#L2962-L2966
|
# https://github.com/ziglang/zig/blob/0cfa39304b18c6a04689bd789f5dc4d035ec43b0/src/main.zig#L2962-L2966
|
||||||
TARGET_CONFIGS = [
|
TARGET_CONFIGS = [
|
||||||
struct(
|
struct(
|
||||||
target="x86_64-macos-gnu",
|
target = "x86_64-macos-gnu",
|
||||||
includes=[
|
includes = [
|
||||||
"libunwind/include",
|
"libunwind/include",
|
||||||
"libc/include/any-macos-any",
|
"libc/include/any-macos-any",
|
||||||
"libc/include/x86_64-macos-any",
|
"libc/include/x86_64-macos-any",
|
||||||
"libc/include/x86_64-macos-gnu",
|
"libc/include/x86_64-macos-gnu",
|
||||||
],
|
],
|
||||||
# linkopts=["-lc++", "-lc++abi"],
|
# linkopts=["-lc++", "-lc++abi"],
|
||||||
linkopts=[],
|
linkopts = [],
|
||||||
copts=[],
|
copts = [],
|
||||||
bazel_target_cpu="darwin",
|
bazel_target_cpu = "darwin",
|
||||||
constraint_values=[
|
constraint_values = [
|
||||||
"@platforms//os:macos",
|
"@platforms//os:macos",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
],
|
],
|
||||||
tool_paths={"ld": "ld64.lld"},
|
tool_paths = {"ld": "ld64.lld"},
|
||||||
),
|
),
|
||||||
|
] + [
|
||||||
struct(
|
struct(
|
||||||
target="x86_64-linux-gnu",
|
target = "x86_64-linux-gnu",
|
||||||
target_suffix = ".2.19",
|
target_suffix = ".2.19",
|
||||||
includes=[
|
includes = [
|
||||||
"libunwind/include",
|
"libunwind/include",
|
||||||
"libc/include/generic-glibc",
|
"libc/include/generic-glibc",
|
||||||
"libc/include/any-linux-any",
|
"libc/include/any-linux-any",
|
||||||
"libc/include/x86_64-linux-gnu",
|
"libc/include/x86_64-linux-gnu",
|
||||||
"libc/include/x86_64-linux-any",
|
"libc/include/x86_64-linux-any",
|
||||||
],
|
],
|
||||||
linkopts=["-lc++", "-lc++abi"],
|
linkopts = ["-lc++", "-lc++abi"],
|
||||||
copts=[],
|
copts = [],
|
||||||
bazel_target_cpu="k8",
|
bazel_target_cpu = "k8",
|
||||||
constraint_values=[
|
constraint_values = [
|
||||||
"@platforms//os:linux",
|
"@platforms//os:linux",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
],
|
],
|
||||||
tool_paths={"ld": "ld.lld"},
|
tool_paths = {"ld": "ld.lld"},
|
||||||
),
|
),
|
||||||
struct(
|
struct(
|
||||||
target="x86_64-linux-musl",
|
target = "x86_64-linux-musl",
|
||||||
includes=[
|
includes = [
|
||||||
"libc/include/generic-musl",
|
"libc/include/generic-musl",
|
||||||
"libc/include/any-linux-any",
|
"libc/include/any-linux-any",
|
||||||
"libc/include/x86_64-linux-musl",
|
"libc/include/x86_64-linux-musl",
|
||||||
"libc/include/x86_64-linux-any",
|
"libc/include/x86_64-linux-any",
|
||||||
],
|
],
|
||||||
linkopts=[],
|
linkopts = [],
|
||||||
copts=["-D_LIBCPP_HAS_MUSL_LIBC", "-D_LIBCPP_HAS_THREAD_API_PTHREAD"],
|
copts = ["-D_LIBCPP_HAS_MUSL_LIBC", "-D_LIBCPP_HAS_THREAD_API_PTHREAD"],
|
||||||
bazel_target_cpu="k8",
|
bazel_target_cpu = "k8",
|
||||||
constraint_values=[
|
constraint_values = [
|
||||||
"@platforms//os:linux",
|
"@platforms//os:linux",
|
||||||
"@platforms//cpu:x86_64",
|
"@platforms//cpu:x86_64",
|
||||||
":musl",
|
":musl",
|
||||||
],
|
],
|
||||||
tool_paths={"ld": "ld.lld"},
|
tool_paths = {"ld": "ld.lld"},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def toolchain_repositories():
|
def toolchain_repositories():
|
||||||
zig_repository(
|
zig_repository(
|
||||||
name = "zig_sdk",
|
name = "zig_sdk",
|
||||||
|
|
||||||
version = "0.8.0",
|
version = "0.8.0",
|
||||||
url_format = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.tar.xz",
|
url_format = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.tar.xz",
|
||||||
host_platform_sha256 = {
|
host_platform_sha256 = {
|
||||||
"linux-x86_64": "502625d3da3ae595c5f44a809a87714320b7a40e6dff4a895b5fa7df3391d01e",
|
"linux-x86_64": "502625d3da3ae595c5f44a809a87714320b7a40e6dff4a895b5fa7df3391d01e",
|
||||||
"macos-x86_64": "279f9360b5cb23103f0395dc4d3d0d30626e699b1b4be55e98fd985b62bc6fbe",
|
"macos-x86_64": "279f9360b5cb23103f0395dc4d3d0d30626e699b1b4be55e98fd985b62bc6fbe",
|
||||||
},
|
},
|
||||||
|
|
||||||
host_platform_include_root = {
|
host_platform_include_root = {
|
||||||
"macos-x86_64": "lib/zig/",
|
"macos-x86_64": "lib/zig/",
|
||||||
"linux-x86_64": "lib/",
|
"linux-x86_64": "lib/",
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def register_all_toolchains():
|
def register_all_toolchains():
|
||||||
@ -121,10 +119,10 @@ ZIG_TOOLS = [
|
|||||||
"ar",
|
"ar",
|
||||||
# List of ld tools: https://github.com/ziglang/zig/blob/0cfa39304b18c6a04689bd789f5dc4d035ec43b0/src/main.zig#L2962-L2966
|
# List of ld tools: https://github.com/ziglang/zig/blob/0cfa39304b18c6a04689bd789f5dc4d035ec43b0/src/main.zig#L2962-L2966
|
||||||
# and also: https://github.com/ziglang/zig/issues/3257
|
# and also: https://github.com/ziglang/zig/issues/3257
|
||||||
"ld.lld", # ELF
|
"ld.lld", # ELF
|
||||||
"ld64.lld", # Mach-O
|
"ld64.lld", # Mach-O
|
||||||
"lld-link", # COFF
|
"lld-link", # COFF
|
||||||
"wasm-ld", # WebAssembly
|
"wasm-ld", # WebAssembly
|
||||||
]
|
]
|
||||||
|
|
||||||
def _zig_repository_impl(repository_ctx):
|
def _zig_repository_impl(repository_ctx):
|
||||||
@ -136,8 +134,8 @@ def _zig_repository_impl(repository_ctx):
|
|||||||
zig_include_root = repository_ctx.attr.host_platform_include_root[host_platform]
|
zig_include_root = repository_ctx.attr.host_platform_include_root[host_platform]
|
||||||
zig_sha256 = repository_ctx.attr.host_platform_sha256[host_platform]
|
zig_sha256 = repository_ctx.attr.host_platform_sha256[host_platform]
|
||||||
format_vars = {
|
format_vars = {
|
||||||
"version" : repository_ctx.attr.version,
|
"version": repository_ctx.attr.version,
|
||||||
"host_platform" : host_platform,
|
"host_platform": host_platform,
|
||||||
}
|
}
|
||||||
zig_url = repository_ctx.attr.url_format.format(**format_vars)
|
zig_url = repository_ctx.attr.url_format.format(**format_vars)
|
||||||
|
|
||||||
@ -149,8 +147,8 @@ def _zig_repository_impl(repository_ctx):
|
|||||||
|
|
||||||
for zig_tool in ZIG_TOOLS:
|
for zig_tool in ZIG_TOOLS:
|
||||||
repository_ctx.file(
|
repository_ctx.file(
|
||||||
ZIG_TOOL_PATH.format(zig_tool=zig_tool),
|
ZIG_TOOL_PATH.format(zig_tool = zig_tool),
|
||||||
ZIG_TOOL_WRAPPER.format(zig=str(repository_ctx.path("zig")), zig_tool=zig_tool),
|
ZIG_TOOL_WRAPPER.format(zig = str(repository_ctx.path("zig")), zig_tool = zig_tool),
|
||||||
)
|
)
|
||||||
|
|
||||||
absolute_path = json.encode(str(repository_ctx.path("")))
|
absolute_path = json.encode(str(repository_ctx.path("")))
|
||||||
@ -179,9 +177,9 @@ def filegroup(name, **kwargs):
|
|||||||
return ":" + name
|
return ":" + name
|
||||||
|
|
||||||
def zig_build_macro(absolute_path, zig_include_root):
|
def zig_build_macro(absolute_path, zig_include_root):
|
||||||
filegroup(name="empty")
|
filegroup(name = "empty")
|
||||||
filegroup(name="zig_compiler", srcs=["zig"])
|
filegroup(name = "zig_compiler", srcs = ["zig"])
|
||||||
filegroup(name="lib/std", srcs=native.glob(["lib/std/**"]))
|
filegroup(name = "lib/std", srcs = native.glob(["lib/std/**"]))
|
||||||
|
|
||||||
native.constraint_setting(name = "libc")
|
native.constraint_setting(name = "libc")
|
||||||
|
|
||||||
@ -209,7 +207,7 @@ def zig_build_macro(absolute_path, zig_include_root):
|
|||||||
for d in DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
|
for d in DEFAULT_INCLUDE_DIRECTORIES + target_config.includes:
|
||||||
d = zig_include_root + d
|
d = zig_include_root + d
|
||||||
if d not in lazy_filegroups:
|
if d not in lazy_filegroups:
|
||||||
lazy_filegroups[d] = filegroup(name=d, srcs=native.glob([d + "/**"]))
|
lazy_filegroups[d] = filegroup(name = d, srcs = native.glob([d + "/**"]))
|
||||||
compiler_srcs.append(lazy_filegroups[d])
|
compiler_srcs.append(lazy_filegroups[d])
|
||||||
cxx_builtin_include_directories.append(absolute_path + "/" + d)
|
cxx_builtin_include_directories.append(absolute_path + "/" + d)
|
||||||
|
|
||||||
@ -218,19 +216,19 @@ def zig_build_macro(absolute_path, zig_include_root):
|
|||||||
if path[0] == "/":
|
if path[0] == "/":
|
||||||
absolute_tool_paths[name] = path
|
absolute_tool_paths[name] = path
|
||||||
continue
|
continue
|
||||||
tool_path = ZIG_TOOL_PATH.format(zig_tool=path)
|
tool_path = ZIG_TOOL_PATH.format(zig_tool = path)
|
||||||
absolute_tool_paths[name] = "%s/%s" % (absolute_path, tool_path)
|
absolute_tool_paths[name] = "%s/%s" % (absolute_path, tool_path)
|
||||||
tool_srcs[name].append(tool_path)
|
tool_srcs[name].append(tool_path)
|
||||||
|
|
||||||
ar_files = filegroup(name=target + "_ar_files", srcs=ar_srcs)
|
ar_files = filegroup(name = target + "_ar_files", srcs = ar_srcs)
|
||||||
linker_files = filegroup(name=target + "_linker_files", srcs=linker_srcs)
|
linker_files = filegroup(name = target + "_linker_files", srcs = linker_srcs)
|
||||||
compiler_files = filegroup(name=target + "_compiler_files", srcs=compiler_srcs)
|
compiler_files = filegroup(name = target + "_compiler_files", srcs = compiler_srcs)
|
||||||
all_files = filegroup(name=target + "_all_files", srcs=all_srcs + [ar_files, linker_files, compiler_files])
|
all_files = filegroup(name = target + "_all_files", srcs = all_srcs + [ar_files, linker_files, compiler_files])
|
||||||
|
|
||||||
zig_cc_toolchain_config(
|
zig_cc_toolchain_config(
|
||||||
name = target + "_cc_toolchain_config",
|
name = target + "_cc_toolchain_config",
|
||||||
target = target,
|
target = target,
|
||||||
target_suffix = getattr(target_config, 'target_suffix', ''),
|
target_suffix = getattr(target_config, "target_suffix", ""),
|
||||||
tool_paths = absolute_tool_paths,
|
tool_paths = absolute_tool_paths,
|
||||||
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
||||||
copts = target_config.copts,
|
copts = target_config.copts,
|
||||||
@ -262,7 +260,7 @@ def zig_build_macro(absolute_path, zig_include_root):
|
|||||||
toolchains = {
|
toolchains = {
|
||||||
target_config.bazel_target_cpu: ":%s_cc_toolchain" % target,
|
target_config.bazel_target_cpu: ":%s_cc_toolchain" % target,
|
||||||
},
|
},
|
||||||
tags = ["manual"]
|
tags = ["manual"],
|
||||||
)
|
)
|
||||||
|
|
||||||
native.toolchain(
|
native.toolchain(
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
|
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
|
||||||
load("@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
|
load(
|
||||||
|
"@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
|
||||||
"feature",
|
"feature",
|
||||||
"flag_group",
|
"flag_group",
|
||||||
"flag_set",
|
"flag_set",
|
||||||
"tool_path",
|
|
||||||
"tool",
|
"tool",
|
||||||
|
"tool_path",
|
||||||
)
|
)
|
||||||
|
|
||||||
all_link_actions = [
|
all_link_actions = [
|
||||||
@ -40,7 +41,8 @@ def _zig_cc_toolchain_config_impl(ctx):
|
|||||||
"-I" + d
|
"-I" + d
|
||||||
for d in ctx.attr.cxx_builtin_include_directories
|
for d in ctx.attr.cxx_builtin_include_directories
|
||||||
] + [
|
] + [
|
||||||
"-target", ctx.attr.target + ctx.attr.target_suffix,
|
"-target",
|
||||||
|
ctx.attr.target + ctx.attr.target_suffix,
|
||||||
"-no-canonical-prefixes",
|
"-no-canonical-prefixes",
|
||||||
"-Wno-builtin-macro-redefined",
|
"-Wno-builtin-macro-redefined",
|
||||||
"-D__DATE__=\"redacted\"",
|
"-D__DATE__=\"redacted\"",
|
||||||
@ -62,7 +64,8 @@ def _zig_cc_toolchain_config_impl(ctx):
|
|||||||
flag_groups = ([
|
flag_groups = ([
|
||||||
flag_group(
|
flag_group(
|
||||||
flags = [
|
flags = [
|
||||||
"-target", ctx.attr.target,
|
"-target",
|
||||||
|
ctx.attr.target,
|
||||||
] + ctx.attr.linkopts,
|
] + ctx.attr.linkopts,
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
@ -87,7 +90,7 @@ def _zig_cc_toolchain_config_impl(ctx):
|
|||||||
abi_version = ctx.attr.abi_version,
|
abi_version = ctx.attr.abi_version,
|
||||||
abi_libc_version = ctx.attr.abi_libc_version,
|
abi_libc_version = ctx.attr.abi_libc_version,
|
||||||
tool_paths = [
|
tool_paths = [
|
||||||
tool_path(name=name, path=path)
|
tool_path(name = name, path = path)
|
||||||
for name, path in ctx.attr.tool_paths.items()
|
for name, path in ctx.attr.tool_paths.items()
|
||||||
],
|
],
|
||||||
cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories,
|
cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories,
|
||||||
|
Loading…
Reference in New Issue
Block a user