-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CLI and separate compilation #6333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
proposals/p6333.md
Outdated
| Right now, `carbon compile` produces an object file per input file. This has a | ||
| few issues, for example when it comes to compiling prelude files: it's not clear | ||
| how to get a prelude `.o` file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe worth calling out: we only support one --output-file per compilation, but always compile a file and all of its interface dependencies together, so we end up creating and then repeatedly overwriting the output file.
The upshot of this is that our carbon_library rule passes all of the carbon files to every compile, putting "the one it's building" last so that its object file is the one left behind as the --output-file after all the overwriting happens. And that means that our compile times are scaling quadratically with the number of files we build. Fortunately our builds are so fast that we're getting away with this, but it clearly won't scale, and is a cause of our -c dbg //examples/... builds being slow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusting/reformatting.
proposals/p6333.md
Outdated
| Additionally, the compilation setup doesn't work well with the prelude because | ||
| symbols don't get emitted for prelude files. Right now, we generally don't | ||
| notice this because the prelude has been implemented in a way that typically | ||
| doesn't require separate object files, but it will likely become an issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what it's worth, this does work these days with the existing carbon_library rule, because it adds all the prelude files to the list of sources. Some of our examples depend on that. But as you mention in the next paragraph, that doesn't really apply to real-world build scenarios where it won't be easy to get a list of the prelude files and build them manually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note that carbon_binary has a workaround, but I don't think that's someone using carbon compile can make use of.
proposals/p6333.md
Outdated
| - Run the equivalent of `carbon link` over produced inputs. | ||
|
|
||
| While the build command will default to providing an executable `program`, we'll | ||
| also want it to be capable of producing `.a` and `.so` files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chandlerc I think you had some particular plans around .so files. Should we include or exclude them as possible carbon build outputs for now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm updating the doc to suggest that these be decided as an implementation detail instead of design. Like maybe we really want carbon build to be more demo-y, and .so files are a little too non-demo-y.
proposals/p6333.md
Outdated
| - For `lib`, we'll delegate to `carbon build`: | ||
| - Examine the four files, and determine a compile order. | ||
| - Invoke the four `carbon compile` behaviors, producing a `.o` file. | ||
| - For `bin`, we'll again delegate to `carbon build`: | ||
| - Given one file, determine the trivial compile order. | ||
| - Invoke `carbon compile` to produce a `.o` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The phrasing here leaves me unsure whether we're invoking carbon build, or whether we're invoking carbon compile directly, or some hybrid such as running carbon build in a "tell me what you would have done" mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a mistake and doesn't reflect how we're likely to want to write this. Rewriting it all. :)
proposals/p6333.md
Outdated
| without relying on user decisions. | ||
| - This makes the `srcs` versus `apis` difference less meaningful. | ||
|
|
||
| Disadvantages: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another disadvantage: once we have separate compilation to some kind of precompiled artifact, having all the files in srcs would mean the set of precompilation actions isn't knowable from just the build rules -- bazel would need to read the package / library declaration in the file to determine whether it's an impl file or not, and hence whether it produces a precompiled Carbon unit that downstream compilations might want to consume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this the case? For a source file, the extension is either .carbon or .impl.carbon, and from that we can tell whether it's an impl file. For a precompiled unit, shouldn't there be some way to map between the source file it was built from?
proposals/p6333.md
Outdated
| inclusive of C++ code. Hopefully then people can learn that the new thing works | ||
| with both. | ||
|
|
||
| What's really missing is a better name for this than "carbon". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could invent a name for the C, C++, and Carbon ecosystem, and then use that here. Just to throw out an idea, maybe the "CX ecosystem"? (as in, /C.*/) -- so cx_library, cx_binary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per open discussion today, probably keeping with carbon_* and saying it's essentially the "carbon" ecosystem.
Co-authored-by: Richard Smith <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion, pulled out a lot of the Bazel mentions out separately and trying to avoid making design choices for it here. (trying to just use it for illustrative purposes)
proposals/p6333.md
Outdated
| Additionally, the compilation setup doesn't work well with the prelude because | ||
| symbols don't get emitted for prelude files. Right now, we generally don't | ||
| notice this because the prelude has been implemented in a way that typically | ||
| doesn't require separate object files, but it will likely become an issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note that carbon_binary has a workaround, but I don't think that's someone using carbon compile can make use of.
proposals/p6333.md
Outdated
| Right now, `carbon compile` produces an object file per input file. This has a | ||
| few issues, for example when it comes to compiling prelude files: it's not clear | ||
| how to get a prelude `.o` file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjusting/reformatting.
proposals/p6333.md
Outdated
| At the end, it should be possible to: | ||
|
|
||
| - Run `carbon build main.carbon` (or even just `carbon build`) with | ||
| non-prelude `Core` imports, and get an executable `program`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
program was suggested by chandlerc:
I think saying get an executable `main` would also be confusing because "main" is also a term... I've dropped the backticks, do you think that's okay?
proposals/p6333.md
Outdated
| - Run the equivalent of `carbon link` over produced inputs. | ||
|
|
||
| While the build command will default to providing an executable `program`, we'll | ||
| also want it to be capable of producing `.a` and `.so` files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm updating the doc to suggest that these be decided as an implementation detail instead of design. Like maybe we really want carbon build to be more demo-y, and .so files are a little too non-demo-y.
proposals/p6333.md
Outdated
| - For `lib`, we'll delegate to `carbon build`: | ||
| - Examine the four files, and determine a compile order. | ||
| - Invoke the four `carbon compile` behaviors, producing a `.o` file. | ||
| - For `bin`, we'll again delegate to `carbon build`: | ||
| - Given one file, determine the trivial compile order. | ||
| - Invoke `carbon compile` to produce a `.o` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a mistake and doesn't reflect how we're likely to want to write this. Rewriting it all. :)
proposals/p6333.md
Outdated
| - `apis` more clearly reflects the design intent of "API". `hdrs` is an opaque | ||
| naming choice for Carbon when considered independently of C++. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the note.
proposals/p6333.md
Outdated
| without relying on user decisions. | ||
| - This makes the `srcs` versus `apis` difference less meaningful. | ||
|
|
||
| Disadvantages: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this the case? For a source file, the extension is either .carbon or .impl.carbon, and from that we can tell whether it's an impl file. For a precompiled unit, shouldn't there be some way to map between the source file it was built from?
proposals/p6333.md
Outdated
| - Some other name for `public_deps` | ||
| - I'm not really sure `public_deps` is the best name, but it's my best | ||
| thought for something to reflect the transitive nature of API exposure | ||
| being proposed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #6333 (comment), I think this is commenting about the same naming
proposals/p6333.md
Outdated
| inclusive of C++ code. Hopefully then people can learn that the new thing works | ||
| with both. | ||
|
|
||
| What's really missing is a better name for this than "carbon". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per open discussion today, probably keeping with carbon_* and saying it's essentially the "carbon" ecosystem.
proposals/p6333.md
Outdated
|
|
||
| Because we'll build this for Core, it would probably be straightforward to | ||
| expose this for other packages, too. So for example, we will support | ||
| `--package_path=MyPackage:/my/package`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hedging this mention a bit more, are you okay with that? I'd in particular expect any support along these lines to mirror Core... for example, maybe you still need to compile the package's files to produce objects, and link it; it's just pulling API files in an easy way (as it would for Core).
sounds a little fragile for an environment like
bazel
I think it's too fragile for a fully hermetic environment. However, some users use bazel in a fully hermetic way, and others cut corners (e.g. we don't use a fully hermetic python in Carbon, but we definitely could).
For a fully hermetic setup where even Core is explicitly built through build rules, I would expect them not to use this feature at all. For something like carbon build and users just trying to do something quickly, or for someone using a slightly non-hermetic setup (perhaps custom bazel rules, or their CMake setup), does it make a little more sense to provide?
carboncompilation command set to usecompile,link, andbuild.Core, but support it in a generalmanner.
Drafted in Docs