Repository: carbon-language/carbon-lang
File: toolchain/driver/clang_runtimes.cpp (C++)

Code before:
    result_ = std::move(build_dir_or_error).error();
    return;
  }
  auto build_dir = *(std::move(build_dir_or_error));
  if (std::holds_alternative<std::filesystem::path>(build_dir)) {
    // Found cached build.
    result_ = std::get<std::filesystem::path>(std::move(build_dir));
    return;
  }

  if constexpr (Component == Runtimes::LibUnwind) {
    srcs_path_ = installation().libunwind_path();
    include_path_ = installation().libunwind_path() / "include";
    archive_path_ = std::filesystem::path("lib") / "libunwind.a";
  } else {
    static_assert(false,
                  "Invalid runtimes component for an archive runtime builder.");
  }

  runtimes_builder_ = std::get<Runtimes::Builder>(std::move(build_dir));
  archive_.emplace(this, archive_path_, srcs_path_, CollectSrcFiles(),
                   CollectCflags());
  tasks_.async([this]() mutable { Setup(); });
}

template <Runtimes::Component Component>
auto ClangArchiveRuntimesBuilder<Component>::CollectSrcFiles()
    -> llvm::SmallVector<llvm::StringRef> {
  if constexpr (Component == Runtimes::LibUnwind) {
    return llvm::SmallVector<llvm::StringRef>(llvm::make_filter_range(
        RuntimeSources::LibunwindSrcs, [](llvm::StringRef src) {
          return src.ends_with(".c") || src.ends_with(".cpp") ||
                 src.ends_with(".S");
        }));
  } else {
    static_assert(false,
                  "Invalid runtimes component for an archive runtime builder.");
  }
}

template <Runtimes::Component Component>
auto ClangArchiveRuntimesBuilder<Component>::CollectCflags()
    -> llvm::SmallVector<llvm::StringRef> {
  if constexpr (Component == Runtimes::LibUnwind) {
    return {
        "-no-canonical-prefixes",
        "-O3",
        "-fPIC",
        "-funwind-tables",
        "-fno-exceptions",
        "-fno-rtti",

Review comment (bug):
I thought [before C++23](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2593r1.html) a `static_assert(false)`, without any dependent template variable involved, would just unconditionally fail?

We have this which we could move to somewhere common? https://github.com/carbon-language/carbon-lang/blob/6451ae60244dc8d2e780c4114426cf396da2579f/toolchain/diagnostics/diagnostic_emitter.h#L349-L350

Code after:
  auto build_dir_or_error = runtimes->Build(Component);
  if (!build_dir_or_error.ok()) {
    result_ = std::move(build_dir_or_error).error();
    return;
  }
  auto build_dir = *(std::move(build_dir_or_error));
  CARBON_KIND_SWITCH(std::move(build_dir)) {
    case CARBON_KIND(std::filesystem::path build_dir_path): {
      // Found cached build.
      result_ = std::move(build_dir_path);
      return;
    }
    case CARBON_KIND(Runtimes::Builder builder): {
      runtimes_builder_ = std::move(builder);
      // Building the runtimes is handled below.
      break;
    }
  }

  if constexpr (Component == Runtimes::LibUnwind) {
    srcs_path_ = installation().libunwind_path();
    include_path_ = installation().libunwind_path() / "include";
    archive_path_ = std::filesystem::path("lib") / "libunwind.a";
  } else {
    static_assert(false,
                  "Invalid runtimes component for an archive runtime builder.");
  }

  archive_.emplace(this, archive_path_, srcs_path_, CollectSrcFiles(),
                   CollectCflags());
  tasks_.async([this]() mutable { Setup(); });
}

template <Runtimes::Component Component>
  requires(Component == Runtimes::LibUnwind)
auto ClangArchiveRuntimesBuilder<Component>::CollectSrcFiles()
    -> llvm::SmallVector<llvm::StringRef> {
  if constexpr (Component == Runtimes::LibUnwind) {
    return llvm::SmallVector<llvm::StringRef>(llvm::make_filter_range(
        RuntimeSources::LibunwindSrcs, [](llvm::StringRef src) {
          return src.ends_with(".c") || src.ends_with(".cpp") ||
                 src.ends_with(".S");
        }));
  } else {
    static_assert(false,
                  "Invalid runtimes component for an archive runtime builder.");
  }
}

template <Runtimes::Component Component>
  requires(Component == Runtimes::LibUnwind)