Skip to content

Conversation

@aw-andre
Copy link

@aw-andre aw-andre commented Nov 13, 2025

This adds a CarbonRunner class that (for now) builds an archive of the compiled Core libs in the carbon_runtimes cache.
It also modifies carbon build-runtimes to call this functionality and carbon link to automatically use the archive during linking.

Cross-subcommand functionality is confined to the CarbonRunner class as future work will probably require a lot more crossing (i.e. carbon build will probably call compile and link, and carbon compile will probably need precompiled metadata to be built by carbon build-runtimes).

To do this in a type-safe manner, constructors were added for subcommand objects that use the associated options struct and some (missing?) defaults were added to the structs.
These defaults don't change behavior as they were already defaulted in the command line parser, but not in the struct itself.
Most of the constructors are not yet used (only compile is used now) but they may be useful for later.

@aw-andre
Copy link
Author

AFAIK @chandlerc was working on refactoring the code for runtimes, so he might need to review this.
I included a previous change that changed the printed output for the build-runtimes subcommand and where he was called to review, but I closed the PR for that as I thought adding the autolinking functionality now would make the refactor pretty hard.
I think I was able to confine the parts that would get affected by this to less than 40 LOC, so hopefully this shouldn't be too difficult to maintain.

@aw-andre
Copy link
Author

Also, I might be missing something with adding the defaults to the structs as some other options have defaults, but all the functionality appears to be the same.

@aw-andre aw-andre marked this pull request as ready for review November 13, 2025 01:28
@aw-andre aw-andre requested a review from a team as a code owner November 13, 2025 01:28
@aw-andre aw-andre requested review from zygoloid and removed request for a team November 13, 2025 01:28
@zygoloid zygoloid requested review from chandlerc and removed request for zygoloid November 13, 2025 21:14
Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for being a bit slow to get back here, left some initial comments.

Comment on lines +124 to +125
"carbon_runner.cpp",
"carbon_runner.h",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be split into a separate carbon_runner library? Is there something that goes wrong with that?

Comment on lines +30 to +31
friend CarbonRunner;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? It doesn't seem like it should be...

Comment on lines +33 to +36
private:
auto Compile(llvm::SmallVector<std::filesystem::path> input_filenames,
Lower::OptimizationLevel opt_level, llvm::Triple target,
bool prelude_import) -> DriverResult;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't expect this to be private, this seems like it should be part of the public API?


// Helper class for cross-subcommand functionality.
// Allows type-safe calls of subcommands.
// TODO: May need to be adjusted once caching is refactored.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the refactorings are now landed, so hopefully can update all of this and address the TODOs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants