This commit is contained in:
parent
9bd12660eb
commit
d98738fe68
4 changed files with 88 additions and 146 deletions
|
|
@ -245,32 +245,18 @@ namespace Crafter {
|
|||
std::string editedTarget = config.target;
|
||||
std::replace(editedTarget.begin(), editedTarget.end(), '-', '_');
|
||||
|
||||
#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_{} -fprebuilt-module-path={} -I{} -I{}", config.target, config.march, config.march, config.standard, editedTarget, (exeDir/config.target).string(), buildDir.string(), (exeDir/"cloneCache").string());
|
||||
#endif
|
||||
#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-cl.exe /EHsc --target={} -march={} -mtune={} /std:{} /D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={} -Wno-unused-command-line-argument", config.target, config.march, config.march, config.standard, editedTarget, (exeDir/config.target).string());
|
||||
#endif
|
||||
|
||||
if(config.target == "wasm32-wasi") {
|
||||
command += std::format(" --sysroot={} -fno-exceptions -fno-c++-static-destructors", (exeDir/"wasi-sysroot-28.0").string());
|
||||
}
|
||||
|
||||
for(const Define& define : config.defines) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
if(define.value.empty()) {
|
||||
command += std::format(" -D {}", define.name);
|
||||
} else {
|
||||
command += std::format(" -D {}={}", define.name, define.value);
|
||||
}
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
if(define.value.empty()) {
|
||||
command += std::format(" /D {}", define.name);
|
||||
} else {
|
||||
command += std::format(" /D {}={}", define.name, define.value);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
fs::path pcmDir;
|
||||
|
|
@ -280,24 +266,14 @@ namespace Crafter {
|
|||
command += " -fPIC -D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
command += " /D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_SHARED_LIBRARY";
|
||||
#endif
|
||||
pcmDir = binDir;
|
||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_LIBRARY";
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
command += " /D CRAFTER_BUILD_CONFIGURATION_TYPE_LIBRARY";
|
||||
#endif
|
||||
pcmDir = binDir;
|
||||
} else {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
command += " -D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE";
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
command += " /D CRAFTER_BUILD_CONFIGURATION_TYPE_EXECUTABLE";
|
||||
#endif
|
||||
pcmDir = buildDir;
|
||||
}
|
||||
|
||||
|
|
@ -307,20 +283,10 @@ namespace Crafter {
|
|||
|
||||
if(config.debug) {
|
||||
cmakeBuildType = "Debug";
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
command += " -g -D CRAFTER_BUILD_CONFIGURATION_DEBUG";
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
command += " -g /MDd /D CRAFTER_BUILD_CONFIGURATION_DEBUG";
|
||||
#endif
|
||||
} else {
|
||||
cmakeBuildType = "Release";
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
command += " -O3";
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
command += " /Ot";
|
||||
#endif
|
||||
}
|
||||
|
||||
for(const std::string& dir : config.includeDirs) {
|
||||
|
|
@ -380,12 +346,7 @@ namespace Crafter {
|
|||
for(const fs::path& cFile: config.c_files) {
|
||||
files+=std::format(" {}_source.o ",(buildDir/cFile.filename()).string());
|
||||
if(!fs::exists((buildDir/cFile.filename()).string()+"_source.o") || fs::last_write_time(cFile.string()+".c") > fs::last_write_time((buildDir/cFile.filename()).string()+"_source.o")) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
threads.emplace_back(&RunClang, std::format("clang {}.c -c -o {}_source.o", cFile.string(), (buildDir/cFile.filename()).string()));
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
threads.emplace_back(&RunClang, std::format("{} {}.c -c -o {}_source.o", command, cFile.string(), (buildDir/cFile.filename()).string()));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -396,11 +357,12 @@ namespace Crafter {
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> resultInterfaces(config.interfaces.size());
|
||||
std::vector<std::string> resultInterfaces(config.interfaces.size()*2);
|
||||
|
||||
for(uint_fast32_t i = 0; i < config.interfaces.size(); i++) {
|
||||
if(config.interfaces[i]->Check(pcmDir)) {
|
||||
threads.emplace_back(&Module::Compile, config.interfaces[i].get(), command, pcmDir, buildDir, std::ref(resultInterfaces[i]));
|
||||
threads.emplace_back(&Module::CompileSource, config.interfaces[i].get(), command, pcmDir, buildDir, std::ref(resultInterfaces[config.interfaces.size()+i]));
|
||||
buildResult.repack = true;
|
||||
}
|
||||
files += std::format(" {}/{}.o", buildDir.string(), config.interfaces[i]->path.filename().string());
|
||||
|
|
@ -441,15 +403,9 @@ namespace Crafter {
|
|||
command += std::format(" -L{}", buildDir.string());
|
||||
|
||||
if(config.type != CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
command += libsString;
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
files += libsString;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
for(const std::string& lib : config.libs) {
|
||||
depLibSet.insert(lib);
|
||||
command += std::format(" -l{}", lib);
|
||||
|
|
@ -458,7 +414,6 @@ namespace Crafter {
|
|||
for(const std::string& dir : config.libDirs) {
|
||||
command += std::format(" -L{}", dir);
|
||||
}
|
||||
#endif
|
||||
|
||||
fileThread.join();
|
||||
|
||||
|
|
@ -468,21 +423,10 @@ namespace Crafter {
|
|||
|
||||
if(buildResult.repack) {
|
||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
if(config.target == "wasm32-wasi") {
|
||||
outputName += ".wasm";
|
||||
}
|
||||
buildResult.errors = RunClang(std::format("{}{} -o {} -fuse-ld=lld ", command, files, (binDir/outputName).string()));
|
||||
#endif
|
||||
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
std::string libPath = "";
|
||||
for(const std::string_view lib : config.libDirs) {
|
||||
libPath += std::format(" /LIBPATH:{}", lib);
|
||||
}
|
||||
|
||||
buildResult.errors = RunClang(std::format("{} && link.exe /NODEFAULTLIB:libcmt.lib {} {} {}\\{}\\std.obj msvcrt.lib kernel32.lib user32.lib /OUT:{}.exe", vsVars, libPath, files, exeDir.string(), config.target, (binDir/outputName).string()));
|
||||
#endif
|
||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
RunClang(std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files));
|
||||
|
|
@ -492,9 +436,7 @@ namespace Crafter {
|
|||
RunClang(std::format("{} && lib.exe {} /OUT:{}.lib", vsVars, files, (binDir/fs::path(outputName)).string()));
|
||||
#endif
|
||||
} else {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
buildResult.errors = RunClang(std::format("{}{} -shared -o {}.so -Wl,-rpath,'$ORIGIN' -fuse-ld=lld", command, files, (binDir/(std::string("lib")+outputName)).string()));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue