This commit is contained in:
parent
714e82daa9
commit
c4686ae1cc
5 changed files with 159 additions and 42 deletions
|
|
@ -146,13 +146,23 @@ namespace Crafter {
|
|||
void AddLibsRecursive(std::string& libsString, std::unordered_set<std::string> depLibSet, Configuration& depConfig) {
|
||||
for(const std::string& lib2 : depConfig.libs) {
|
||||
if (depLibSet.insert(lib2).second) {
|
||||
libsString+=std::format(" -l{}", lib2);
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
libsString += std::format(" -l{}", lib2);
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
libsString+=std::format(" {}.lib", lib2);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
for(const std::tuple<std::shared_ptr<Project>, Configuration&>& dep2 : depConfig.dependencies) {
|
||||
std::string outputLib = std::get<0>(dep2)->name+std::get<1>(dep2).name;
|
||||
if (depLibSet.insert(outputLib).second) {
|
||||
libsString+=std::format(" -l{}", outputLib);
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
libsString += std::format(" -l{}", outputLib);
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
libsString+=std::format(" {}.lib", outputLib);
|
||||
#endif
|
||||
}
|
||||
AddLibsRecursive(libsString, depLibSet, std::get<1>(dep2));
|
||||
}
|
||||
|
|
@ -230,39 +240,82 @@ 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++ --target={} -march={} -mtune={} -std={} -D CRAFTER_BUILD_CONFIGURATION_TARGET_{} -fprebuilt-module-path={}", config.target, config.march, config.march, config.standard, editedTarget, (exeDir/config.target).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={}", clangClDir, 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) {
|
||||
if(define.value.empty()) {
|
||||
#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
|
||||
|
||||
|
||||
for(const Define& define : config.defines) {
|
||||
|
||||
|
||||
fs::path pcmDir;
|
||||
|
||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_SHARED_LIBRARY) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
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";
|
||||
#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;
|
||||
}
|
||||
|
||||
command += std::format(" -fprebuilt-module-path={}", pcmDir.string());
|
||||
|
||||
if(config.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 {
|
||||
#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) {
|
||||
|
|
@ -272,7 +325,12 @@ namespace Crafter {
|
|||
std::unordered_set<std::string> depLibSet;
|
||||
std::vector<std::thread> depThreads = std::vector<std::thread>(config.dependencies.size());
|
||||
std::mutex libMutex;
|
||||
std::string files;
|
||||
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu)
|
||||
std::string libsString;
|
||||
#endif
|
||||
|
||||
std::vector<std::string> resultsDep(config.dependencies.size());
|
||||
|
||||
for(std::uint_fast32_t i = 0; i < depThreads.size(); i++) {
|
||||
|
|
@ -289,11 +347,18 @@ namespace Crafter {
|
|||
}
|
||||
resultsDep[i] = depResult.errors;
|
||||
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
if (depLibSet.insert(outputLib).second) {
|
||||
libsString+=std::format(" -l{}", outputLib);
|
||||
}
|
||||
|
||||
AddLibsRecursive(libsString, depLibSet, std::get<1>(config.dependencies[i]));
|
||||
#endif
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
if (depLibSet.insert(outputLib).second) {
|
||||
files+=std::format(" {}.lib", outputLib);
|
||||
}
|
||||
AddLibsRecursive(files, depLibSet, std::get<1>(config.dependencies[i]));
|
||||
#endif
|
||||
libMutex.unlock();
|
||||
});
|
||||
}
|
||||
|
|
@ -311,13 +376,15 @@ namespace Crafter {
|
|||
return buildResult;
|
||||
}
|
||||
|
||||
std::string files;
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -373,6 +440,7 @@ namespace Crafter {
|
|||
|
||||
command += libsString;
|
||||
|
||||
#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);
|
||||
|
|
@ -381,6 +449,7 @@ namespace Crafter {
|
|||
for(const std::string& dir : config.libDirs) {
|
||||
command += std::format(" -L{}", dir);
|
||||
}
|
||||
#endif
|
||||
|
||||
fileThread.join();
|
||||
|
||||
|
|
@ -389,15 +458,34 @@ namespace Crafter {
|
|||
}
|
||||
|
||||
if(buildResult.repack) {
|
||||
if(config.type == CRAFTER_CONFIGURATION_TYPE_EXECUTABLE){
|
||||
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()));
|
||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY){
|
||||
#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 = RunCommand(std::format("link {} {} .\\build\\std.o msvcrt.lib kernel32.lib user32.lib /OUT:{}.exe", lib, files, (binDir/outputName).string()));
|
||||
#endif
|
||||
} else if(config.type == CRAFTER_CONFIGURATION_TYPE_LIBRARY) {
|
||||
#ifdef CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_linux_gnu
|
||||
RunCommandIgnore(std::format("ar r {}.a {}", (binDir/fs::path(std::string("lib")+outputName)).string(), files));
|
||||
#endif
|
||||
|
||||
#if defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_pc_windows_msvc) || defined(CRAFTER_BUILD_CONFIGURATION_TARGET_x86_64_w64_mingw32)
|
||||
RunCommandIgnore(std::format("lib {} /OUT:{}.lib", 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