Skip to content
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
2 changes: 1 addition & 1 deletion swift/toolchains/config/compile_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ def _plugin_search_paths_configurator(prerequisites, args):
if prerequisites.include_dev_srch_paths:
args.add(
"-plugin-path",
"__BAZEL_XCODE_DEVELOPER_DIR__/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins/testing",
"__BAZEL_SWIFT_TOOLCHAIN_PATH__/usr/lib/swift/host/plugins/testing",
)

def _dependencies_swiftmodules_vfsoverlay_configurator(prerequisites, args, is_frontend = False):
Expand Down
2 changes: 1 addition & 1 deletion swift/toolchains/xcode_swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ def _xcode_swift_toolchain_impl(ctx):
fail("Do not use SWIFT_USE_TOOLCHAIN_ROOT and TOOLCHAINS" +
"in the same build.")
elif custom_toolchain:
custom_xcode_toolchain_root = "__BAZEL_CUSTOM_XCODE_TOOLCHAIN_PATH__"
custom_xcode_toolchain_root = "__BAZEL_SWIFT_TOOLCHAIN_PATH__"

swift_linkopts_cc_info = _swift_linkopts_cc_info(
apple_toolchain = apple_toolchain,
Expand Down
31 changes: 17 additions & 14 deletions tools/common/bazel_substitutions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ static const char kBazelXcodeDeveloperDir[] = "__BAZEL_XCODE_DEVELOPER_DIR__";
// at runtime.
static const char kBazelXcodeSdkRoot[] = "__BAZEL_XCODE_SDKROOT__";

// The placeholder string used by the Apple and Swift rules to be replaced with
// the absolute path to the custom toolchain being used
static const char kBazelToolchainPath[] =
"__BAZEL_CUSTOM_XCODE_TOOLCHAIN_PATH__";
// The placeholder string used by Bazel that should be replaced by the swift
// toolchain root directory. For instance:
// * when using the toolchain within Xcode, this will be something like this:
// .../Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
// * when using a standalone non-Xcode toolchain, this will be something like:
// .../swift-6.2-RELEASE.xctoolchain
// Either way, swift binaries are expected to be found at this location under
// usr/bin, swift standard libraries are expected to be found at usr/lib/swift,
// etc...
static const char kBazelSwiftToolchainPath[] =
"__BAZEL_SWIFT_TOOLCHAIN_PATH__";

// Returns the value of the given environment variable, or the empty string if
// it wasn't set.
Expand All @@ -60,17 +67,13 @@ std::string GetToolchainPath() {
#endif

char *toolchain_id = getenv("TOOLCHAINS");
if (toolchain_id == nullptr) {
return "";
}

std::ostringstream output_stream;
int exit_code =
RunSubProcess({"/usr/bin/xcrun", "--find", "clang", "--toolchain", toolchain_id},
RunSubProcess({"/usr/bin/xcrun", "--find", "clang"},
/*env=*/nullptr, &output_stream, /*stdout_to_stderr=*/true);
if (exit_code != 0) {
std::cerr << output_stream.str() << "Error: TOOLCHAINS was set to '"
<< toolchain_id << "' but xcrun failed when searching for that ID"
std::cerr << output_stream.str() << "Error: `TOOLCHAINS=" << toolchain_id
<< "xcrun --find clang` failed with error code " << exit_code
<< std::endl;
exit(EXIT_FAILURE);
}
Expand All @@ -79,8 +82,8 @@ std::string GetToolchainPath() {
std::cerr << "Error: TOOLCHAINS was set to '" << toolchain_id
<< "' but no toolchain with that ID was found" << std::endl;
exit(EXIT_FAILURE);
} else if (output_stream.str().find("XcodeDefault.xctoolchain") !=
std::string::npos) {
} else if ((toolchain_id != nullptr)
&& output_stream.str().find("XcodeDefault.xctoolchain") != std::string::npos) {
// NOTE: Ideally xcrun would fail if the toolchain we asked for didn't exist
// but it falls back to the DEVELOPER_DIR instead, so we have to check the
// output ourselves.
Expand Down Expand Up @@ -110,7 +113,7 @@ BazelPlaceholderSubstitutions::BazelPlaceholderSubstitutions() {
{kBazelXcodeSdkRoot, PlaceholderResolver([]() {
return GetAppleEnvironmentVariable("SDKROOT");
})},
{kBazelToolchainPath,
{kBazelSwiftToolchainPath,
PlaceholderResolver([]() { return GetToolchainPath(); })},
};
}
Expand Down