Skip to content

Commit 4133e5e

Browse files
committed
Improve new project library workflow
1 parent 43772ea commit 4133e5e

4 files changed

Lines changed: 72 additions & 8 deletions

File tree

src/commands/NewCommand.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ namespace vix::commands::NewCommand
349349
<< " • Generates a ready-to-run Vix project\n"
350350
<< " • Sets up CMake, source structure, and config files\n"
351351
<< " • Creates a vix.json manifest\n"
352-
<< " • For apps, includes default tasks and an empty deps list\n"
353-
<< " • For libraries, includes package metadata and an empty deps list\n"
352+
<< " • For apps, creates an executable target matching the project name\n"
353+
<< " • For libraries, creates a header-only CMake interface target\n"
354354
<< " • Applies the selected template (app or library)\n\n"
355355

356356
<< "Options\n"
@@ -359,6 +359,17 @@ namespace vix::commands::NewCommand
359359
<< " -d, --dir Base directory for project creation\n"
360360
<< " --force Overwrite existing directory\n\n"
361361

362+
<< "Application workflow\n"
363+
<< " cd api/\n"
364+
<< " vix build\n"
365+
<< " vix run\n\n"
366+
367+
<< "Library workflow\n"
368+
<< " cd tree/\n"
369+
<< " vix build --build-target all\n"
370+
<< " vix build --build-target all -- -Dtree_BUILD_TESTS=ON\n"
371+
<< " vix tests\n\n"
372+
362373
<< "Environment\n"
363374
<< " VIX_NONINTERACTIVE=1 Disable prompts\n"
364375
<< " CI=1 Disable prompts\n\n"
@@ -368,6 +379,8 @@ namespace vix::commands::NewCommand
368379
<< " • Use 'vix add <pkg>' to add dependencies\n"
369380
<< " • Use 'vix install' to install from vix.lock\n"
370381
<< " • Use 'vix task <name>' to run generated tasks\n"
382+
<< " • For header-only libraries, use '--build-target all' to build the generated project\n"
383+
<< " • Tests for header-only libraries are disabled by default and must be enabled with CMake args\n"
371384
<< " • Designed for fast start with zero setup\n";
372385

373386
return 0;

src/commands/new/NewOutput.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,19 @@ namespace vix::commands::new_cmd::output
7373
print_command_step(1, "cd " + projName + "/", "enter project");
7474
print_command_step(2, "vix build", "compile");
7575
print_command_step(3, "vix run", "start app");
76-
77-
std::cout << "\n";
7876
}
7977

8078
static void print_steps_lib(const std::string &projName)
8179
{
8280
section("next");
8381

8482
print_command_step(1, "cd " + projName + "/", "enter project");
85-
print_command_step(2, "vix build", "compile");
86-
print_command_step(3, "vix tests", "run tests");
87-
88-
std::cout << "\n";
83+
print_command_step(2, "vix build --build-target all", "compile");
84+
print_command_step(
85+
3,
86+
"vix build --build-target all -- -D" + projName + "_BUILD_TESTS=ON",
87+
"enable tests");
88+
print_command_step(4, "vix tests", "run tests");
8989
}
9090

9191
// ------------------------------------------------------------------

src/commands/new/NewTemplates.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ namespace vix::commands::new_cmd::templates
251251
readme += "```\n\n";
252252

253253
readme += "## Tests\n\n";
254+
readme += "Tests are disabled by default for header-only libraries.\n\n";
255+
readme += "Enable them first:\n\n";
256+
readme += "```bash\n";
257+
readme += "vix build --build-target all -- -D" + name + "_BUILD_TESTS=ON\n";
258+
readme += "```\n\n";
259+
readme += "Then run:\n\n";
254260
readme += "```bash\n";
255261
readme += "vix tests\n";
256262
readme += "```\n\n";

src/errors/build/CMakeBuildErrors.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,48 @@ namespace vix::cli::errors::build
4343
return {};
4444
}
4545

46+
static bool handle_unknown_ninja_target(std::string_view log)
47+
{
48+
constexpr std::string_view marker = "ninja: error: unknown target '";
49+
50+
const std::size_t pos = log.find(marker);
51+
52+
if (pos == std::string_view::npos)
53+
return false;
54+
55+
const std::size_t start = pos + marker.size();
56+
const std::size_t end = log.find('\'', start);
57+
58+
std::string target = "unknown";
59+
60+
if (end != std::string_view::npos && end > start)
61+
target = std::string(log.substr(start, end - start));
62+
63+
std::cerr << PAD
64+
<< RED << BOLD << "✖ Build target not found" << RESET
65+
<< "\n";
66+
67+
std::cerr << PAD
68+
<< CYAN << "target:" << RESET
69+
<< " "
70+
<< target
71+
<< "\n";
72+
73+
std::cerr << PAD
74+
<< YELLOW << "hint:" << RESET
75+
<< " "
76+
<< "This project does not define a CMake target named '"
77+
<< target
78+
<< "'.\n";
79+
80+
std::cerr << PAD
81+
<< " "
82+
<< "Check your CMakeLists.txt or use --build-target with an existing target."
83+
<< "\n";
84+
85+
return true;
86+
}
87+
4688
bool contains(std::string_view log, std::string_view needle)
4789
{
4890
return log.find(needle) != std::string_view::npos;
@@ -570,6 +612,9 @@ namespace vix::cli::errors::build
570612

571613
bool handleCMakeBuildError(std::string_view log)
572614
{
615+
if (handle_unknown_ninja_target(log))
616+
return true;
617+
573618
if (handleCacheMismatch(log))
574619
return true;
575620

0 commit comments

Comments
 (0)