From c206fd07db07dc6271185dabac822e10d78b4443 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 2 Oct 2018 00:52:30 +0200 Subject: Add sibs package command Currently in testing phase. Builds a redistributable binary by statically linking libraries (including standard library). --- backend/ninja/Ninja.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'backend') diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 53b1667..943e090 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -316,8 +316,8 @@ namespace backend vector pkgConfigDependencies; for(PackageListDependency *dependency : packageListDependencies) { - Result pkgConfigDependencyValidation = PkgConfig::validatePkgConfigPackageVersionExists(dependency); - if(pkgConfigDependencyValidation.isOk()) + // PkgConfig libraries, even the static ones are most likely not built statically against libgcc/libc++, so we don't use them + if(!config.packaging && PkgConfig::validatePkgConfigPackageVersionExists(dependency)) { pkgConfigDependencies.push_back(dependency); } @@ -662,6 +662,11 @@ namespace backend string generatedZigHeaderDirUtf8 = toUtf8(generatedZigHeadersDir); LibraryType libraryType = getNinjaLibraryType(config.getPackageType()); + // TODO: Instead of statically linking everything, maybe we should build everything as they prefer to be built + // and then copy the files if they are shared libraries to the same directory as the root project executable + // so they can be packaged into an archive that can be distributed? + if(config.packaging && !config.isMainProject()) + libraryType = LibraryType::STATIC; string savePathUtf8 = toUtf8(savePath); string projectPathUtf8 = toUtf8(config.getProjectPath()); @@ -1077,6 +1082,23 @@ namespace backend objectNames.emplace_back(move(objectName)); } + if(config.packaging) + { + switch(config.getCompiler()) + { + case Compiler::GCC: + { + allLinkerFlags += " -static-libgcc -static-libstdc++"; + break; + } + case Compiler::MSVC: + { + // We always statically link using /MT so there is no need to do it here + break; + } + } + } + // TODO: For now zig projects (zig object files) are built with c/c++ compiler, // they should be built with zig if project only contains zig files. // But how to combine object files with zig? build-exe only wants to accept .zig files -- cgit v1.2.3