v2 nearly done

This commit is contained in:
Jorijn van der Graaf 2026-04-27 07:04:42 +02:00
commit f13671b2be
24 changed files with 1467 additions and 314 deletions

View file

@ -20,6 +20,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
export module Crafter.Build:Clang;
import std;
import :Shader;
import :Interface;
import :Implementation;
import :External;
namespace fs = std::filesystem;
export namespace Crafter {
@ -27,14 +30,9 @@ export namespace Crafter {
std::string result;
bool repack;
std::unordered_set<std::string> libs;
}
};
struct Dependency {
fs::path path;
std::vector<std::pair<std::string, std::string>> arguments;
}
export struct Define {
struct Define {
std::string name;
std::string value;
};
@ -46,20 +44,34 @@ export namespace Crafter {
};
struct Configuration {
fs::path path;
std::string outputName;
std::string name;
std::string march = "native";
std::string mtune = "native";
std::string target;
bool debug = false;
ConfigurationType type = ConfigurationType::Executable;
std::vector<std::path> interfaces;
std::vector<std::path> implementations;
std::vector<std::path> cFiles;
std::vector<std::path> dependencies;
std::vector<std::path> files;
std::vector<std::unique_ptr<Module>> interfaces;
std::vector<Implementation> implementations;
std::vector<fs::path> cFiles;
std::vector<fs::path> cuda;
std::vector<Configuration*> dependencies;
std::vector<fs::path> files;
std::vector<Define> defines;
std::vector<Shader> shaders;
std::vector<Dependency> deps;
}
std::vector<ExternalDependency> externalDependencies;
std::vector<std::string> compileFlags;
std::vector<std::string> linkFlags;
void GetInterfacesAndImplementations(std::span<fs::path> interfaces, std::span<fs::path> implementations);
fs::path PcmDir() const {
return path
/ (type == ConfigurationType::Executable ? "build" : "bin")
/ std::format("{}-{}-{}", name, target, march);
}
};
BuildResult Build(fs::path config, std::unordered_set<std::string> depSet);
BuildResult Build(const Configuration& config, std::unordered_set<std::string> depSet);
BuildResult Build(Configuration& config, std::unordered_map<fs::path, std::shared_future<BuildResult>>& depResults, std::mutex& depMutex);
int Run(int argc, char** argv);
}

View file

@ -0,0 +1,55 @@
/*
Crafter® Build
Copyright (C) 2026 Catcrafts®
Catcrafts.net
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License version 3.0 as published by the Free Software Foundation;
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
export module Crafter.Build:External;
import std;
namespace fs = std::filesystem;
export namespace Crafter {
struct GitSource {
std::string url;
std::string branch;
std::string commit;
};
enum class ExternalBuilder {
None,
CMake,
};
struct ExternalDependency {
std::string name;
GitSource source;
ExternalBuilder builder = ExternalBuilder::None;
std::vector<std::string> options;
std::vector<fs::path> includeDirs;
std::vector<std::string> libs;
};
struct ExternalBuildResult {
std::string error;
std::vector<std::string> compileFlags;
std::vector<std::string> linkFlags;
fs::file_time_type latestArtifact = fs::file_time_type::min();
};
ExternalBuildResult BuildExternal(
const ExternalDependency& dep,
std::atomic<bool>& cancelled);
}

View file

@ -18,7 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
export module Crafter.Build:Implementation;
import :CompileStatus;
import std;
namespace fs = std::filesystem;
@ -29,9 +28,10 @@ namespace Crafter {
public:
std::vector<Module*> moduleDependencies;
std::vector<ModulePartition*> partitionDependencies;
std::vector<std::pair<Module*, fs::path>> externalModuleDependencies;
fs::path path;
Implementation(fs::path&& path);
bool Check(const fs::path& buildDir, const fs::path& pcmDir) const;
void Compile(const std::string_view clang, const fs::path& buildDir, std::string& result) const;
bool Check(const fs::path& buildDir, const fs::path& pcmDir, fs::file_time_type sourceFloor = fs::file_time_type::min()) const;
void Compile(const std::string_view clang, const fs::path& buildDir, std::atomic<bool>& buildCancelled, std::string& buildError) const;
};
}

View file

@ -27,13 +27,14 @@ namespace Crafter {
public:
std::vector<Module*> moduleDependencies;
std::vector<ModulePartition*> partitionDependencies;
std::vector<std::pair<Module*, fs::path>> externalModuleDependencies;
std::atomic<bool> compiled;
bool needsRecompiling;
bool checked = false;
std::string name;
fs::path path;
ModulePartition(std::string&& name, fs::path&& path);
bool Check(const fs::path& pcmDir);
bool Check(const fs::path& pcmDir, fs::file_time_type sourceFloor = fs::file_time_type::min());
void Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::atomic<bool>& buildCancelled, std::string& buildError);
};
@ -46,7 +47,7 @@ namespace Crafter {
std::string name;
fs::path path;
Module(std::string&& name, fs::path&& path);
bool Check(const fs::path& pcmDir);
bool Check(const fs::path& pcmDir, fs::file_time_type sourceFloor = fs::file_time_type::min());
void Compile(const std::string_view clang, const fs::path& pcmDir, const fs::path& buildDir, std::atomic<bool>& buildCancelled, std::string& buildError);
};
}

View file

@ -23,8 +23,14 @@ namespace fs = std::filesystem;
namespace Crafter {
struct Configuration;
std::string BuildStdPcm(Configuration& config);
struct CommandResult {
int exitCode;
std::string output;
};
std::string BuildStdPcm(const Configuration& config, fs::path stdPcm);
fs::path GetCacheDir();
std::string RunCommand();
std::string GetBaseCommand(Configuration& config);
std::string RunCommand(const std::string_view command);
CommandResult RunCommandChecked(std::string_view command);
std::string GetBaseCommand(const Configuration& config);
export Configuration LoadProject(const fs::path& projectFile, std::span<const std::string_view> args);
}

View file

@ -17,19 +17,34 @@ License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
module;
#include "glslang/Public/ShaderLang.h"
export module Crafter.Build:Shader;
import std;
namespace fs = std::filesystem;
namespace Crafter {
export enum class ShaderType {
Vertex,
TessControl,
TessEvaluation,
Geometry,
Fragment,
Compute,
RayGen,
Intersect,
AnyHit,
ClosestHit,
Miss,
Callable,
Task,
Mesh,
};
export class Shader {
public:
fs::path path;
std::string entrypoint;
EShLanguage type;
Shader(fs::path&& path, std::string&& entrypoint, EShLanguage type);
ShaderType type;
Shader(fs::path&& path, std::string&& entrypoint, ShaderType type);
bool Check(const fs::path& outputDir) const;
std::string Compile(const fs::path& outputDir) const;
};

View file

@ -21,4 +21,5 @@ export module Crafter.Build;
export import :Clang;
export import :Platform;
export import :Implementation;
export import :Shader;
export import :Shader;
export import :External;