From 74fe535c397626cdaf5f51dfe6e32706abc4b468 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 5 Nov 2018 01:32:29 +0100 Subject: Move build files into platform specific location --- README.md | 4 ++-- backend/ninja/Ninja.cpp | 21 ++++++++++++--------- examples/hello_lua_mingw_w64/run.sh | 2 +- install.sh | 5 +++-- src/Conf.cpp | 2 +- src/GlobalLib.cpp | 2 +- src/main.cpp | 12 +++++++++--- 7 files changed, 29 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b80260b..35677d4 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Sibs is inspired by [Cargo](https://github.com/rust-lang/cargo/), you can think Zig support has not been tested properly yet and currently always links to c library. You can run zig tests with `sibs test --file filepath` or `sibs test --all-files`. Currently zig tests are cached because ninja build system is used, which means if source files do not change between runs. -Currently zig files generate header files and include exported functions into sibs-build/generated-headers/zig and the generated headers +Currently zig files generate header files and include exported functions into `sibs-build//generated-headers/zig` and the generated headers are usable from c/c++ by using including: `#include `. If your project contains zig files then it will currently only run on Linux, Windows and MacOS as zig doesn't support more platforms at the moment. @@ -28,7 +28,7 @@ Linux is the primary platform, the platform which master branch is guaranteed to Newest version of sibs builds itself. If you don't already have sibs installed and you are using Windows then you can find prebuilt binary under msvc folder. On MacOS, OpenBSD and Haiku you need to install from source by running install.sh under cmake directory. On Linux you can install from source by running install.sh under cmake directory or if you are using Arch Linux you can use the PKGBUILD under distribute/arch_linux. You can also use prebuild package under distribute/linux_x86_64 if you are running on x86_64 machine. -After you've installed sibs once, you can install new versions by running install.sh (or use `sibs.exe build --release` if you are on windows, and sibs binary will be located under sibs-build/release/sibs.exe). +After you've installed sibs once, you can install new versions by running install.sh (or use `sibs.exe build --release` if you are on windows, and sibs binary will be located under `sibs-build//release/sibs.exe`). For easiest usage of sibs under windows, add msvc subdirectory to PATH environment variable. msvc subdirectory also contains additional libraries and software that is needed for sibs to run with the only missing software being cmake. diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index f8c3ae9..37669da 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -746,7 +746,9 @@ namespace backend if (!createBuildDirResult) return createBuildDirResult; - FileString generatedHeadersDir = config.getProjectPath() + TINYDIR_STRING("/sibs-build/generated-headers"); + FileString generatedHeadersDir = config.getProjectPath() + TINYDIR_STRING("/sibs-build/"); + generatedHeadersDir += toFileString(asString(config.platform)) + TINYDIR_STRING("/"); + generatedHeadersDir += TINYDIR_STRING("generated-headers"); Result createGeneratedHeadersDirResult = createDirectoryRecursive(generatedHeadersDir.c_str()); if (!createGeneratedHeadersDirResult) return createGeneratedHeadersDirResult; @@ -780,7 +782,7 @@ namespace backend string globalIncDir; for(const auto &includeDir : config.getIncludeDirs()) { - string includeDirRelative = "../../"; + string includeDirRelative = "../../../"; includeDirRelative += includeDir; globalIncDir += " "; globalIncDir += getIncludeOptionFlag(config.getCompiler(), includeDirRelative); @@ -1099,7 +1101,7 @@ namespace backend // TODO: Remove --library c if project does not depend on c libraries or project only has .zig files vector commonZigArgs = { - ninja::NinjaArg::createRaw("-isystem ../../"), + ninja::NinjaArg::createRaw("-isystem ../../../"), ninja::NinjaArg::createRaw("--color on"), ninja::NinjaArg::createRaw("$globalIncDirZig") }; @@ -1182,9 +1184,9 @@ namespace backend ninja::NinjaArgValue zigHeaderFileValue = { zigHeaderFile, '"' + toUtf8(zigHeaderFileDir) + '/' + headerName + '"' }; ninja::NinjaBuild *ninjaBuild = nullptr; if(zigTest) - ninjaBuild = testZigRule->build("../../" + sourceFile.filepath, objectName, { zigHeaderFileValue }); + ninjaBuild = testZigRule->build("../../../" + sourceFile.filepath, objectName, { zigHeaderFileValue }); else - ninjaBuild = compileZigRule->build("../../" + sourceFile.filepath, objectName, { zigHeaderFileValue }); + ninjaBuild = compileZigRule->build("../../../" + sourceFile.filepath, objectName, { zigHeaderFileValue }); zigBuilds.push_back(ninjaBuild); objectNames.emplace_back(move(objectName)); @@ -1203,7 +1205,7 @@ namespace backend { objectName += config.getPackageName() + "@exe/" + sourceFile.filepath; objectName += getObjectFileExtension(config.getCompiler()); - compileCRule->build("../../" + sourceFile.filepath, objectName, {}, zigBuilds); + compileCRule->build("../../../" + sourceFile.filepath, objectName, {}, zigBuilds); usesCFiles = true; break; } @@ -1211,7 +1213,7 @@ namespace backend { objectName += config.getPackageName() + "@exe/" + sourceFile.filepath; objectName += getObjectFileExtension(config.getCompiler()); - compileCppRule->build("../../" + sourceFile.filepath, objectName, {}, zigBuilds); + compileCppRule->build("../../../" + sourceFile.filepath, objectName, {}, zigBuilds); usesCppFiles = true; break; } @@ -1776,13 +1778,14 @@ namespace backend if(!ninja.getSourceFiles().empty()) { FileString buildPath = testSourceDirNative; + buildPath += TINYDIR_STRING("/sibs-build/") + toFileString(asString(config.platform)); switch(sibsTestConfig.getOptimizationLevel()) { case OPT_LEV_DEBUG: - buildPath += TINYDIR_STRING("/sibs-build/debug"); + buildPath += TINYDIR_STRING("/debug"); break; case OPT_LEV_RELEASE: - buildPath += TINYDIR_STRING("/sibs-build/release"); + buildPath += TINYDIR_STRING("/release"); break; } diff --git a/examples/hello_lua_mingw_w64/run.sh b/examples/hello_lua_mingw_w64/run.sh index 0f23a37..86c7178 100755 --- a/examples/hello_lua_mingw_w64/run.sh +++ b/examples/hello_lua_mingw_w64/run.sh @@ -5,4 +5,4 @@ set -e script_path=`readlink -f $0` script_dir=`dirname $script_path` cd "$script_dir" -sibs build --platform win64 && ./sibs-build/debug/hello_lua.exe +sibs build --platform win64 && ./sibs-build/win64/debug/hello_lua.exe diff --git a/install.sh b/install.sh index 44cb648..05c6b8f 100755 --- a/install.sh +++ b/install.sh @@ -26,6 +26,7 @@ esac project_dir=`dirname $0` sibs build $project_dir --release -sudo cp "$project_dir/sibs-build/release/sibs" "$bin_dir/sibs" -echo "Copied $project_dir/sibs-build/release/sibs to $bin_dir/sibs" +platform=`sibs platform` +sudo cp "$project_dir/sibs-build/$platform/release/sibs" "$bin_dir/sibs" +echo "Copied $project_dir/sibs-build/$platform/release/sibs to $bin_dir/sibs" echo "Installation successful!" diff --git a/src/Conf.cpp b/src/Conf.cpp index 7ae589e..aade4f7 100644 --- a/src/Conf.cpp +++ b/src/Conf.cpp @@ -527,7 +527,7 @@ namespace sibs exit(6); } - buildPath = projectPath + TINYDIR_STRING("/sibs-build/"); + buildPath = projectPath + TINYDIR_STRING("/sibs-build/") + toFileString(asString(sibsConfig.platform)) + TINYDIR_STRING("/"); if(sibsConfig.packaging) { buildPath += TINYDIR_STRING("package"); diff --git a/src/GlobalLib.cpp b/src/GlobalLib.cpp index 5c0e16d..1a795bf 100644 --- a/src/GlobalLib.cpp +++ b/src/GlobalLib.cpp @@ -219,7 +219,7 @@ namespace sibs return Result::Err(errMsg); } - FileString buildPath = packageDir + TINYDIR_STRING("/sibs-build/"); + FileString buildPath = packageDir + TINYDIR_STRING("/sibs-build/") + toFileString(asString(sibsConfig.platform)) + TINYDIR_STRING("/"); switch (sibsConfig.getOptimizationLevel()) { case OPT_LEV_DEBUG: diff --git a/src/main.cpp b/src/main.cpp index c8e9b27..c954634 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,6 +126,7 @@ static void usage() printf(" init\t\tInitialize project in an existing directory\n"); printf(" test\t\tBuild and run tests for a sibs project\n"); printf(" package\t\tCreate a redistributable package from a sibs project. Note: Redistributable packages can't use system packages to build\n"); + printf(" platform\t\tPrint name of platform (to stdout) and exit\n"); exit(1); } @@ -1153,7 +1154,7 @@ static int packageProject(int argc, const _tinydir_char_t **argv) { case PackagingType::STATIC: { - string packagePath = toUtf8(projectPath + TINYDIR_STRING("/sibs-build/package")); + string packagePath = toUtf8(projectPath + TINYDIR_STRING("/sibs-build/") + toFileString(asString(sibsConfig.platform)) + TINYDIR_STRING("/package")); printf("Project %s was successfully packaged and can be found at %s\n", sibsConfig.getPackageName().c_str(), packagePath.c_str()); break; } @@ -1171,8 +1172,8 @@ static int packageProject(int argc, const _tinydir_char_t **argv) break; } - FileString packagePath = projectPath + TINYDIR_STRING("/sibs-build/package"); - FileString executablePath = projectPath + TINYDIR_STRING("/sibs-build/release/") + toFileString(sibsConfig.getPackageName()); + FileString packagePath = projectPath + TINYDIR_STRING("/sibs-build/") + toFileString(asString(sibsConfig.platform)) + TINYDIR_STRING("/package"); + FileString executablePath = projectPath + TINYDIR_STRING("/sibs-build/") + toFileString(asString(sibsConfig.platform)) + TINYDIR_STRING("/release/")+ toFileString(sibsConfig.getPackageName()); printf("Creating a package from project and dependencies...\n"); // args: executable_path program_version destination_path <--bundle|--bundle-install> FileString cmd = TINYDIR_STRING("python3 \"") + @@ -1428,6 +1429,11 @@ int wmain(int argc, const _tinydir_char_t **argv) { return packageProject(subCommandArgCount, subCommandArgPtr); } + else if(_tinydir_strcmp(arg, TINYDIR_STRING("platform")) == 0) + { + printf("%s\n", asString(SYSTEM_PLATFORM)); + return 0; + } else { ferr << "Expected command to be either 'build', 'new' or 'test', was: " << arg << endl << endl; -- cgit v1.2.3