Skip to content

Commit ddbe325

Browse files
committed
feat(manifest): [build].profile sets the project default build profile; v0.0.76
Adds a per-project default-profile knob so a plain `mcpp build` can use a project's preferred profile without typing --profile every time. The global convention default stays "release"; `[build] profile = "dev"` overrides it for that project; a `--profile <name>` flag still overrides everything. Precedence (prepare.cppm): --profile flag > [build].profile > "release". manifest.cppm: parse build.profile into buildConfig.defaultProfile. Test: tests/e2e/87_build_default_profile.sh ([build].profile=dev → plain build is -O0 -g; --profile release overrides to -O2).
1 parent 37aa710 commit ddbe325

5 files changed

Lines changed: 50 additions & 3 deletions

File tree

mcpp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mcpp"
3-
version = "0.0.75"
3+
version = "0.0.76"
44
description = "Modern C++ build & package management tool"
55
license = "Apache-2.0"
66
authors = ["mcpp-community"]

src/build/prepare.cppm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,11 @@ prepare_build(bool print_fingerprint,
557557
// Resolve the build profile: --profile (default "release") → built-in
558558
// defaults, overlaid by any [profile.<name>] from the manifest → buildConfig.
559559
{
560-
std::string pname = overrides.profile.empty() ? "release" : overrides.profile;
560+
// Precedence: --profile flag > [build].profile (project default) >
561+
// "release" (global convention).
562+
std::string pname = !overrides.profile.empty() ? overrides.profile
563+
: !m->buildConfig.defaultProfile.empty() ? m->buildConfig.defaultProfile
564+
: "release";
561565
mcpp::manifest::Profile pr;
562566
if (pname == "dev" || pname == "debug") { pr.optLevel = "0"; pr.debug = true; }
563567
else if (pname == "dist") { pr.optLevel = "3"; pr.strip = true; }

src/manifest.cppm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ struct BuildConfig {
148148
bool debug = false; // -g
149149
bool lto = false; // -flto
150150
bool strip = false; // link -s
151+
// `[build].profile` — the project's DEFAULT profile when no --profile is
152+
// passed. The global convention default stays "release"; this lets a project
153+
// opt its plain `mcpp build` into e.g. "dev" without typing --profile. A
154+
// `--profile <name>` flag always overrides it.
155+
std::string defaultProfile;
151156
};
152157

153158
// `[runtime]` — requirements needed when launching built binaries.
@@ -1118,6 +1123,7 @@ std::expected<Manifest, ManifestError> parse_string(std::string_view content,
11181123
if (auto v = doc->get_string_array("build.cxxflags")) m.buildConfig.cxxflags = *v;
11191124
if (auto v = doc->get_string_array("build.ldflags")) m.buildConfig.ldflags = *v;
11201125
if (auto v = doc->get_string("build.c_standard")) m.buildConfig.cStandard = *v;
1126+
if (auto v = doc->get_string("build.profile")) m.buildConfig.defaultProfile = *v;
11211127
if (auto v = doc->get_string("build.macos_deployment_target"))
11221128
m.buildConfig.macosDeploymentTarget = *v;
11231129
for (auto const& flag : m.buildConfig.cxxflags) {

src/toolchain/fingerprint.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import mcpp.toolchain.detect;
1818

1919
export namespace mcpp::toolchain {
2020

21-
inline constexpr std::string_view MCPP_VERSION = "0.0.75";
21+
inline constexpr std::string_view MCPP_VERSION = "0.0.76";
2222

2323
struct FingerprintInputs {
2424
Toolchain toolchain;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
# 87_build_default_profile.sh — `[build].profile` sets a project's DEFAULT build
3+
# profile, so plain `mcpp build` uses it without typing --profile. The global
4+
# convention default stays "release"; a `--profile <name>` flag overrides the
5+
# project default. See .agents/docs/2026-06-29-manifest-environment-and-platform-design.md.
6+
set -e
7+
8+
TMP=$(mktemp -d)
9+
trap "rm -rf $TMP" EXIT
10+
cd "$TMP"
11+
12+
mkdir -p app/src
13+
cat > app/mcpp.toml <<'EOF'
14+
[package]
15+
name = "app"
16+
version = "0.1.0"
17+
18+
# Project opts its plain `mcpp build` into the dev profile.
19+
[build]
20+
profile = "dev"
21+
EOF
22+
cat > app/src/main.cpp <<'EOF'
23+
int main() { return 0; }
24+
EOF
25+
26+
cd app
27+
28+
# Plain build → the [build].profile default ("dev": -O0 -g), no --profile typed.
29+
"$MCPP" build > b.log 2>&1 || { cat b.log; echo "FAIL: build errored"; exit 1; }
30+
grep -q '\-O0' compile_commands.json || { echo "FAIL: [build].profile=dev did not yield -O0"; cat compile_commands.json; exit 1; }
31+
grep -q '\-g\b' compile_commands.json || { echo "FAIL: [build].profile=dev did not yield -g (debug)"; exit 1; }
32+
33+
# An explicit --profile overrides the project default (release → -O2, no -g debug).
34+
"$MCPP" build --profile release > b2.log 2>&1 || { cat b2.log; echo "FAIL: --profile release build errored"; exit 1; }
35+
grep -q '\-O2' compile_commands.json || { echo "FAIL: --profile release did not override to -O2"; cat compile_commands.json; exit 1; }
36+
37+
echo "OK"

0 commit comments

Comments
 (0)