wasm
This commit is contained in:
parent
47b135aca0
commit
f90881b03d
9824 changed files with 1706556 additions and 114 deletions
|
|
@ -57,7 +57,7 @@ namespace Crafter {
|
|||
}
|
||||
throw std::runtime_error(std::format("Configuration: {} not found.", configuration));
|
||||
}
|
||||
Configuration& Project::Build(std::string_view configuration, const fs::path& binDir, const fs::path& buildDir, const std::string_view outputName) {
|
||||
Configuration& Project::Build(std::string_view configuration, const fs::path& binDir, const fs::path& buildDir, std::string outputName) {
|
||||
for(Configuration& config : configurations) {
|
||||
if(config.name == configuration){
|
||||
Build(config, binDir, buildDir, outputName);
|
||||
|
|
@ -85,7 +85,7 @@ namespace Crafter {
|
|||
void Project::Build(Configuration& config, const fs::path& binDir, const fs::path& buildDir) const {
|
||||
Build(config, binDir, buildDir, name);
|
||||
}
|
||||
void Project::Build(Configuration& config, const fs::path& binDir, const fs::path& buildDir, const std::string_view outputName) const {
|
||||
void Project::Build(Configuration& config, const fs::path& binDir, const fs::path& buildDir, std::string outputName) const {
|
||||
if (!fs::exists(binDir)) {
|
||||
fs::create_directories(binDir);
|
||||
}
|
||||
|
|
@ -102,20 +102,41 @@ namespace Crafter {
|
|||
}
|
||||
|
||||
std::thread fileThread([&config, &binDir](){
|
||||
for(const fs::path& additionalFile : config.additionalFiles){
|
||||
if(!fs::exists(binDir/additionalFile.filename())) {
|
||||
fs::copy(additionalFile, binDir);
|
||||
} else if (fs::last_write_time(additionalFile) > fs::last_write_time(binDir/additionalFile.filename())){
|
||||
fs::remove(binDir/additionalFile.filename());
|
||||
fs::copy(additionalFile, binDir);
|
||||
for (const fs::path& additionalFile : config.additionalFiles) {
|
||||
fs::path destination = binDir / additionalFile.filename();
|
||||
|
||||
if (fs::is_directory(additionalFile)) {
|
||||
if (!fs::exists(destination)) {
|
||||
fs::copy(additionalFile, destination, fs::copy_options::recursive);
|
||||
} else if (fs::last_write_time(additionalFile) > fs::last_write_time(destination)) {
|
||||
fs::remove_all(destination);
|
||||
fs::copy(additionalFile, destination, fs::copy_options::recursive);
|
||||
}
|
||||
} else {
|
||||
// Handle regular file
|
||||
if (!fs::exists(destination)) {
|
||||
fs::copy(additionalFile, destination);
|
||||
} else if (fs::last_write_time(additionalFile) > fs::last_write_time(destination)) {
|
||||
fs::remove(destination);
|
||||
fs::copy(additionalFile, destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
char path[PATH_MAX];
|
||||
ssize_t count = readlink("/proc/self/exe", path, PATH_MAX);
|
||||
if (count == -1) {
|
||||
throw std::runtime_error("Failed to get executable path");
|
||||
}
|
||||
path[count] = '\0';
|
||||
const std::string exeDir = fs::path(path).parent_path().parent_path().string();
|
||||
std::string command = "clang++";
|
||||
if(!config.target.empty()) {
|
||||
command += std::format(" -target={}", config.target);
|
||||
command += std::format(" --target={}", config.target);
|
||||
if(config.target == "wasm32-wasi") {
|
||||
command += std::format(" --sysroot={}/wasi-sysroot-28.0 -fno-exceptions", exeDir);
|
||||
}
|
||||
}
|
||||
if(!config.march.empty()) {
|
||||
command += std::format(" -march={}", config.march);
|
||||
|
|
@ -148,27 +169,43 @@ namespace Crafter {
|
|||
command += " -O3";
|
||||
}
|
||||
|
||||
char path[PATH_MAX];
|
||||
ssize_t count = readlink("/proc/self/exe", path, PATH_MAX);
|
||||
if (count == -1) {
|
||||
throw std::runtime_error("Failed to get executable path");
|
||||
}
|
||||
path[count] = '\0';
|
||||
const std::string exeDir = fs::path(path).parent_path().parent_path().string();
|
||||
const std::string stdPcm = std::format("{}/std.pcm", exeDir);
|
||||
std::string gccVersion = RunCommand("g++ -dumpversion");
|
||||
gccVersion.pop_back();
|
||||
fs::path stdCc = fs::path(std::format("/usr/include/c++/{}/bits/std.cc", gccVersion));
|
||||
if(config.target != "wasm32-wasi") {
|
||||
const std::string stdPcm = std::format("{}/std.pcm", exeDir);
|
||||
std::string gccVersion = RunCommand("g++ -dumpversion");
|
||||
gccVersion.pop_back();
|
||||
fs::path stdCc = fs::path(std::format("/usr/include/c++/{}/bits/std.cc", gccVersion));
|
||||
|
||||
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
|
||||
std::string result = RunCommand(std::format(R"(cp {} {}/std.cppm
|
||||
clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/std.cppm -o {} )", stdCc.string(), exeDir, exeDir, stdPcm));
|
||||
if(result != "") {
|
||||
throw std::runtime_error(result);
|
||||
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
|
||||
std::string result = RunCommand(std::format("cp {} {}/std.cppm\nclang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/std.cppm -o {}", stdCc.string(), exeDir, exeDir, stdPcm));
|
||||
if(result != "") {
|
||||
throw std::runtime_error(result);
|
||||
}
|
||||
}
|
||||
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}", pcmDir.string(), exeDir);
|
||||
} else {
|
||||
const std::string stdPcm = std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.pcm", exeDir);
|
||||
fs::path stdCc = fs::path(std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.cppm", exeDir));
|
||||
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
|
||||
std::string result = RunCommand(std::format("clang++ -fno-exceptions --target=wasm32-wasi -nodefaultlibs --sysroot={}/wasi-sysroot-28.0 -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {} -o {}", exeDir, stdCc.string(), stdPcm));
|
||||
if(result != "") {
|
||||
throw std::runtime_error(result);
|
||||
}
|
||||
}
|
||||
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}/wasi-sysroot-28.0/share/libc++/v1", pcmDir.string(), exeDir);
|
||||
|
||||
const fs::path indexPath = std::format("{}/index.html", exeDir);
|
||||
const fs::path indexDstPath = binDir/"index.html";
|
||||
if(!fs::exists(indexDstPath) || fs::last_write_time(indexDstPath) < fs::last_write_time(indexPath)) {
|
||||
fs::copy(indexPath, indexDstPath);
|
||||
}
|
||||
|
||||
const fs::path runtimePath = std::format("{}/runtime.js", exeDir);
|
||||
const fs::path runtimeDstPath = binDir/"runtime.js";
|
||||
if(!fs::exists(runtimeDstPath) || fs::last_write_time(runtimeDstPath) < fs::last_write_time(runtimePath)) {
|
||||
fs::copy(runtimePath, runtimeDstPath);
|
||||
}
|
||||
}
|
||||
|
||||
command += std::format(" -fprebuilt-module-path={} -fprebuilt-module-path={}", pcmDir.string(), exeDir);
|
||||
|
||||
std::unordered_set<std::string> depLibSet;
|
||||
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
||||
|
|
@ -257,7 +294,14 @@ clang++ -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --pr
|
|||
thread.join();
|
||||
}
|
||||
|
||||
command += " -L/usr/local/lib";
|
||||
if(config.target != "wasm32-wasi") {
|
||||
command += " -L/usr/local/lib";
|
||||
}
|
||||
|
||||
if(config.target == "wasm32-wasi") {
|
||||
outputName += ".wasm";
|
||||
}
|
||||
|
||||
command += libsString;
|
||||
|
||||
for(const std::string& lib : config.libs) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue