@@ -85,7 +85,6 @@ std::vector<std::string> extract_platform_flags(const toml::table& package_table
8585 return flags;
8686}
8787
88- // Extract compiler-specific flags
8988std::vector<std::string> extract_compiler_flags (const toml::table& package_table, const muuk::Compiler compiler) {
9089 std::vector<std::string> flags;
9190 if (!package_table.contains (" compiler" ))
@@ -104,6 +103,7 @@ std::vector<std::string> extract_compiler_flags(const toml::table& package_table
104103 return flags;
105104}
106105
106+ // / Parses compilation units (modules or sources) from the TOML array
107107void parse_compilation_unit (BuildManager& build_manager, const toml::array& unit_array, const CompilationUnitType compilation_unit_type, const std::filesystem::path& pkg_dir, CompilationFlags compilation_flags) {
108108
109109 for (const auto & unit_entry : unit_array) {
@@ -113,11 +113,11 @@ void parse_compilation_unit(BuildManager& build_manager, const toml::array& unit
113113 if (!unit_entry.contains (" path" ))
114114 continue ;
115115
116- std::string src_path = util::file_system::to_linux_path (
117- std::filesystem::absolute (
118- std::filesystem::path (unit_entry. at ( " path " ). as_string ()))
119- . string (),
120- " ../../ " );
116+ std::string src_path
117+ = util::file_system::to_linux_path (
118+ std::filesystem::absolute (
119+ std::filesystem::path (unit_entry. at ( " path " ). as_string ()))
120+ . string () );
121121
122122 std::string obj_path = util::file_system::to_linux_path (
123123 (pkg_dir / std::filesystem::path (src_path).stem ()).string () + OBJ_EXT,
@@ -246,20 +246,30 @@ void parse_libraries(BuildManager& build_manager, const muuk::Compiler compiler,
246246 }
247247
248248 std::vector<std::string> obj_files;
249- if (library_table. contains ( " sources " )) {
250- auto sources = library_table. at ( " sources " ). as_array ();
251- for (const auto & src_entry : sources ) {
252- if (!src_entry .is_table ())
249+
250+ auto parse_entries = [&build_dir, &library_name, &library_version, &obj_files]( const toml::array& entries) {
251+ for (const auto & entry : entries ) {
252+ if (!entry .is_table ())
253253 continue ;
254- auto source_table = src_entry .as_table ();
255- if (!source_table .contains (" path" ))
254+ auto entry_table = entry .as_table ();
255+ if (!entry_table .contains (" path" ))
256256 continue ;
257257
258258 const auto obj_file = util::file_system::to_linux_path (
259- (build_dir / library_name / library_version / std::filesystem::path (source_table .at (" path" ).as_string ()).stem ()).string () + OBJ_EXT,
259+ (build_dir / library_name / library_version / std::filesystem::path (entry_table .at (" path" ).as_string ()).stem ()).string () + OBJ_EXT,
260260 " ../../" );
261261 obj_files.push_back (obj_file);
262262 }
263+ };
264+
265+ // Parse modules
266+ if (library_table.contains (" modules" )) {
267+ parse_entries (library_table.at (" modules" ).as_array ());
268+ }
269+
270+ // Parse sources
271+ if (library_table.contains (" sources" )) {
272+ parse_entries (library_table.at (" sources" ).as_array ());
263273 }
264274
265275 auto aflags = muuk::parse_array_as_vec (library_table.as_table (), " aflags" );
@@ -393,7 +403,8 @@ void parse_executables(BuildManager& build_manager, const muuk::Compiler compile
393403 if (lib_map.contains (lib_name) && lib_map.at (lib_name).contains (version)) {
394404 const auto & lib_table = lib_map.at (lib_name).at (version).as_table ();
395405
396- if (lib_table.contains (" sources" )) {
406+ // If it doesn't have these keys, then its an empty library so we should skip it
407+ if (lib_table.contains (" sources" ) || lib_table.contains (" modules" )) {
397408 std::string lib_path = util::file_system::to_linux_path (
398409 (build_dir / lib_name / version / (lib_name + LIB_EXT)).string (), " ../../" );
399410 libs.push_back (lib_path);
@@ -417,10 +428,10 @@ void parse_executables(BuildManager& build_manager, const muuk::Compiler compile
417428 build_manager.add_link_target (exe_path, obj_files, libs, lflags);
418429
419430 muuk::logger::info (" Added link target: {}" , exe_path);
420- muuk::logger::trace (" - Object Files: {} " , fmt::join (obj_files, " , " ));
421- muuk::logger::trace (" - Libraries: {} " , fmt::join (libs, " , " ));
422- muuk::logger::trace (" - Include Flags: {} " , fmt::join (iflags, " , " ));
423- muuk::logger::trace (" - Linker Flags: {} " , fmt::join (lflags, " , " ));
431+ muuk::logger::trace (" - Object Files: '{}' " , fmt::join (obj_files, " ', ' " ));
432+ muuk::logger::trace (" - Libraries: '{}' " , fmt::join (libs, " ', ' " ));
433+ muuk::logger::trace (" - Include Flags: '{}' " , fmt::join (iflags, " ', ' " ));
434+ muuk::logger::trace (" - Linker Flags: '{}' " , fmt::join (lflags, " ', ' " ));
424435 }
425436}
426437
0 commit comments