clang_subcommand.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "toolchain/driver/clang_subcommand.h"
  5. #include "llvm/TargetParser/Host.h"
  6. #include "toolchain/driver/clang_runner.h"
  7. namespace Carbon {
  8. constexpr CommandLine::CommandInfo ClangOptions::Info = {
  9. .name = "clang",
  10. .help = R"""(
  11. Runs Clang on arguments.
  12. This is equivalent to running the `clang` command line directly, and provides
  13. the full command line interface.
  14. Use `carbon clang -- ARGS` to pass flags to `clang`. Although there are
  15. currently no flags for `carbon clang`, the `--` reserves the ability to add
  16. flags in the future.
  17. This is provided to help guarantee consistent compilation of C++ files, both
  18. when Clang is invoked directly and when a Carbon file importing a C++ file
  19. results in an indirect Clang invocation.
  20. )""",
  21. };
  22. auto ClangOptions::Build(CommandLine::CommandBuilder& b) -> void {
  23. b.AddStringPositionalArg(
  24. {
  25. .name = "ARG",
  26. .help = R"""(
  27. Arguments passed to Clang.
  28. )""",
  29. },
  30. [&](auto& arg_b) { arg_b.Append(&args); });
  31. }
  32. // TODO: This lacks a lot of features from the main driver code. We may need to
  33. // add more.
  34. // https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/driver.cpp
  35. auto ClangSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
  36. std::string target = llvm::sys::getDefaultTargetTriple();
  37. ClangRunner runner(driver_env.installation, target, driver_env.vlog_stream);
  38. return {.success = runner.Run(options_.args)};
  39. }
  40. } // namespace Carbon