carbon-language / carbon-lang

Carbon Language's main repository: documents, design, implementation, and related tools. (NOTE: Carbon Language is experimental; see README)
https://github.com/carbon-language/carbon-lang/blob/trunk/README.md
Other
32.31k stars 1.48k forks source link

Introduce version and build info stamping. #4054

Closed chandlerc closed 1 week ago

chandlerc commented 2 weeks ago

This adds a defined Carbon version to the Bazel build and codebase that can be used both to implement features like version checks and to report a meaningful version on the command line. This replaces a hard-coded string and a TODO in the driver.

As part of this, it adds support for defining the version in Bazel, and special build flags for overriding relevant parts such as the pre-release marker used. The exact structure and meaning of our version string, including the pre-release parts, is implemented here in line with the draft proposal: https://docs.google.com/document/d/11S5VAPe5Pm_BZPlajWrqDDVr9qc7-7tS2VshqO0wWkk/edit?resourcekey=0-2YFC9Uvl4puuDnWlr2MmYw

This also introduces a workspace status command to the repository to extract the git commit SHA and other information when building, and the logic to stamp that into binaries as part of the version string when useful. The technique used leverages weak symbols with whole archive linking to allow a link-time override of unstamped data with stamped data in the leaf executable. This makes building with --stamp a reasonable default, especially for development builds. The CI system is explicitly opted out of this as there it has no benefit.

Last but not least, all of these are wired into the install rules so that we build installable packages with the version number in a conventional place in the directory and filename.

jonmeow commented 1 week ago

(adding comments to gen_tmpl, sorry I hadn't looked at it originally since I'd been hoping expand_template would work)

chandlerc commented 1 week ago

I messed up and didn't commit&push the fixes intended in the last comment round here. Very sorry for that. They're in https://github.com/carbon-language/carbon-lang/pull/4059 now.