Files
carbon-lang/toolchain/driver/clang_subcommand.h
T
Chandler Carruth 8b967943d3 Move the build-runtimes option up to the top-level driver (#6720)
Multiple subcommands all need the ability to disable on-demand runtime
building, and this may be needed outside of using _prebuilt_ runtimes.
For example, with Bazel the plan is to not build runtimes at all and
have Bazel provide them as native Bazel libraries.

Updates the `link` subcommand to respect this flag when running Clang to
perform links.

We didn't have any real testing of the `link` subcommand, in part
because it was difficult -- it would try to link runtime libraries. Now
that we can prevent building them on demand, we can use that to test the
link command. That in turn helped uncover a couple of bugs that are
fixed here.

1) The `driver_env_` member of the `Driver` was re-used across
   `RunCommand` invocations. Some of its fields are constant across
   these, others can be updated, and still more are not necessarily
   something we would expect to be re-used. This fixes that by removing
   the `driver_env_` member, and replacing it with members for just the
   fields of `DriverEnv` that we want to set initially based on the
   construction of the `Driver` object. This causes multiple, sequential
   `RunCommand` calls to not clobber or erroneously inherit state.

2) The temporary directory support in the driver unittest didn't allow
   the driver to observe the things it wrote to the temporary directory.
   This PR updates the test logic to create an overlay VFS so that both
   the in-memory test inputs are observed, but so are the real files
   written into the temporary directory.

3) The Clang runner, when asked to run Clang without runtimes would
   still attempt to include runtimes in any link command. This isn't
   quite what we want, as the whole reason to use this without building
   runtimes is to reuse ones built in some other way and potentially in
   some other location. For now, this PR uses a hack to suppress these
   issues so that we can have a basic test, but in the future we'll need
   a better solution here.

4) The driver test didn't include the actual driver in the install data.
   The test even worked around this, but it makes it impossible to link
   reliably as the `lld` binary isn't available. This adds the data
   dependency and updates the test to the available digest, etc.
2026-02-11 19:16:38 +00:00

43 lines
1.2 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
#ifndef CARBON_TOOLCHAIN_DRIVER_CLANG_SUBCOMMAND_H_
#define CARBON_TOOLCHAIN_DRIVER_CLANG_SUBCOMMAND_H_
#include "common/command_line.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "toolchain/driver/driver_env.h"
#include "toolchain/driver/driver_subcommand.h"
namespace Carbon {
// Options for the clang subcommand, which is just a thin wrapper.
//
// See the implementation of `Build` for documentation on members.
struct ClangOptions {
auto Build(CommandLine::CommandBuilder& b) -> void;
llvm::SmallVector<llvm::StringRef> args;
};
// Implements the clang subcommand of the driver.
class ClangSubcommand : public DriverSubcommand {
public:
explicit ClangSubcommand();
auto BuildOptions(CommandLine::CommandBuilder& b) -> void override {
options_.Build(b);
}
auto Run(DriverEnv& driver_env) -> DriverResult override;
private:
ClangOptions options_;
};
} // namespace Carbon
#endif // CARBON_TOOLCHAIN_DRIVER_CLANG_SUBCOMMAND_H_