mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 20:20:10 +01:00
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. --------- Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
# 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
|
|
|
|
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag", "int_flag", "string_flag")
|
|
|
|
package(default_visibility = ["//toolchain/install:__pkg__"])
|
|
|
|
exports_files(["gen_tmpl.py"])
|
|
|
|
# Several flags are provided for customizing the exact version used for the
|
|
# build of Carbon. Each of these is documented here, but rather than using the
|
|
# label-based names in Bazel invocations (`bazel build --//bazel/version:flag`)
|
|
# we suggest using the flag aliases provided in the project's `.bazelrc` and we
|
|
# document the flags using those aliases. The aliases match the local flag names
|
|
# here.
|
|
#
|
|
# For more details on the versioning scheme used by Carbon, see:
|
|
# - https://docs.google.com/document/d/11S5VAPe5Pm_BZPlajWrqDDVr9qc7-7tS2VshqO0wWkk/edit?resourcekey=0-2YFC9Uvl4puuDnWlr2MmYw
|
|
# TODO: Replace with path to the markdown once this lands.
|
|
#
|
|
# First, we provide a flag to enable a release version: `--release`. It is
|
|
# disabled by default, and if enabled it must be the only version flag used.
|
|
bool_flag(
|
|
name = "release",
|
|
build_setting_default = False,
|
|
)
|
|
|
|
# A `--pre_release=KIND` flag where `KIND` must be one of:
|
|
# - `rc` -- a release candidate version.
|
|
# Example: `--pre_release=rc --rc_number=2`
|
|
# - `beta` -- a beta version.
|
|
# Example: `--pre_release=beta --beta_number=2`
|
|
# - `alpha` -- an alpha version.
|
|
# Example: `--pre_release=alpha --alpha_number=2`
|
|
# - `nightly -- a nightly version.
|
|
# Example: `--pre_release=nightly --nightly_date=2024.06.17`
|
|
# - `dev` -- the default, a development build.
|
|
# Example: `--pre_release=dev`
|
|
#
|
|
# This flag cannot be used along with `--release`, and for all but the `dev`
|
|
# kind must be combined with one of the below flags to specify further details
|
|
# of the version.
|
|
string_flag(
|
|
name = "pre_release",
|
|
build_setting_default = "dev",
|
|
values = [
|
|
"rc",
|
|
"beta",
|
|
"alpha",
|
|
"nightly",
|
|
"dev",
|
|
],
|
|
)
|
|
|
|
# `--rc_number=N` sets the release candidate number to `N`. Requires `--pre_release=rc`.
|
|
int_flag(
|
|
name = "rc_number",
|
|
build_setting_default = -1,
|
|
)
|
|
|
|
# When `--pre_release=beta` is used, `--beta_number=N` set's the beta
|
|
# pre-release number to `N`.
|
|
#
|
|
# An error if used without `--pre_release=beta`.
|
|
int_flag(
|
|
name = "beta_number",
|
|
build_setting_default = -1,
|
|
)
|
|
|
|
# When `--pre_release=alpha` is used, `--alpha_number=N` set's the alpha
|
|
# pre-release number to `N`.
|
|
#
|
|
# An error if used without `--pre_release=alpha`.
|
|
int_flag(
|
|
name = "alpha_number",
|
|
build_setting_default = -1,
|
|
)
|
|
|
|
# When `--pre_release=nightly` is used, `--nightly_date=YYYY.MM.DD` set's the
|
|
# nightly build date. The value for this flag must be a string with the exact
|
|
# format of `YYYY.MM.DD`.
|
|
#
|
|
# An error if used without `--pre_release=nightly`.
|
|
string_flag(
|
|
name = "nightly_date",
|
|
build_setting_default = "",
|
|
)
|
|
|
|
# A config setting to observe the value of the `--stamp` command line flag
|
|
# within starlark with a macro and `select`. This is a workaround suggested for
|
|
# a Bazel issue: https://github.com/bazelbuild/bazel/issues/11164
|
|
config_setting(
|
|
name = "internal_stamp_flag_detect",
|
|
values = {"stamp": "1"},
|
|
visibility = ["//visibility:public"],
|
|
)
|