diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index fd9a2c7a673b..3606d52015f6 100644 --- a/toolchain/driver/BUILD +++ b/toolchain/driver/BUILD @@ -17,6 +17,7 @@ cc_library( name = "driver", srcs = ["driver.cpp"], hdrs = ["driver.h"], + data = ["//core"], textual_hdrs = ["flags.def"], deps = [ "//common:command_line", diff --git a/toolchain/driver/driver.cpp b/toolchain/driver/driver.cpp index b27a6b7fb5cf..1cf01cc62733 100644 --- a/toolchain/driver/driver.cpp +++ b/toolchain/driver/driver.cpp @@ -671,7 +671,17 @@ auto Driver::Compile(const CompileOptions& options) -> RunResult { // Prepare CompilationUnits before building scope exit handlers. StreamDiagnosticConsumer stream_consumer(error_stream_); llvm::SmallVector> units; - units.reserve(options.input_filenames.size()); + units.reserve(options.prelude_import + options.input_filenames.size()); + + // Directly insert the core package into the compilation units. + // TODO: Should expand this into a more rich system to search for the core + // package source code. + if (options.prelude_import) { + units.push_back(std::make_unique( + this, options, &stream_consumer, "core/prelude.carbon")); + } + + // Add the input source files. for (const auto& input_filename : options.input_filenames) { units.push_back(std::make_unique( this, options, &stream_consumer, input_filename)); diff --git a/toolchain/driver/testdata/dump_shared_values.carbon b/toolchain/driver/testdata/dump_shared_values.carbon index 18e61ba99685..fd50600b5bc9 100644 --- a/toolchain/driver/testdata/dump_shared_values.carbon +++ b/toolchain/driver/testdata/dump_shared_values.carbon @@ -15,6 +15,15 @@ var real3: f64 = 0.8e9; var str1: String = "abc"; var str2: String = "ab'\"c"; +// CHECK:STDOUT: --- +// CHECK:STDOUT: filename: 'core/prelude.carbon' +// CHECK:STDOUT: shared_values: +// CHECK:STDOUT: ints: {} +// CHECK:STDOUT: reals: {} +// CHECK:STDOUT: strings: +// CHECK:STDOUT: str0: Core +// CHECK:STDOUT: str1: prelude +// CHECK:STDOUT: ... // CHECK:STDOUT: --- // CHECK:STDOUT: filename: dump_shared_values.carbon // CHECK:STDOUT: shared_values: diff --git a/toolchain/testing/BUILD b/toolchain/testing/BUILD index 033cb2a4a234..b16e74c9fd98 100644 --- a/toolchain/testing/BUILD +++ b/toolchain/testing/BUILD @@ -11,7 +11,6 @@ file_test( name = "file_test", size = "small", srcs = ["file_test.cpp"], - data = ["//core"], tests = [ "//toolchain/check:testdata", "//toolchain/codegen:testdata", diff --git a/toolchain/testing/file_test.cpp b/toolchain/testing/file_test.cpp index 8cbd0510c6ba..1134cb761bec 100644 --- a/toolchain/testing/file_test.cpp +++ b/toolchain/testing/file_test.cpp @@ -52,11 +52,14 @@ class ToolchainFileTest : public FileTestBase { llvm::SmallVector args = {"compile", "--phase=" + component_.str()}; + // For `lex` and `parse`, we don't need to import the prelude. Suppress it + // to improve the dump output for the tests. if (component_ == "lex") { - args.insert(args.end(), {"--dump-tokens", "%s"}); + args.insert(args.end(), {"--no-prelude-import", "--dump-tokens", "%s"}); return args; } else if (component_ == "parse") { - args.insert(args.end(), {"--dump-parse-tree", "%s"}); + args.insert(args.end(), + {"--no-prelude-import", "--dump-parse-tree", "%s"}); return args; } @@ -69,8 +72,7 @@ class ToolchainFileTest : public FileTestBase { << test_name(); } - args.insert(args.end(), {"--exclude-dump-file-prefix=core/", - "core/prelude.carbon", "%s"}); + args.insert(args.end(), {"--exclude-dump-file-prefix=core/", "%s"}); return args; }