This commit is contained in:
parent
bc9ceb8f24
commit
0ab30a1d81
5 changed files with 249 additions and 18 deletions
|
|
@ -62,7 +62,9 @@ void Configuration::GetInterfacesAndImplementations(std::span<fs::path> interfac
|
|||
|
||||
std::vector<std::tuple<fs::path, std::string, ModulePartition*, Module*>> tempModulePaths = std::vector<std::tuple<fs::path, std::string, ModulePartition*, Module*>>(interfaces.size());
|
||||
for(std::uint16_t i = 0; i < interfaces.size(); i++){
|
||||
fs::path file = path / interfaces[i];
|
||||
// Resolve to absolute now so the stored path survives cwd changes
|
||||
// (matters for GitProject deps loaded from a different working dir).
|
||||
fs::path file = fs::absolute(path / interfaces[i]).lexically_normal();
|
||||
file += ".cppm";
|
||||
std::ifstream t(file);
|
||||
std::stringstream buffer;
|
||||
|
|
@ -136,7 +138,7 @@ void Configuration::GetInterfacesAndImplementations(std::span<fs::path> interfac
|
|||
}
|
||||
|
||||
for(const fs::path& tempFile : implementations) {
|
||||
fs::path file = path / tempFile;
|
||||
fs::path file = fs::absolute(path / tempFile).lexically_normal();
|
||||
file += ".cpp";
|
||||
std::ifstream t(file);
|
||||
std::stringstream buffer;
|
||||
|
|
@ -232,8 +234,8 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
}
|
||||
#endif
|
||||
|
||||
fs::path buildDir = config.path/"build"/std::format("{}-{}-{}", config.name, config.target, config.march);
|
||||
fs::path outputDir = config.path/"bin"/std::format("{}-{}-{}", config.name, config.target, config.march);
|
||||
fs::path buildDir = config.BuildDir();
|
||||
fs::path outputDir = config.BinDir();
|
||||
|
||||
if (!fs::exists(buildDir)) {
|
||||
fs::create_directories(buildDir);
|
||||
|
|
@ -520,7 +522,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
files += std::format(" {}_source.o ", (buildDir / cFile.filename()).string());
|
||||
const std::string objPath = (buildDir / cFile.filename()).string() + "_source.o";
|
||||
const std::string srcPath = cFile.string() + ".c";
|
||||
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
||||
if (!fs::exists(objPath) || (fs::exists(srcPath) && fs::last_write_time(srcPath) > fs::last_write_time(objPath))) {
|
||||
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled, &config]() {
|
||||
Progress::Task task(std::format("Compiling {}.c", cFile.filename().string()));
|
||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||
|
|
@ -540,7 +542,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
files += std::format(" {}_source.o ", (buildDir / cFile.filename()).string());
|
||||
const std::string objPath = (buildDir / cFile.filename()).string() + "_source.o";
|
||||
const std::string srcPath = cFile.string() + ".cu";
|
||||
if (!fs::exists(objPath) || fs::last_write_time(srcPath) > fs::last_write_time(objPath)) {
|
||||
if (!fs::exists(objPath) || (fs::exists(srcPath) && fs::last_write_time(srcPath) > fs::last_write_time(objPath))) {
|
||||
threads.emplace_back([&cFile, &buildDir, &buildError, &buildCancelled]() {
|
||||
Progress::Task task(std::format("Compiling {}.cu", cFile.filename().string()));
|
||||
if (buildCancelled.load(std::memory_order_relaxed)) return;
|
||||
|
|
@ -669,7 +671,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
// but the consumer was never relinked against the new dep.
|
||||
{
|
||||
auto expectedOutputFor = [](const Configuration& c) -> fs::path {
|
||||
fs::path dir = c.path/"bin"/std::format("{}-{}-{}", c.name, c.target, c.march);
|
||||
fs::path dir = c.BinDir();
|
||||
if (c.type == ConfigurationType::Executable) {
|
||||
if (c.target.starts_with("wasm32"))
|
||||
return dir / (c.outputName + ".wasm");
|
||||
|
|
@ -719,7 +721,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
std::function<void(Configuration*)> copyDepDlls = [&](Configuration* dep) {
|
||||
if (!dllSeen.insert(dep).second) return;
|
||||
if (dep->type == ConfigurationType::LibraryDynamic && dep->target == "x86_64-w64-mingw32") {
|
||||
fs::path depDir = dep->path / "bin" / std::format("{}-{}-{}", dep->name, dep->target, dep->march);
|
||||
fs::path depDir = dep->BinDir();
|
||||
// The DLL itself (Windows resolves it from the
|
||||
// exe's directory at load time) and the mingw
|
||||
// import lib (so a downstream `crafter-build.exe`
|
||||
|
|
@ -761,7 +763,7 @@ BuildResult Crafter::Build(Configuration& config, std::unordered_map<fs::path, s
|
|||
std::function<void(Configuration*)> copyDepDlls = [&](Configuration* dep) {
|
||||
if (!dllSeen.insert(dep).second) return;
|
||||
if (dep->type == ConfigurationType::LibraryDynamic && dep->target == "x86_64-w64-mingw32") {
|
||||
fs::path depDir = dep->path / "bin" / std::format("{}-{}-{}", dep->name, dep->target, dep->march);
|
||||
fs::path depDir = dep->BinDir();
|
||||
for (auto fname : {std::format("{}.dll", dep->outputName),
|
||||
std::format("lib{}.dll.a", dep->outputName)}) {
|
||||
fs::path src = depDir / fname;
|
||||
|
|
@ -863,19 +865,25 @@ std::string Crafter::HostTarget() {
|
|||
return cached;
|
||||
}
|
||||
|
||||
void Crafter::ApplyStandardArgs(Configuration& cfg, std::span<const std::string_view> args) {
|
||||
ArgQuery Crafter::ApplyStandardArgs(Configuration& cfg, std::span<const std::string_view> args) {
|
||||
if (const char* envMarch = std::getenv("CRAFTER_BUILD_MARCH"); envMarch && *envMarch) {
|
||||
cfg.march = envMarch;
|
||||
}
|
||||
if (const char* envMtune = std::getenv("CRAFTER_BUILD_MTUNE"); envMtune && *envMtune) {
|
||||
cfg.mtune = envMtune;
|
||||
}
|
||||
bool sawLib = false, sawShared = false;
|
||||
for (std::string_view a : args) {
|
||||
if (a == "--debug") cfg.debug = true;
|
||||
else if (a == "--lib") sawLib = true;
|
||||
else if (a == "--shared") sawShared = true;
|
||||
else if (a.starts_with("--target=")) cfg.target = std::string(a.substr(std::string_view("--target=").size()));
|
||||
else if (a.starts_with("--march=")) cfg.march = std::string(a.substr(std::string_view("--march=").size()));
|
||||
else if (a.starts_with("--mtune=")) cfg.mtune = std::string(a.substr(std::string_view("--mtune=").size()));
|
||||
}
|
||||
if (sawLib && cfg.type == ConfigurationType::Executable) cfg.type = ConfigurationType::LibraryStatic;
|
||||
if (sawShared && cfg.type == ConfigurationType::LibraryStatic) cfg.type = ConfigurationType::LibraryDynamic;
|
||||
return ArgQuery{args};
|
||||
}
|
||||
|
||||
static void PrintHelp(std::string_view argv0) {
|
||||
|
|
@ -1015,7 +1023,7 @@ int Crafter::Run(int argc, char** argv) {
|
|||
std::println(std::cerr, "-r: cannot run a library");
|
||||
return 1;
|
||||
}
|
||||
fs::path dir = config.path / "bin" / std::format("{}-{}-{}", config.name, config.target, config.march);
|
||||
fs::path dir = config.BinDir();
|
||||
fs::path artifact = dir / config.outputName;
|
||||
if (config.target.starts_with("wasm32")) {
|
||||
artifact += ".wasm";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue