mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 13:11:05 +01:00
Add a clang subcommand. (#4322)
This makes something like `bazel run :toolchain -- clang -- -c test.cpp` work, because that can be run in-process. Note that `bazel run :toolchain -- clang -- test.cpp` still requires subprocessing, and does not work. Note, the vision here is that we are trying to align how clang and carbon compile c++ code. This is work towards intertwining command execution. --------- Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
co-authored by
Chandler Carruth
parent
c7057eff89
commit
c107aaad13
@@ -0,0 +1,50 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "toolchain/driver/clang_subcommand.h"
|
||||
|
||||
#include "llvm/TargetParser/Host.h"
|
||||
#include "toolchain/driver/clang_runner.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
constexpr CommandLine::CommandInfo ClangOptions::Info = {
|
||||
.name = "clang",
|
||||
.help = R"""(
|
||||
Runs Clang on arguments.
|
||||
|
||||
This is equivalent to running the `clang` command line directly, and provides
|
||||
the full command line interface.
|
||||
|
||||
Use `carbon clang -- ARGS` to pass flags to `clang`. Although there are
|
||||
currently no flags for `carbon clang`, the `--` reserves the ability to add
|
||||
flags in the future.
|
||||
|
||||
This is provided to help guarantee consistent compilation of C++ files, both
|
||||
when Clang is invoked directly and when a Carbon file importing a C++ file
|
||||
results in an indirect Clang invocation.
|
||||
)""",
|
||||
};
|
||||
|
||||
auto ClangOptions::Build(CommandLine::CommandBuilder& b) -> void {
|
||||
b.AddStringPositionalArg(
|
||||
{
|
||||
.name = "ARG",
|
||||
.help = R"""(
|
||||
Arguments passed to Clang.
|
||||
)""",
|
||||
},
|
||||
[&](auto& arg_b) { arg_b.Append(&args); });
|
||||
}
|
||||
|
||||
// TODO: This lacks a lot of features from the main driver code. We may need to
|
||||
// add more.
|
||||
// https://github.com/llvm/llvm-project/blob/main/clang/tools/driver/driver.cpp
|
||||
auto ClangSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
|
||||
std::string target = llvm::sys::getDefaultTargetTriple();
|
||||
ClangRunner runner(driver_env.installation, target, driver_env.vlog_stream);
|
||||
return {.success = runner.Run(options_.args)};
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
Reference in New Issue
Block a user