This commit is contained in:
parent
e4e4e67cc0
commit
2d89528bdf
5 changed files with 51 additions and 35 deletions
|
|
@ -39,35 +39,35 @@ namespace Crafter {
|
||||||
std::filesystem::path GetPath();
|
std::filesystem::path GetPath();
|
||||||
|
|
||||||
void BuildWasmStdPcm(const Project& project, const Configuration& config) {
|
void BuildWasmStdPcm(const Project& project, const Configuration& config) {
|
||||||
fs::path exeDir = GetPath();
|
// fs::path exeDir = GetPath();
|
||||||
fs::create_directories(exeDir/config.target);
|
// fs::create_directories(exeDir/config.target);
|
||||||
|
|
||||||
const std::string stdPcm = std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.pcm", exeDir.string());
|
// const std::string stdPcm = std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.pcm", exeDir.string());
|
||||||
fs::path stdCc = fs::path(std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.cppm", exeDir.string()));
|
// fs::path stdCc = fs::path(std::format("{}/wasi-sysroot-28.0/share/libc++/v1/std.cppm", exeDir.string()));
|
||||||
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
|
// 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 -fno-c++-static-destructors --precompile {} -o {}", exeDir.string(), stdCc.string(), stdPcm));
|
// 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 -fno-c++-static-destructors --precompile {} -o {}", exeDir.string(), stdCc.string(), stdPcm));
|
||||||
if(result != "") {
|
// if(result != "") {
|
||||||
throw std::runtime_error(result);
|
// throw std::runtime_error(result);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
const fs::path indexPath = std::format("{}/index.html", exeDir.string());
|
// const fs::path indexPath = std::format("{}/index.html", exeDir.string());
|
||||||
const fs::path indexDstPath = project.binDir/"index.html";
|
// const fs::path indexDstPath = project.binDir/"index.html";
|
||||||
if(!fs::exists(indexDstPath)) {
|
// if(!fs::exists(indexDstPath)) {
|
||||||
fs::copy(indexPath, indexDstPath);
|
// fs::copy(indexPath, indexDstPath);
|
||||||
} else if(fs::last_write_time(indexDstPath) < fs::last_write_time(indexPath)) {
|
// } else if(fs::last_write_time(indexDstPath) < fs::last_write_time(indexPath)) {
|
||||||
fs::remove(indexDstPath);
|
// fs::remove(indexDstPath);
|
||||||
fs::copy(indexPath, indexDstPath);
|
// fs::copy(indexPath, indexDstPath);
|
||||||
}
|
// }
|
||||||
|
|
||||||
const fs::path runtimePath = std::format("{}/runtime.js", exeDir.string());
|
// const fs::path runtimePath = std::format("{}/runtime.js", exeDir.string());
|
||||||
const fs::path runtimeDstPath = project.binDir/"runtime.js";
|
// const fs::path runtimeDstPath = project.binDir/"runtime.js";
|
||||||
if(!fs::exists(runtimeDstPath)) {
|
// if(!fs::exists(runtimeDstPath)) {
|
||||||
fs::copy(runtimePath, runtimeDstPath);
|
// fs::copy(runtimePath, runtimeDstPath);
|
||||||
} else if(fs::last_write_time(runtimeDstPath) < fs::last_write_time(runtimePath)) {
|
// } else if(fs::last_write_time(runtimeDstPath) < fs::last_write_time(runtimePath)) {
|
||||||
fs::remove(runtimeDstPath);
|
// fs::remove(runtimeDstPath);
|
||||||
fs::copy(runtimePath, runtimeDstPath);
|
// fs::copy(runtimePath, runtimeDstPath);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||||
|
|
@ -182,7 +182,7 @@ namespace Crafter {
|
||||||
const std::string stdPcm = std::format("{}/{}{}/std.pcm", exeDir.string(), config.target, config.march);
|
const std::string stdPcm = std::format("{}/{}{}/std.pcm", exeDir.string(), config.target, config.march);
|
||||||
|
|
||||||
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time("/usr/share/libc++/v1/std.cppm")) {
|
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time("/usr/share/libc++/v1/std.cppm")) {
|
||||||
std::string result = RunCommand(std::format("clang++ --target={} -std=c++26 -stdlib=libc++ -march={} -mtune={} -O3 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile /usr/share/libc++/v1/std.cppm -o {}", config.target, config.march, config.march, stdPcm));
|
std::string result = RunCommand(std::format("clang++ --target={} -std=c++26 -stdlib=libc++ -march={} -mtune={} -O3 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile /usr/share/libc++/v1/std.cppm -o {}", config.target, config.march, config.mtune, stdPcm));
|
||||||
if(result != "") {
|
if(result != "") {
|
||||||
throw std::runtime_error(result);
|
throw std::runtime_error(result);
|
||||||
}
|
}
|
||||||
|
|
@ -191,9 +191,9 @@ namespace Crafter {
|
||||||
|
|
||||||
void BuildMingwStdPcm(const Project& project, const Configuration& config) {
|
void BuildMingwStdPcm(const Project& project, const Configuration& config) {
|
||||||
fs::path exeDir = GetPath();
|
fs::path exeDir = GetPath();
|
||||||
fs::create_directories(exeDir/config.target);
|
fs::create_directories(exeDir/(config.target+config.march));
|
||||||
|
|
||||||
const std::string stdPcm = std::format("{}/{}/std.pcm", exeDir.string(), config.target);
|
const std::string stdPcm = std::format("{}/{}{}/std.pcm", exeDir.string(), config.target, config.march);
|
||||||
std::vector<std::string> folders;
|
std::vector<std::string> folders;
|
||||||
|
|
||||||
// Iterate through the directory and collect all subdirectories
|
// Iterate through the directory and collect all subdirectories
|
||||||
|
|
@ -213,7 +213,7 @@ namespace Crafter {
|
||||||
fs::path stdCc = fs::path(std::format("/usr/x86_64-w64-mingw32/include/c++/{}/bits/std.cc", mingWversion));
|
fs::path stdCc = fs::path(std::format("/usr/x86_64-w64-mingw32/include/c++/{}/bits/std.cc", mingWversion));
|
||||||
|
|
||||||
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
|
if(!fs::exists(stdPcm) || fs::last_write_time(stdPcm) < fs::last_write_time(stdCc)) {
|
||||||
std::string result = RunCommand(std::format("cp {} {}/{}/std.cppm\nclang++ --target={} -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/{}/std.cppm -o {}", stdCc.string(), exeDir.string(), config.target, config.target, exeDir.string(), config.target, stdPcm));
|
std::string result = RunCommand(std::format("cp {} {}/{}{}/std.cppm\nclang++ --target={} -march={} -mtune={} -O3 -std=c++26 -Wno-reserved-identifier -Wno-reserved-module-identifier --precompile {}/{}{}/std.cppm -o {}", stdCc.string(), exeDir.string(), config.target, config.march, config.target, config.march, config.mtune, exeDir.string(), config.target, config.march, stdPcm));
|
||||||
if(result != "") {
|
if(result != "") {
|
||||||
throw std::runtime_error(result);
|
throw std::runtime_error(result);
|
||||||
}
|
}
|
||||||
|
|
@ -225,7 +225,7 @@ namespace Crafter {
|
||||||
// Check if the file is a regular file and ends with ".dll"
|
// Check if the file is a regular file and ends with ".dll"
|
||||||
if (fs::is_regular_file(entry) && entry.path().extension() == ".dll") {
|
if (fs::is_regular_file(entry) && entry.path().extension() == ".dll") {
|
||||||
// Construct the destination file path
|
// Construct the destination file path
|
||||||
fs::path dest_file = project.binDir / entry.path().filename();
|
fs::path dest_file = project.binDir / config.name / entry.path().filename();
|
||||||
|
|
||||||
// Check if the destination file exists and if it is older than the source file
|
// Check if the destination file exists and if it is older than the source file
|
||||||
if (!fs::exists(dest_file) || fs::last_write_time(entry.path()) > fs::last_write_time(dest_file)) {
|
if (!fs::exists(dest_file) || fs::last_write_time(entry.path()) > fs::last_write_time(dest_file)) {
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,13 @@ namespace Crafter {
|
||||||
} else {
|
} else {
|
||||||
march = "native";
|
march = "native";
|
||||||
}
|
}
|
||||||
|
if(config.contains("mtune")) {
|
||||||
|
mtune = config["mtune"].get<std::string>();
|
||||||
|
} else if(config.contains("march")) {
|
||||||
|
mtune = march;
|
||||||
|
} else {
|
||||||
|
mtune = "native";
|
||||||
|
}
|
||||||
if(config.contains("libs")) {
|
if(config.contains("libs")) {
|
||||||
for (auto it : config["libs"]) {
|
for (auto it : config["libs"]) {
|
||||||
libs.push_back(it.get<std::string>());
|
libs.push_back(it.get<std::string>());
|
||||||
|
|
|
||||||
|
|
@ -237,10 +237,14 @@ namespace Crafter {
|
||||||
|
|
||||||
|
|
||||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||||
std::string command = std::format("clang++ -stdlib=libc++ --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET=\\\"{}\\\" -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={}", config.target, config.march, config.march, config.standard, editedTarget, editedTarget, (exeDir/(config.target+config.march)).string());
|
std::string stdlib = "-stdlib=libc++";
|
||||||
|
if(config.target == "x86_64-w64-mingw32") {
|
||||||
|
stdlib = "";
|
||||||
|
}
|
||||||
|
std::string command = std::format("clang++ {} --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET=\\\"{}\\\" -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={}", stdlib, config.target, config.march, config.mtune, config.standard, editedTarget, editedTarget, (exeDir/(config.target+config.march)).string());
|
||||||
#endif
|
#endif
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||||
std::string command = std::format("clang++ -nostdinc++ -nostdlib++ -isystem %LIBCXX_DIR%\\include\\c++\\v1 --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET=\"\"{}\"\" -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={}", config.target, config.march, config.march, config.standard, editedTarget, editedTarget, (exeDir/(config.target+config.march)).string());
|
std::string command = std::format("clang++ -nostdinc++ -nostdlib++ -isystem %LIBCXX_DIR%\\include\\c++\\v1 --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET=\"\"{}\"\" -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={}", config.target, config.march, config.mtune, config.standard, editedTarget, editedTarget, (exeDir/(config.target+config.march)).string());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (const auto& entry : fs::recursive_directory_iterator(buildDir)) {
|
for (const auto& entry : fs::recursive_directory_iterator(buildDir)) {
|
||||||
|
|
@ -455,6 +459,10 @@ namespace Crafter {
|
||||||
command += std::format(" -L{}", pcmDir.string());
|
command += std::format(" -L{}", pcmDir.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config.target == "x86_64-w64-mingw32"){
|
||||||
|
command += std::format(" -L{}", binDir.string());
|
||||||
|
}
|
||||||
|
|
||||||
if(buildResult.repack) {
|
if(buildResult.repack) {
|
||||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE) {
|
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE) {
|
||||||
if(config.target == "wasm32-wasi") {
|
if(config.target == "wasm32-wasi") {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ void terminateHandler() {
|
||||||
}
|
}
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
}
|
||||||
#endif
|
#endif//
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ namespace Crafter {
|
||||||
ConfigurationType type;
|
ConfigurationType type;
|
||||||
std::string target;
|
std::string target;
|
||||||
std::string march;
|
std::string march;
|
||||||
|
std::string mtune;
|
||||||
bool debug;
|
bool debug;
|
||||||
std::vector<std::string> libs;
|
std::vector<std::string> libs;
|
||||||
Configuration(std::string&& name);
|
Configuration(std::string&& name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue