build(wasm): libconfig now builds and works in wasm

This commit is contained in:
2025-12-03 08:54:33 -05:00
parent 067a3a0d51
commit 1a7f4837c6
9 changed files with 138 additions and 7 deletions

View File

@@ -0,0 +1,4 @@
men: ["John Smith", "Bill Jones"]
women:
- Karol Boudreaux
- Emily Boudreaux

2
examples/meson.build Normal file
View File

@@ -0,0 +1,2 @@
executable('simple_config_test', 'simple.cpp', dependencies: [config_dep])
executable('simple_config_wasm_test', 'wasm.cpp', dependencies: [config_dep])

35
examples/simple.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "fourdst/config/config.h"
#include <string>
#include <vector>
#include <iostream>
#include <filesystem>
std::string get_validated_filename(int argc, char* argv[]) {
if (argc != 2) {
std::cout << "Usage: " << argv[0] << " <input_file>" << std::endl;
exit(1);
}
std::filesystem::path const file_path{ argv[1] };
if (not std::filesystem::exists(file_path) || not std::filesystem::is_regular_file(file_path)) {
std::cout << "Error: File does not exist or is not a regular file." << std::endl;
exit(1);
}
return file_path.string();
}
int main(int argc, char* argv[]) {
fourdst::config::Config& config = fourdst::config::Config::getInstance();
std::string filename = get_validated_filename(argc, argv);
config.loadConfig(filename);
auto men = config.get<std::vector<std::string>>("men", {});
for (const auto& name : men) {
std::cout << "men are " << name << std::endl;
}
}

19
examples/wasm.cpp Normal file
View File

@@ -0,0 +1,19 @@
#include "fourdst/config/config.h"
#include <string>
#include <vector>
#include <iostream>
#include <filesystem>
int main(int argc, char* argv[]) {
fourdst::config::Config& config = fourdst::config::Config::getInstance();
config.loadConfig("/input.yaml");
auto men = config.get<std::vector<std::string>>("men", {});
for (const auto& name : men) {
std::cout << "men are " << name << std::endl;
}
}