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

chore: ensure we don't try to compile any C++ code #16

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ common --action_env=RULES_PYTHON_ENABLE_PYSTAR=0
# https://bazelbuild.slack.com/archives/C014RARENH0/p1691158021917459?thread_ts=1691156601.420349&cid=C014RARENH0
common --check_direct_dependencies=off

# Force rules_go to disable CGO even though we have a (fake) C++ toolchain registered.
common --host_platform=//:no_cgo_host_platform

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
Expand Down
8 changes: 8 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("@platforms//host:constraints.bzl", "HOST_CONSTRAINTS")

platform(
name = "no_cgo_host_platform",
constraint_values = HOST_CONSTRAINTS + [
"@rules_go//go/toolchain:cgo_off",
],
)
8 changes: 7 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module(
bazel_dep(name = "bazel_features", version = "1.9.0")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "rules_proto", version = "6.0.0")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "platforms", version = "0.0.10")

protoc = use_extension("//protoc:extensions.bzl", "protoc")
protoc.toolchain(
Expand All @@ -20,6 +20,12 @@ use_repo(protoc, "com_google_protobuf", "toolchains_protoc_hub")

register_toolchains("@toolchains_protoc_hub//:all")

# Assert no CC compilation occurs
register_toolchains(
"//tools/toolchains:all",
dev_dependency = True,
)

bazel_dep(name = "aspect_bazel_lib", version = "1.32.1", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.1.2", dev_dependency = True)
bazel_dep(name = "aspect_rules_py", version = "0.7.1", dev_dependency = True)
Expand Down
31 changes: 31 additions & 0 deletions tools/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Define a non-functional cc toolchain.

To fail-fast in cases where we are forced to compile third-party C++ code,
define a cc toolchain that doesn't work, by using 'false' as the compiler.
See https://bazel.build/tutorials/ccp-toolchain-config
"""

load("defs.bzl", "cc_toolchain_config")

filegroup(name = "empty")

cc_toolchain_config(name = "noop_toolchain_config")

cc_toolchain(
name = "noop_toolchain",
all_files = ":empty",
compiler_files = ":empty",
dwp_files = ":empty",
linker_files = ":empty",
objcopy_files = ":empty",
strip_files = ":empty",
supports_param_files = 0,
toolchain_config = ":noop_toolchain_config",
toolchain_identifier = "noop-toolchain",
)

toolchain(
name = "cc_toolchain",
toolchain = ":noop_toolchain",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
20 changes: 20 additions & 0 deletions tools/toolchains/defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"Configure a cc toolchain to call 'false' if used."

def _impl(ctx):
return cc_common.create_cc_toolchain_config_info(
ctx = ctx,
toolchain_identifier = "noop-toolchain",
host_system_name = "local",
target_system_name = "local",
target_cpu = "k8",
target_libc = "unknown",
compiler = "false",
abi_version = "unknown",
abi_libc_version = "unknown",
)

cc_toolchain_config = rule(
implementation = _impl,
attrs = {},
provides = [CcToolchainConfigInfo],
)