Skip to content

Instantly share code, notes, and snippets.

@steeve
Created March 14, 2021 22:30
Show Gist options
  • Save steeve/e5830b97925e8f3a72a89bdc5909e588 to your computer and use it in GitHub Desktop.
Save steeve/e5830b97925e8f3a72a89bdc5909e588 to your computer and use it in GitHub Desktop.
package(default_visibility = ["//visibility:public"])
load("@bazel_tools//tools/cpp:unix_cc_toolchain_config.bzl", "cc_toolchain_config")
load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite")
licenses(["notice"]) # Apache 2.0
filegroup(
name = "empty",
srcs = [],
)
filegroup(
name = "compiler_deps",
srcs = glob(
["zig/**"],
allow_empty = True,
),
)
# This is the entry point for --crosstool_top. Toolchains are found
# by lopping off the name of --crosstool_top and searching for
# the "${CPU}" entry in the toolchains attribute.
cc_toolchain_suite(
name = "zig_suite",
toolchains = {
"x86_64-macos": ":cc-compiler-x86_64-macos",
"x86_64-linux": ":cc-compiler-x86_64-linux",
"x86_64-windows": ":cc-compiler-x86_64-windows",
},
)
_CPUS = [
"x86_64-macos",
"x86_64-linux",
"x86_64-windows",
]
[
cc_toolchain(
name = "cc-compiler-{}".format(cpu),
all_files = ":compiler_deps",
ar_files = ":compiler_deps",
as_files = ":compiler_deps",
compiler_files = ":compiler_deps",
dwp_files = ":empty",
linker_files = ":compiler_deps",
module_map = None,
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 1,
toolchain_config = ":local-{}".format(cpu),
toolchain_identifier = "local-{}".format(cpu),
)
for cpu in _CPUS
]
[
cc_toolchain_config(
name = "local-{}".format(cpu),
abi_libc_version = "local",
abi_version = "local",
compile_flags = [
"-U_FORTIFY_SOURCE",
"-fstack-protector",
"-Wall",
"-fno-omit-frame-pointer",
],
compiler = "compiler",
coverage_compile_flags = ["--coverage"],
coverage_link_flags = ["--coverage"],
cpu = cpu,
cxx_builtin_include_directories = [
"/Users/steeve/code/github.com/znly/bazel_zig_toolchain/zig_toolchain/zig",
],
cxx_flags = ["-std=c++0x"],
dbg_compile_flags = ["-g"],
host_system_name = "local",
link_flags = [""],
link_libs = [
"-lstdc++",
"-lm",
],
opt_compile_flags = [
"-g0",
"-O2",
"-D_FORTIFY_SOURCE=1",
"-DNDEBUG",
"-ffunction-sections",
"-fdata-sections",
],
opt_link_flags = [],
supports_start_end_lib = False,
target_libc = "local",
target_system_name = "local",
tool_paths = {
"ar": "/usr/bin/false",
"ld": "//usr/bin/false",
"llvm-cov": "None",
"cpp": "/usr/bin/false",
"gcc": "/Users/steeve/code/github.com/znly/bazel_zig_toolchain/zig_toolchain/zig_cc_{}.sh".format(cpu),
"dwp": "/usr/bin/false",
"gcov": "None",
"nm": "/usr/bin/false",
"objcopy": "/usr/bin/false",
"objdump": "/usr/bin/false",
"strip": "/usr/bin/false",
},
toolchain_identifier = "local",
unfiltered_compile_flags = [
"-Wno-builtin-macro-redefined",
"-D__DATE__=\"redacted\"",
"-D__TIMESTAMP__=\"redacted\"",
"-D__TIME__=\"redacted\"",
],
)
for cpu in _CPUS
]
#!/bin/bash
export HOME=${PWD}
export ZIG_LOCAL_CACHE_DIR=${PWD}/.zig
$(dirname ${0})/zig/zig cc -target x86_64-macos "${@}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment