Files
carbon-lang/toolchain/driver/compile_subcommand.cpp
T
Lucile Rose Nihlen 1a26b57732 add first implementation of carbon build subcommand (#7239)
This is the first draft of the implementation of
[p6333](https://docs.carbon-lang.dev/proposals/p6333.html).

The `build` subcommand shared logic with the `compile` and `link`
subcommands,
so I've moved some of the functionality in `compile` and `link` to
shared
`CompileDriver` and `LinkDriver` classes, respectively. This also
required exposing the
`CompileOptions` and `LinkOptions` subcommand structs for re-use.

There's still some work to do on the proposal, most notably the package
include automatic path resolution and import, and the refactors to
`carbon compile`.
2026-06-09 20:24:01 +00:00

49 lines
1.5 KiB
C++

// 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/compile_subcommand.h"
#include "toolchain/driver/compile_driver.h"
namespace Carbon {
static constexpr CommandLine::CommandInfo SubcommandInfo = {
.name = "compile",
.help = R"""(
Compile Carbon source code.
This subcommand runs the Carbon compiler over input source code, checking it for
errors and producing the requested output.
Error messages are written to the standard error stream.
Different phases of the compiler can be selected to run, and intermediate state
can be written to standard output as these phases progress.
)""",
};
CompileSubcommand::CompileSubcommand() : DriverSubcommand(SubcommandInfo) {}
auto CompileSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
if (driver_env.fuzzing && !options_.clang_args.empty()) {
// Parsing specific Clang arguments can reach deep into
// external libraries that aren't fuzz clean.
TestAndDiagnoseIfFuzzingExternalLibraries(driver_env, "compile");
return {.success = false};
}
auto compile_driver = CompileDriver(&options_);
if (!compile_driver.Initialize(driver_env,
[&](llvm::StringRef) -> std::string {
return options_.output_filename.str();
})) {
return {.success = false};
}
return compile_driver.Compile(driver_env);
}
} // namespace Carbon