Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hermetic_cc_toolchain for a hermetic cc toolchain #12135

Merged
merged 62 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9cf58cb
Add bazel-zig-cc for a hermetic cc toolchain
prestonvanloon Mar 15, 2023
845f57e
gazelle
prestonvanloon Mar 15, 2023
08303b0
Remove llvm
prestonvanloon Mar 17, 2023
2bb0073
Merge branch 'develop' of github.com:prysmaticlabs/prysm into bazel-z…
prestonvanloon Mar 17, 2023
01f62c0
Merge branch 'develop' of github.com:prysmaticlabs/prysm into bazel-z…
prestonvanloon Apr 21, 2023
421ba54
remove wl
prestonvanloon Apr 21, 2023
a6766ea
Add new URLs for renamed repo
prestonvanloon Apr 24, 2023
f55485e
Merge branch 'develop' of github.com:prysmaticlabs/prysm into bazel-z…
prestonvanloon Apr 24, 2023
4cbc1a4
gazelle
prestonvanloon Apr 24, 2023
a8606c2
Update to v2.0.0-rc1
prestonvanloon Apr 24, 2023
f61fec3
Merge branch 'develop' into bazel-zig-cc
prestonvanloon May 1, 2023
3b4705b
Merge branch 'develop' into bazel-zig-cc
prestonvanloon May 1, 2023
3d23e8e
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 3, 2023
7fe5aa5
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 4, 2023
db9dd87
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 5, 2023
473b165
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 5, 2023
1780382
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 7, 2023
15468fd
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 7, 2023
62d8a44
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 8, 2023
9eda6b8
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 10, 2023
90d6792
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 10, 2023
0762e53
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 10, 2023
bc9a39e
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 10, 2023
4a69ed0
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 10, 2023
ad4705e
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 11, 2023
172bdba
bump to rc2
prestonvanloon May 11, 2023
9fff6bf
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 11, 2023
0c2b6c1
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 12, 2023
7ce2083
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 12, 2023
93ef895
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 12, 2023
37fe595
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 12, 2023
0fdf2b6
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 12, 2023
0f806e8
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 13, 2023
efbcb69
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 14, 2023
3e46317
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 15, 2023
baa59af
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 15, 2023
6ef1747
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 15, 2023
d74d9c7
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 16, 2023
1e5fe12
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 16, 2023
93dba8f
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 16, 2023
a792628
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 16, 2023
4bc5e22
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 16, 2023
9313a7c
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 16, 2023
8c256fc
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 17, 2023
82ad902
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 17, 2023
7054bd2
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 18, 2023
7a3469b
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 18, 2023
f39a45c
Merge refs/heads/develop into bazel-zig-cc
prylabs-bulldozer[bot] May 18, 2023
64b126b
Merge branch 'develop' into bazel-zig-cc
prestonvanloon May 23, 2023
fdfc683
Some PR feedback
prestonvanloon May 23, 2023
b7e9c1a
Merge branch 'develop' of github.com:prysmaticlabs/prysm into bazel-z…
prestonvanloon Jun 20, 2023
92375d0
use v2.0.0 from rc2
prestonvanloon Jun 20, 2023
571a4a8
Merge branch 'develop' of github.com:prysmaticlabs/prysm into bazel-z…
prestonvanloon Jun 20, 2023
9ba3750
Disable hermetic builds for mac and windows.
prestonvanloon Jun 20, 2023
fa3ef31
bump bazel version, add darwin hack
prestonvanloon Jun 20, 2023
5bcb909
fix
prestonvanloon Jun 20, 2023
ec4c18c
Add the no-op emtpy cc toolchain code
prestonvanloon Jun 20, 2023
aade909
typo and additional copy
prestonvanloon Jun 20, 2023
7bb4b6b
update protobuf and fix vaticle warning
prestonvanloon Jun 21, 2023
4bb6008
Revert "update protobuf and fix vaticle warning"
prestonvanloon Jun 21, 2023
6f39389
Merge branch 'develop' of github.com:prysmaticlabs/prysm into bazel-z…
prestonvanloon Jun 21, 2023
b16b8de
Merge branch 'develop' into bazel-zig-cc
prestonvanloon Jun 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import %workspace%/build/bazelrc/convenience.bazelrc
import %workspace%/build/bazelrc/correctness.bazelrc
import %workspace%/build/bazelrc/cross.bazelrc
import %workspace%/build/bazelrc/debug.bazelrc
import %workspace%/build/bazelrc/hermetic-cc.bazelrc
import %workspace%/build/bazelrc/performance.bazelrc

# E2E run with debug gotag
Expand All @@ -27,30 +28,7 @@ build:minimal --@io_bazel_rules_go//go/config:tags=minimal
build:release --compilation_mode=opt
build:release --stamp

# LLVM compiler for building C/C++ dependencies.
build:llvm --define compiler=llvm
build:llvm --copt -fno-sanitize=vptr,function
build:llvm --linkopt -fno-sanitize=vptr,function
# --incompatible_enable_cc_toolchain_resolution not needed after this issue is closed https://github.com/bazelbuild/bazel/issues/7260
build:llvm --incompatible_enable_cc_toolchain_resolution

build:asan --copt -fsanitize=address,undefined
build:asan --copt -fno-omit-frame-pointer
build:asan --linkopt -fsanitize=address,undefined
build:asan --copt -fno-sanitize=vptr,function
build:asan --linkopt -fno-sanitize=vptr,function
build:asan --copt -DADDRESS_SANITIZER=1
build:asan --copt -D__SANITIZE_ADDRESS__
build:asan --linkopt -ldl

build:llvm-asan --config=llvm
build:llvm-asan --config=asan
build:llvm-asan --linkopt -fuse-ld=ld.lld

build:fuzz --@io_bazel_rules_go//go/config:tags=fuzz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note that we are removing fuzzing and the sanitize_address stuff is used for this.


# Build binary with cgo symbolizer for debugging / profiling.
build:cgo_symbolizer --config=llvm
build:cgo_symbolizer --copt=-g
build:cgo_symbolizer --define=USE_CGO_SYMBOLIZER=true
build:cgo_symbolizer -c dbg
Expand All @@ -59,7 +37,7 @@ build:cgo_symbolizer --define=gotags=cgosymbolizer_enabled
# toolchain build debug configs
#------------------------------
build:debug --sandbox_debug
build:debug --toolchain_resolution_debug
build:debug --toolchain_resolution_debug=".*"
build:debug --verbose_failures
build:debug -s

Expand Down
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.1.0
6.2.1
36 changes: 23 additions & 13 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,37 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")

rules_pkg_dependencies()

HERMETIC_CC_TOOLCHAIN_VERSION = "v2.0.0"

http_archive(
name = "com_grail_bazel_toolchain",
sha256 = "b210fc8e58782ef171f428bfc850ed7179bdd805543ebd1aa144b9c93489134f",
strip_prefix = "bazel-toolchain-83e69ba9e4b4fdad0d1d057fcb87addf77c281c9",
urls = ["https://github.com/grailbio/bazel-toolchain/archive/83e69ba9e4b4fdad0d1d057fcb87addf77c281c9.tar.gz"],
name = "hermetic_cc_toolchain",
sha256 = "57f03a6c29793e8add7bd64186fc8066d23b5ffd06fe9cc6b0b8c499914d3a65",
urls = [
"https://mirror.bazel.build/github.com/uber/hermetic_cc_toolchain/releases/download/{0}/hermetic_cc_toolchain-{0}.tar.gz".format(HERMETIC_CC_TOOLCHAIN_VERSION),
"https://github.com/uber/hermetic_cc_toolchain/releases/download/{0}/hermetic_cc_toolchain-{0}.tar.gz".format(HERMETIC_CC_TOOLCHAIN_VERSION),
],
)

load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies")

bazel_toolchain_dependencies()
load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")

load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")
zig_toolchains()

llvm_toolchain(
name = "llvm_toolchain",
llvm_version = "13.0.1",
# Register zig sdk toolchains with support for Ubuntu 20.04 (Focal Fossa) which has an EOL date of April, 2025.
# For ubuntu glibc support, see https://launchpad.net/ubuntu/+source/glibc
register_toolchains(
"@zig_sdk//toolchain:linux_amd64_gnu.2.31",
"@zig_sdk//toolchain:linux_arm64_gnu.2.31",
# Hermetic cc toolchain is not yet supported on darwin. Sysroot needs to be provided.
# See https://github.com/uber/hermetic_cc_toolchain#osx-sysroot
# "@zig_sdk//toolchain:darwin_amd64",
# "@zig_sdk//toolchain:darwin_arm64",
# Windows builds are not supported yet.
# "@zig_sdk//toolchain:windows_amd64",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
load("@prysm//tools/cross-toolchain:darwin_cc_hack.bzl", "configure_nonhermetic_darwin")

llvm_register_toolchains()
configure_nonhermetic_darwin()

load("@prysm//tools/cross-toolchain:prysm_toolchains.bzl", "configure_prysm_toolchains")

Expand Down
19 changes: 19 additions & 0 deletions build/bazelrc/hermetic-cc.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# From Bazel's perspective, this is almost equivalent to always specifying
# --extra_toolchains on every bazel <...> command-line invocation. It also
# means there is no way to disable the toolchain with the command line. This is
# useful if you find bazel-hermetic-cc useful enough to compile for all of your
# targets and tools.
#
# With BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 Bazel stops detecting the default
# host toolchain. Configuring toolchains is complicated enough, and the
# auto-detection (read: fallback to non-hermetic toolchain) is a footgun best
# avoided. This option is not documented in bazel, so may break. If you intend
# to use the hermetic toolchain exclusively, it won't hurt.
build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1

# This snippet instructs Bazel to use the registered "new kinds of toolchains".
# This flag not needed after this issue is closed https://github.com/bazelbuild/bazel/issues/7260
build --incompatible_enable_cc_toolchain_resolution

# Add a no-op warning for users still using --config=llvm
build:llvm --unconditional_warning="llvm config is no longer used as clang is now the default compiler"
114 changes: 114 additions & 0 deletions tools/cross-toolchain/darwin_cc_hack.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "configure_unix_toolchain")
load(
"@bazel_tools//tools/cpp:lib_cc_configure.bzl",
"get_cpu_value",
"resolve_labels",
)

"""
This file is a copy of https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl
with some minor changes. The original file is licensed under Apache 2.0 license. The gist of this
is that we want darwin to register the local toolchain and disregard the environment variable of
BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN. We must support a local toolchain for darwin until
hermetic_cc_toolchain supports darwin's sysroot in a hermetic way.
"""

def cc_autoconf_toolchains_impl(repository_ctx):
"""Generate BUILD file with 'toolchain' targets for the local host C++ toolchain.

Args:
repository_ctx: repository context
"""

cpu_value = get_cpu_value(repository_ctx)

if cpu_value.startswith("darwin"):
paths = resolve_labels(repository_ctx, [
"@bazel_tools//tools/cpp:BUILD.toolchains.tpl",
])
repository_ctx.template(
"BUILD",
paths["@bazel_tools//tools/cpp:BUILD.toolchains.tpl"],
{"%{name}": get_cpu_value(repository_ctx)},
)
else:
repository_ctx.file("BUILD", "# C++ toolchain autoconfiguration was disabled by BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN env variable.")


def cc_autoconf_impl(repository_ctx, overriden_tools = dict()):
"""Generate BUILD file with 'cc_toolchain' targets for the local host C++ toolchain.

Args:
repository_ctx: repository context
overriden_tools: dict of tool paths to use instead of autoconfigured tools
"""
cpu_value = get_cpu_value(repository_ctx)

if cpu_value.startswith("darwin"):
print("Configuring local C++ toolchain for Darwin. This is non-hermetic and builds may " +
"not be reproducible. Consider building on linux for a hermetic build.")
configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools)
else:
paths = resolve_labels(repository_ctx, [
"@bazel_tools//tools/cpp:BUILD.empty.tpl",
"@bazel_tools//tools/cpp:empty_cc_toolchain_config.bzl",
])
repository_ctx.symlink(paths["@bazel_tools//tools/cpp:empty_cc_toolchain_config.bzl"], "cc_toolchain_config.bzl")
repository_ctx.template("BUILD", paths["@bazel_tools//tools/cpp:BUILD.empty.tpl"], {
"%{cpu}": get_cpu_value(repository_ctx),
})

cc_autoconf_toolchains = repository_rule(
environ = [
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN",
],
implementation = cc_autoconf_toolchains_impl,
configure = True,
)

cc_autoconf = repository_rule(
environ = [
"ABI_LIBC_VERSION",
"ABI_VERSION",
"BAZEL_COMPILER",
"BAZEL_HOST_SYSTEM",
"BAZEL_CONLYOPTS",
"BAZEL_CXXOPTS",
"BAZEL_LINKOPTS",
"BAZEL_LINKLIBS",
"BAZEL_LLVM_COV",
"BAZEL_LLVM_PROFDATA",
"BAZEL_PYTHON",
"BAZEL_SH",
"BAZEL_TARGET_CPU",
"BAZEL_TARGET_LIBC",
"BAZEL_TARGET_SYSTEM",
"BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN",
"BAZEL_USE_LLVM_NATIVE_COVERAGE",
"BAZEL_LLVM",
"BAZEL_IGNORE_SYSTEM_HEADERS_VERSIONS",
"USE_CLANG_CL",
"CC",
"CC_CONFIGURE_DEBUG",
"CC_TOOLCHAIN_NAME",
"CPLUS_INCLUDE_PATH",
"DEVELOPER_DIR",
"GCOV",
"LIBTOOL",
"HOMEBREW_RUBY_PATH",
"SYSTEMROOT",
"USER",
],
implementation = cc_autoconf_impl,
configure = True,
)

def configure_nonhermetic_darwin():
"""A C++ configuration rules that generate the crosstool file."""
cc_autoconf_toolchains(name = "local_config_cc_toolchains")
cc_autoconf(name = "local_config_cc")
native.bind(name = "cc_toolchain", actual = "@local_config_cc//:toolchain")
native.register_toolchains(
# Use register_toolchain's target pattern expansion to register all toolchains in the package.
"@local_config_cc_toolchains//:all",
)