Skip to content

Commit 3d72eea

Browse files
committed
feat(run,build): add SQLite/MySQL flags and clean support
2 parents cb55a3c + 76452dc commit 3d72eea

File tree

8 files changed

+102
-6
lines changed

8 files changed

+102
-6
lines changed

include/vix/cli/commands/run/RunDetail.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ namespace vix::commands::RunCommand::detail
9292
std::vector<std::string> doubleDashArgs;
9393
std::vector<std::string> runArgsAfterRun;
9494
bool hasRunSeparator = false;
95+
96+
bool withSqlite = false;
97+
bool withMySql = false;
98+
bool clean = false;
9599
};
96100

97101
struct ScriptRunResult
@@ -157,7 +161,9 @@ namespace vix::commands::RunCommand::detail
157161
const std::string &exeName,
158162
const fs::path &cppPath,
159163
bool useVixRuntime,
160-
const std::vector<std::string> &scriptFlags);
164+
const std::vector<std::string> &scriptFlags,
165+
bool withSqlite,
166+
bool withMySql);
161167

162168
int run_single_cpp(const Options &opt);
163169
int run_single_cpp_watch(const Options &opt);

include/vix/cli/commands/run/detail/ScriptCMake.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ namespace vix::commands::RunCommand::detail
2626
const std::string &exeName,
2727
const fs::path &cppPath,
2828
bool useVixRuntime,
29-
const std::vector<std::string> &scriptFlags);
29+
const std::vector<std::string> &scriptFlags,
30+
bool withSqlite,
31+
bool withMySql);
3032
}
3133

3234
#endif

include/vix/cli/process/Process.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ namespace vix::cli::process
151151
* @brief Extra arguments forwarded directly to CMake.
152152
*/
153153
std::vector<std::string> cmakeArgs;
154+
155+
bool withSqlite = false;
156+
bool withMySql = false;
154157
};
155158

156159
/**

src/commands/BuildCommand.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ namespace vix::commands::BuildCommand
321321
}
322322
o.preset = std::string(*v);
323323
}
324+
else if (a == "--with-sqlite")
325+
{
326+
o.withSqlite = true;
327+
}
328+
else if (a == "--with-mysql")
329+
{
330+
o.withMySql = true;
331+
}
324332
else if (a.rfind("--preset=", 0) == 0)
325333
{
326334
o.preset = a.substr(std::string("--preset=").size());
@@ -724,6 +732,20 @@ namespace vix::commands::BuildCommand
724732
vars.emplace_back("CMAKE_MODULE_LINKER_FLAGS", *fastLinkerFlag);
725733
}
726734

735+
if (opt.withSqlite)
736+
{
737+
vars.emplace_back("VIX_ENABLE_DB", "ON");
738+
vars.emplace_back("VIX_DB_USE_SQLITE", "ON");
739+
vars.emplace_back("VIX_DB_REQUIRE_SQLITE", "ON");
740+
}
741+
742+
if (opt.withMySql)
743+
{
744+
vars.emplace_back("VIX_ENABLE_DB", "ON");
745+
vars.emplace_back("VIX_DB_USE_MYSQL", "ON");
746+
vars.emplace_back("VIX_DB_REQUIRE_MYSQL", "ON");
747+
}
748+
727749
std::sort(
728750
vars.begin(),
729751
vars.end(),
@@ -1257,6 +1279,8 @@ namespace vix::commands::BuildCommand
12571279
out << " --target <triple> Cross-compilation target triple (auto toolchain)\n";
12581280
out << " --sysroot <path> Sysroot for cross toolchain (optional)\n";
12591281
out << " --static Request static linking (VIX_LINK_STATIC=ON)\n";
1282+
out << " --with-sqlite Enable SQLite support (VIX_DB_USE_SQLITE=ON)\n";
1283+
out << " --with-mysql Enable MySQL support (VIX_DB_USE_MYSQL=ON)\n";
12601284
out << " -j, --jobs <n> Parallel build jobs (default: CPU count, clamped)\n";
12611285
out << " --clean Remove local build directories and reconfigure from scratch\n";
12621286
out << " --no-cache Disable signature cache shortcut\n";
@@ -1279,6 +1303,10 @@ namespace vix::commands::BuildCommand
12791303

12801304
out << "Examples:\n";
12811305
out << " vix build\n";
1306+
out << " vix build --with-sqlite\n";
1307+
out << " vix build --with-mysql\n";
1308+
out << " vix build --preset release --with-sqlite\n";
1309+
out << " vix build --preset dev-ninja --with-mysql\n";
12821310
out << " vix build --verbose\n";
12831311
out << " vix build --fast\n";
12841312
out << " vix build --preset release\n";

src/commands/check/CheckScript.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,13 @@ namespace vix::commands::CheckCommand::detail
211211

212212
if (!write_file_or_report(
213213
cmakeLists,
214-
run::make_script_cmakelists(exeName, script, useVixRuntime, /*scriptFlags=*/{})))
214+
run::make_script_cmakelists(
215+
exeName,
216+
script,
217+
useVixRuntime,
218+
/*scriptFlags=*/{},
219+
false,
220+
false)))
215221
{
216222
return 1;
217223
}

src/commands/run/RunFlow.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,18 @@ namespace vix::commands::RunCommand::detail
373373
else
374374
hint("Invalid value for --docs. Use 0|1|true|false.");
375375
}
376+
else if (a == "--with-sqlite")
377+
{
378+
o.withSqlite = true;
379+
}
380+
else if (a == "--with-mysql")
381+
{
382+
o.withMySql = true;
383+
}
384+
else if (a == "--clean")
385+
{
386+
o.clean = true;
387+
}
376388
else if (a == "--cwd")
377389
{
378390
std::filesystem::path p = take_value(i, "--cwd");

src/commands/run/RunScript.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,13 @@ namespace vix::commands::RunCommand::detail
427427

428428
{
429429
ofstream ofs(cmakeLists);
430-
ofs << make_script_cmakelists(exeName, script, useVixRuntime, o.scriptFlags);
430+
ofs << make_script_cmakelists(
431+
exeName,
432+
script,
433+
useVixRuntime,
434+
o.scriptFlags,
435+
o.withSqlite,
436+
o.withMySql);
431437
}
432438

433439
fs::path buildDir = projectDir / "build-ninja";
@@ -786,12 +792,21 @@ namespace vix::commands::RunCommand::detail
786792
exeName,
787793
script,
788794
useVixRuntime,
789-
o.scriptFlags);
795+
o.scriptFlags,
796+
o.withSqlite,
797+
o.withMySql);
790798
}
791799

792800
fs::path buildDir = projectDir / "build-ninja";
793801
const fs::path sigFile = projectDir / ".vix-config.sig";
794802

803+
if (o.clean)
804+
{
805+
std::error_code ec;
806+
fs::remove_all(buildDir, ec);
807+
fs::remove(sigFile, ec);
808+
}
809+
795810
const std::string sig = make_script_config_signature(
796811
useVixRuntime,
797812
o.enableSanitizers,

src/commands/run/detail/ScriptCMake.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,9 @@ namespace vix::commands::RunCommand::detail
716716
const std::string &exeName,
717717
const fs::path &cppPath,
718718
bool useVixRuntime,
719-
const std::vector<std::string> &scriptFlags)
719+
const std::vector<std::string> &scriptFlags,
720+
bool withSqlite,
721+
bool withMySql)
720722
{
721723
std::string s;
722724
s.reserve(32000);
@@ -1085,6 +1087,28 @@ namespace vix::commands::RunCommand::detail
10851087
}
10861088
else
10871089
{
1090+
if (withSqlite || withMySql)
1091+
{
1092+
s += "set(VIX_ENABLE_DB ON CACHE BOOL \"\" FORCE)\n";
1093+
}
1094+
1095+
if (withSqlite)
1096+
{
1097+
s += "set(VIX_DB_USE_SQLITE ON CACHE BOOL \"\" FORCE)\n";
1098+
s += "set(VIX_DB_REQUIRE_SQLITE ON CACHE BOOL \"\" FORCE)\n";
1099+
}
1100+
1101+
if (withMySql)
1102+
{
1103+
s += "set(VIX_DB_USE_MYSQL ON CACHE BOOL \"\" FORCE)\n";
1104+
s += "set(VIX_DB_REQUIRE_MYSQL ON CACHE BOOL \"\" FORCE)\n";
1105+
}
1106+
1107+
if (withSqlite || withMySql)
1108+
{
1109+
s += "\n";
1110+
}
1111+
10881112
s += "find_package(vix QUIET CONFIG)\n";
10891113
s += "if (NOT vix_FOUND)\n";
10901114
s += " find_package(Vix CONFIG REQUIRED)\n";

0 commit comments

Comments
 (0)