11#include " Manifest.hpp"
22
33#include " Builder/BuildProfile.hpp"
4+ #include " Builder/Builder.hpp"
45#include " Builder/Compiler.hpp"
6+ #include " Diag.hpp"
57#include " Semver.hpp"
68#include " TermColor.hpp"
79#include " VersionReq.hpp"
@@ -103,14 +105,16 @@ static fs::path canonicalizePathDep(const fs::path& baseDir,
103105}
104106
105107static rs::Result<void >
106- installDependencies (const Manifest& manifest, bool includeDevDeps,
108+ installDependencies (const Manifest& manifest, const BuildProfile& buildProfile,
109+ bool includeDevDeps, bool suppressDepDiag,
107110 std::unordered_map<std::string, DepKey>& seenDeps,
108111 std::unordered_set<fs::path>& visited,
109112 std::vector<CompilerOpts>& installed);
110113
111114static rs::Result<void >
112115installPathDependency (const Manifest& manifest, const PathDependency& pathDep,
113- bool includeDevDeps,
116+ const BuildProfile& buildProfile, bool includeDevDeps,
117+ bool suppressDepDiag,
114118 std::unordered_map<std::string, DepKey>& seenDeps,
115119 std::unordered_set<fs::path>& visited,
116120 std::vector<CompilerOpts>& installed) {
@@ -124,22 +128,58 @@ installPathDependency(const Manifest& manifest, const PathDependency& pathDep,
124128 }
125129
126130 CompilerOpts pathOpts;
127- pathOpts.cFlags .includeDirs .emplace_back (resolveIncludeDir (depRoot),
128- /* isSystem=*/ false );
129-
130131 const fs::path depManifestPath = depRoot / Manifest::FILE_NAME;
131132 rs_ensure (fs::exists (depManifestPath), " missing `{}` in path dependency {}" ,
132133 Manifest::FILE_NAME, depRoot.string ());
133134 const Manifest depManifest =
134135 rs_try (Manifest::tryParse (depManifestPath, false ));
135136
137+ if (!suppressDepDiag) {
138+ Diag::info (" Building" , " {} ({})" , depManifest.package .name ,
139+ depRoot.string ());
140+ }
141+
142+ Builder depBuilder (depRoot, buildProfile);
143+ ScheduleOptions depOptions;
144+ depOptions.includeDevDeps = includeDevDeps;
145+ depOptions.suppressAnalysisLog = true ;
146+ depOptions.suppressFinishLog = true ;
147+ depOptions.suppressDepDiag = suppressDepDiag;
148+ rs_try (depBuilder.schedule (depOptions));
149+ rs_try (depBuilder.build ());
150+
151+ const BuildGraph& depGraph = depBuilder.graph ();
152+ const fs::path depOutDir = depGraph.outBasePath ();
153+ const fs::path libPath = depOutDir / depGraph.libraryName ();
154+
155+ pathOpts.cFlags .includeDirs .emplace_back (resolveIncludeDir (depRoot),
156+ /* isSystem=*/ false );
157+
136158 std::vector<CompilerOpts> nestedDeps;
137- rs_try (installDependencies (depManifest, includeDevDeps, seenDeps, visited ,
138- nestedDeps));
159+ rs_try (installDependencies (depManifest, buildProfile, includeDevDeps ,
160+ suppressDepDiag, seenDeps, visited, nestedDeps));
139161 for (const CompilerOpts& opts : nestedDeps) {
140162 pathOpts.merge (opts);
141163 }
142164
165+ const bool libBuilt = fs::exists (libPath);
166+ if (depGraph.hasLibraryTarget ()) {
167+ rs_ensure (libBuilt, " expected `{}` to be built for dependency {}" ,
168+ libPath.string (), depManifest.package .name );
169+ }
170+
171+ if (libBuilt) {
172+ pathOpts.ldFlags .libDirs .emplace (pathOpts.ldFlags .libDirs .begin (),
173+ libPath.parent_path ());
174+
175+ std::string libName = libPath.stem ().string ();
176+ if (libName.starts_with (" lib" )) {
177+ libName.erase (0 , 3 );
178+ }
179+ pathOpts.ldFlags .libs .emplace (pathOpts.ldFlags .libs .begin (),
180+ std::move (libName));
181+ }
182+
143183 installed.emplace_back (std::move (pathOpts));
144184 return rs::Ok ();
145185}
@@ -201,7 +241,8 @@ rememberDep(const Manifest& manifest, const Dependency& dep,
201241}
202242
203243static rs::Result<void >
204- installDependencies (const Manifest& manifest, const bool includeDevDeps,
244+ installDependencies (const Manifest& manifest, const BuildProfile& buildProfile,
245+ const bool includeDevDeps, const bool suppressDepDiag,
205246 std::unordered_map<std::string, DepKey>& seenDeps,
206247 std::unordered_set<fs::path>& visited,
207248 std::vector<CompilerOpts>& installed) {
@@ -219,7 +260,8 @@ installDependencies(const Manifest& manifest, const bool includeDevDeps,
219260 rs_try (Manifest::tryParse (depManifestPath, false ));
220261
221262 std::vector<CompilerOpts> nestedDeps;
222- rs_try (installDependencies (depManifest, includeDevDeps,
263+ rs_try (installDependencies (depManifest, buildProfile,
264+ includeDevDeps, suppressDepDiag,
223265 seenDeps, visited, nestedDeps));
224266 for (const CompilerOpts& opts : nestedDeps) {
225267 depOpts.merge (opts);
@@ -234,7 +276,8 @@ installDependencies(const Manifest& manifest, const bool includeDevDeps,
234276 return rs::Ok ();
235277 },
236278 [&](const PathDependency& pathDep) -> rs::Result<void > {
237- return installPathDependency (manifest, pathDep, includeDevDeps,
279+ return installPathDependency (manifest, pathDep, buildProfile,
280+ includeDevDeps, suppressDepDiag,
238281 seenDeps, visited, installed);
239282 },
240283 },
@@ -663,12 +706,14 @@ rs::Result<fs::path> Manifest::findPath(fs::path candidateDir) noexcept {
663706}
664707
665708rs::Result<std::vector<CompilerOpts>>
666- Manifest::installDeps (const bool includeDevDeps) const {
709+ Manifest::installDeps (const bool includeDevDeps,
710+ const BuildProfile& buildProfile,
711+ const bool suppressDepDiag) const {
667712 std::unordered_map<std::string, DepKey> seenDeps;
668713 std::unordered_set<fs::path> visited;
669714 std::vector<CompilerOpts> installed;
670- rs_try (
671- installDependencies (* this , includeDevDeps , seenDeps, visited, installed));
715+ rs_try (installDependencies (* this , buildProfile, includeDevDeps,
716+ suppressDepDiag , seenDeps, visited, installed));
672717 return rs::Ok (installed);
673718}
674719
0 commit comments