feat(features): additive C++ feature flags (G2)
VoidBuildSystem CI / 1 · Requirements (push) Successful in 8s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m47s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m53s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m36s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m57s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m23s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 25s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 24s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 6m1s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 2m2s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m2s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m54s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 7m4s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
VoidBuildSystem CI / 1 · Requirements (push) Successful in 8s
VoidBuildSystem CI / 2A · Linux build (debug) (push) Successful in 2m47s
VoidBuildSystem CI / 2A · Linux build (coverage) (push) Successful in 2m53s
VoidBuildSystem CI / 2A · Linux build (sanitizers) (push) Successful in 3m36s
VoidBuildSystem CI / 2B · Windows Wine build (debug) (push) Successful in 1m57s
VoidBuildSystem CI / 2B · Windows Wine build (relwithdebinfo) (push) Successful in 3m23s
VoidBuildSystem CI / 3B · Windows Wine test (debug) (push) Successful in 25s
VoidBuildSystem CI / 3B · Windows Wine test (relwithdebinfo) (push) Successful in 24s
VoidBuildSystem CI / 2A · Linux build (relwithdebinfo) (push) Successful in 6m1s
VoidBuildSystem CI / 3A · Linux test (coverage) (push) Failing after 2m2s
VoidBuildSystem CI / 3A · Linux test (sanitizers) (push) Successful in 2m2s
VoidBuildSystem CI / 3A · Linux test (relwithdebinfo) (push) Failing after 6m54s
VoidBuildSystem CI / 3A · Linux test (debug) (push) Failing after 7m4s
VoidBuildSystem CI / 4A2 · VBS installers (linux target) (push) Skipped
VoidBuildSystem CI / 4A2 · VBS installers (windows target) (push) Skipped
VoidBuildSystem CI / 5 · Release (push) Skipped
- Project::feature(name, default_on) / FeatureDescription, Target's require_feature() (the `.requires` spelling is a C++20 keyword), and Dependency::when(feature) for optional dependencies. - --features a,b / --no-default-features on build, test, run, explain and deps resolve/update. Unification is additive: defaults (unless disabled) + features required by targets + requested features. - Enabled features add VBS_FEATURE_<NAME> compile definitions to every target, so action keys and the cache are feature-aware; switching the set invalidates cached actions. - Optional dependencies are filtered before resolution, so vbs.lock contains only active ones. - vbs explain --show-features prints the unified set with reasons (default/requested/required by target); vbs metadata lists declared features with their enabled state; the descriptor JSON carries features and target requirements. API note: features provide preprocessor-level configuration (defines), not ABI/layout changes across a feature boundary. Verified: features_unify_defines_and_invalidate_action_keys and optional_dependencies_follow_feature_selection pass; vbs_core_tests 8/8; CLI contracts pass; clang-format clean.
This commit is contained in:
1 parent
8b21583eeb
commit
f03524628b
10 files changed
+512
-3
No files matched your search
+53
-1
@@ -13,6 +13,7 @@ struct ProjectState {
|
||||
ProfileContext context;
|
||||
std::vector<TargetRecord> targets;
|
||||
std::vector<DependencyRecord> dependencies;
|
||||
std::vector<FeatureDescription> features;
|
||||
std::vector<std::string> dependency_files;
|
||||
std::vector<InstallRule> install_rules;
|
||||
};
|
||||
@@ -891,6 +892,15 @@ Target &Target::fixture_cleanup(std::string name) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Target &Target::require_feature(std::string feature) {
|
||||
require_text(feature, "feature name");
|
||||
auto &features = owner(owner_)->targets.at(index_).required_features;
|
||||
if (!std::ranges::contains(features, feature)) {
|
||||
features.push_back(std::move(feature));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Target &Target::enabled(bool flag) {
|
||||
owner(owner_)->targets.at(index_).enabled = flag;
|
||||
return *this;
|
||||
@@ -1068,6 +1078,12 @@ Dependency &Dependency::feature(std::string name) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dependency &Dependency::when(std::string feature) {
|
||||
require_text(feature, "feature name");
|
||||
owner(owner_)->dependencies.at(index_).required_feature = std::move(feature);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Dependency &Dependency::build_dependency(bool is_build_tool) {
|
||||
owner(owner_)->dependencies.at(index_).build_dependency = is_build_tool;
|
||||
return *this;
|
||||
@@ -1125,6 +1141,35 @@ Target Project::shader_bundle(std::string name) {
|
||||
}
|
||||
Target Project::test(std::string name) { return add_target(std::move(name), TargetKind::Test); }
|
||||
|
||||
Project &Project::feature(std::string name, bool default_on) {
|
||||
FeatureDescription description;
|
||||
description.name = std::move(name);
|
||||
description.default_on = default_on;
|
||||
return feature(std::move(description));
|
||||
}
|
||||
|
||||
Project &Project::feature(FeatureDescription description) {
|
||||
require_text(description.name, "feature name");
|
||||
for (const char c : description.name) {
|
||||
if (!(c >= 'a' && c <= 'z') && !(c >= 'A' && c <= 'Z') && !(c >= '0' && c <= '9') &&
|
||||
c != '_' && c != '-') {
|
||||
throw std::invalid_argument{"feature name '" + description.name +
|
||||
"' may only contain letters, digits, '_' and '-'"};
|
||||
}
|
||||
}
|
||||
if (std::ranges::any_of(state_->features, [&](const FeatureDescription &existing) {
|
||||
return existing.name == description.name;
|
||||
})) {
|
||||
throw std::invalid_argument{"duplicate feature '" + description.name + "'"};
|
||||
}
|
||||
state_->features.push_back(std::move(description));
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::vector<FeatureDescription> &Project::features() const noexcept {
|
||||
return state_->features;
|
||||
}
|
||||
|
||||
Dependency Project::dependency(std::string name) {
|
||||
require_text(name, "dependency name");
|
||||
if (std::ranges::any_of(state_->dependencies,
|
||||
@@ -1225,7 +1270,12 @@ std::string Project::to_json() const {
|
||||
",\"compiler_path\":" + json_quote(profile.compiler_path) +
|
||||
",\"reproducibility_epoch\":" + std::to_string(profile.reproducibility_epoch) +
|
||||
",\"nondeterministic\":" + std::string{profile.nondeterministic ? "true" : "false"} +
|
||||
"},\"targets\":";
|
||||
"},\"features\":" +
|
||||
json_array(features(), [](const FeatureDescription &feature) {
|
||||
return "{\"name\":" + json_quote(feature.name) +
|
||||
",\"default_on\":" + std::string{feature.default_on ? "true" : "false"} +
|
||||
",\"description\":" + json_quote(feature.description) + '}';
|
||||
}) + ",\"targets\":";
|
||||
output += json_array(targets(), [](const TargetRecord &target) {
|
||||
std::string out =
|
||||
"{\"name\":" + json_quote(target.name) +
|
||||
@@ -1257,6 +1307,7 @@ std::string Project::to_json() const {
|
||||
json_quote(visibility_name(link.visibility)) + '}';
|
||||
}) +
|
||||
",\"prerequisites\":" + json_array(target.prerequisites, json_quote) +
|
||||
",\"required_features\":" + json_array(target.required_features, json_quote) +
|
||||
",\"c_standard\":" + json_quote(c_standard_name(target.c_standard)) +
|
||||
",\"cxx_standard\":" + json_quote(cxx_standard_name(target.cxx_standard)) +
|
||||
",\"precompiled_header\":" + json_quote(target.precompiled_header) +
|
||||
@@ -1365,6 +1416,7 @@ std::string Project::to_json() const {
|
||||
",\"options\":" + options_json(dependency.options) +
|
||||
",\"registry_authority\":" + json_quote(dependency.registry_authority) +
|
||||
",\"features\":" + json_array(dependency.features, json_quote) +
|
||||
",\"required_feature\":" + json_quote(dependency.required_feature) +
|
||||
",\"build_dependency\":" +
|
||||
std::string{dependency.build_dependency ? "true" : "false"} + '}';
|
||||
return result;
|
||||
|
||||
Reference in new issue
Block a user