This commit is contained in:
parent
bc9ceb8f24
commit
0ab30a1d81
5 changed files with 249 additions and 18 deletions
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue