fixes
Some checks failed
CI / build-test-release (push) Failing after 8m31s

This commit is contained in:
Jorijn van der Graaf 2026-04-30 02:20:19 +02:00
commit 0ab30a1d81
5 changed files with 249 additions and 18 deletions

View file

@ -117,10 +117,35 @@ export namespace Crafter {
std::vector<std::string> linkFlags;
std::vector<Test> tests;
CRAFTER_API void GetInterfacesAndImplementations(std::span<fs::path> interfaces, std::span<fs::path> implementations);
// Suffix that uniquely identifies this Configuration's compile state.
// target+march+mtune are spelled out for readability; the rest
// (type, debug, sysroot, defines, compileFlags) collapse into a short
// hash so two Configurations sharing a path but with different
// compile state can't clobber each other's outputs.
std::string VariantId() const {
std::string compileKey;
compileKey += std::to_string(static_cast<int>(type));
compileKey += '|';
compileKey += debug ? '1' : '0';
compileKey += '|';
compileKey += sysroot;
for (const Define& d : defines) {
compileKey += "|D:";
compileKey += d.name;
compileKey += '=';
compileKey += d.value;
}
for (const std::string& f : compileFlags) {
compileKey += "|F:";
compileKey += f;
}
std::size_t configHash = std::hash<std::string>{}(compileKey);
return std::format("{}-{}-{}-{}-{:08x}", name, target, march, mtune, configHash);
}
fs::path BuildDir() const { return path / "build" / VariantId(); }
fs::path BinDir() const { return path / "bin" / VariantId(); }
fs::path PcmDir() const {
return path
/ (type == ConfigurationType::Executable ? "build" : "bin")
/ std::format("{}-{}-{}", name, target, march);
return type == ConfigurationType::Executable ? BuildDir() : BinDir();
}
};
@ -143,14 +168,39 @@ export namespace Crafter {
// outputName so renaming the binary later requires another call.
CRAFTER_API void EnableWasiBrowserRuntime(Configuration& cfg);
// View over the project's args with simple query helpers — kept inline
// so it works across the DLL boundary without an extra ABI hop. Use
// Has(flag) for boolean switches and Get(prefix) for valued options
// (e.g. Get("--prefix=") returns the substring after the equals).
struct ArgQuery {
std::span<const std::string_view> args;
bool Has(std::string_view flag) const {
for (std::string_view a : args) if (a == flag) return true;
return false;
}
std::optional<std::string> Get(std::string_view prefix) const {
for (std::string_view a : args) {
if (a.starts_with(prefix)) return std::string(a.substr(prefix.size()));
}
return std::nullopt;
}
};
// Apply the framework's standard CLI args + env vars onto cfg:
// --debug cfg.debug = true
// --target=<triple> cfg.target = <triple>
// --march=<value> cfg.march = <value>
// --mtune=<value> cfg.mtune = <value>
// --lib cfg.type promoted Executable → LibraryStatic
// --shared cfg.type promoted LibraryStatic → LibraryDynamic
// Promotions chain in priority order so `--lib --shared` lands on
// LibraryDynamic regardless of arg order; each is a no-op when the
// baseline doesn't match (e.g. --shared on an Executable, or --lib on a
// pre-set library).
// $CRAFTER_BUILD_MARCH / $CRAFTER_BUILD_MTUNE seed march/mtune.
// Env applies first, then args, so CLI wins over env wins over caller's
// pre-set defaults. Project-specific flags (e.g. --shared, --timing) are
// not handled here — parse them in your own loop alongside this call.
CRAFTER_API void ApplyStandardArgs(Configuration& cfg, std::span<const std::string_view> args);
// pre-set defaults. Returns an ArgQuery over the same span so projects
// can query their own flags (`--timing`, ...) without re-rolling the
// for-arg-in-args loop.
CRAFTER_API ArgQuery ApplyStandardArgs(Configuration& cfg, std::span<const std::string_view> args);
}

View file

@ -24,6 +24,8 @@ import std;
namespace fs = std::filesystem;
export namespace Crafter {
struct Configuration;
struct GitSource {
std::string url;
std::string branch;
@ -55,4 +57,37 @@ export namespace Crafter {
const ExternalDependency& dep,
std::string_view target,
std::atomic<bool>& cancelled);
// Specification for a sibling crafter-build project to fetch and depend on.
// GitSource picks the revision: leave branch + commit empty for the
// remote's default branch HEAD (sloppy but convenient), set branch to
// track a branch tip, or set commit to pin to an immutable SHA. args are
// forwarded verbatim to the dep's CrafterBuildProject — typically you
// pass through the parent's args so target/march/debug propagate.
struct GitProjectSpec {
GitSource source;
fs::path projectFile = "project.cpp";
std::vector<std::string> args;
};
// Clones the spec's git URL into the per-project external cache (keyed by
// url+branch+commit+args+projectFile), recursively LoadProject's the
// remote's project.cpp, and returns a stable Configuration* you can drop
// into cfg.dependencies. The Configuration is owned by an internal cache
// for the lifetime of the build; identical specs share one Configuration.
CRAFTER_API Configuration* GitProject(const GitProjectSpec& spec);
// Specification for a local sibling crafter-build project (e.g. an
// example folder depending on its parent project, or a workspace where
// multiple projects live side-by-side without going through git).
struct LocalProjectSpec {
fs::path projectFile; // relative to cwd or absolute
std::vector<std::string> args; // forwarded to dep's CrafterBuildProject
};
// Same as GitProject but for a local on-disk project — no fetch, no
// cache copy. Resolves projectFile to its canonical absolute path and
// recursively LoadProject's it. Returns a stable Configuration* owned
// by the same internal cache as GitProject.
CRAFTER_API Configuration* LocalProject(const LocalProjectSpec& spec);
}