Skip to content

Commit

Permalink
Make C++ toolchain optional
Browse files Browse the repository at this point in the history
Currently, if you transition a go_binary, you must have a C++ toolchain
for it even if it's building in pure mode without cgo.

By making this toolchain optional, we push the error from a
toolchain-resolution-time error to an analysis-time error only if a
toolchain is both _needed_ and not found.
  • Loading branch information
illicitonion committed Dec 8, 2022
1 parent 1a8fe64 commit cc78849
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,12 @@ http_archive(
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

local_repository(
name = "apple_federation",
path = "/Volumes/Source/github.pie.apple.com/bazel/apple_federation",
)

load("@apple_federation//common:repositories.bzl", "common_deps")

common_deps()
8 changes: 7 additions & 1 deletion go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,13 @@ cgo_context_data = rule(
default = "@bazel_tools//tools/osx:current_xcode_config",
),
},
toolchains = ["@bazel_tools//tools/cpp:toolchain_type"],
toolchains = [
# In pure mode, a C++ toolchain isn't needed when transitioning.
# But if we declare a mandatory toolchain dependency here, a cross-compiling C++ toolchain is required at toolchain resolution time.
# So we make this toolchain dependency optional, so that it's only attempted to be looked up if it's actually needed.
# Optional toolchain support was added in bazel 6.0.0.
config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False) if hasattr(config_common, "toolchain_type") else "@bazel_tools//tools/cpp:toolchain_type",
],
fragments = ["apple", "cpp"],
provides = [CgoContextInfo],
doc = """Collects information about the C/C++ toolchain. The C/C++ toolchain
Expand Down

0 comments on commit cc78849

Please sign in to comment.