aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-13 00:09:22 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:39:33 +0200
commit5e79e361c97e88b4a5912990eda0f1fb0d4a6dbd (patch)
treeb4ea98e404aec68a8eae7f9d64fa24bb4b29effa /src
parent7c24c5d0de4d3584d6d2f9f3c26b4d757b0a0df2 (diff)
Add posix as a platform, remove zig from compile_commands.json
Diffstat (limited to 'src')
-rw-r--r--src/Platform.cpp50
-rw-r--r--src/main.cpp7
2 files changed, 27 insertions, 30 deletions
diff --git a/src/Platform.cpp b/src/Platform.cpp
index dd81667..b011d93 100644
--- a/src/Platform.cpp
+++ b/src/Platform.cpp
@@ -3,27 +3,29 @@
namespace sibs
{
- static int countSetBits(u32 value)
+ static std::unordered_map<Platform, const char*> platformNames;
+ static bool platformNamesSet = false;
+ static int countSetBits(u64 value)
{
int count = 0;
while(value)
{
- count += (value & 1U);
- value >>= 1U;
+ count += (value & 1ULL);
+ value >>= 1ULL;
}
return count;
}
// Returns -1 if no bit is set
- static int getLeastSignificantBitSetPosition(u32 value)
+ static u64 getLeastSignificantBitSetPosition(u64 value)
{
- for(u32 i = 0; i < sizeof(u32); ++i)
+ for(u64 i = 0; i < sizeof(u64); ++i)
{
- if(value & 1U)
+ if(value & 1ULL)
return i;
- value >>= 1U;
+ value >>= 1ULL;
}
- return -1;
+ return -1ULL;
}
bool containsPlatform(const std::vector<Platform> &platforms, Platform platform)
@@ -38,27 +40,19 @@ namespace sibs
const char* asString(Platform platform)
{
- switch (platform)
+ if(!platformNamesSet)
{
- case PLATFORM_ANY: return "any";
- case PLATFORM_LINUX: return "linux";
- case PLATFORM_LINUX32: return "linux32";
- case PLATFORM_LINUX64: return "linux64";
- case PLATFORM_WIN: return "win";
- case PLATFORM_WIN32: return "win32";
- case PLATFORM_WIN64: return "win64";
- case PLATFORM_MACOS: return "macos";
- case PLATFORM_MACOS32: return "macos32";
- case PLATFORM_MACOS64: return "macos64";
- case PLATFORM_BSD: return "bsd";
- case PLATFORM_OPENBSD: return "openbsd";
- case PLATFORM_OPENBSD32: return "openbsd32";
- case PLATFORM_OPENBSD64: return "openbsd64";
- case PLATFORM_HAIKU: return "haiku";
- case PLATFORM_HAIKU32: return "haiku32";
- case PLATFORM_HAIKU64: return "haiku64";
- default: assert(false); return nullptr;
+ platformNamesSet = true;
+ for(auto &it : PLATFORM_BY_NAME)
+ {
+ platformNames[it.second] = it.first.data;
+ }
}
+
+ auto it = platformNames.find(platform);
+ if(it != platformNames.end())
+ return it->second;
+ return nullptr;
}
Platform getPlatformByName(StringView name)
@@ -83,6 +77,6 @@ namespace sibs
{
if(platform == PLATFORM_INVALID || platform == PLATFORM_ANY)
return PLATFORM_INVALID;
- return (Platform)(1U << (u32)getLeastSignificantBitSetPosition(platform));
+ return (Platform)(1ULL << (u64)getLeastSignificantBitSetPosition(platform));
}
}
diff --git a/src/main.cpp b/src/main.cpp
index b3a8f40..952497a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -93,6 +93,9 @@ using namespace std::chrono;
// Also compile_commands.json shouldn't update if no files have changed. This is easier to do when ninja is replaced so we can track changes
// in source/header files.
+// TODO: Create a script that downloads every library in the package list (packages.json) and build each project for every new release of sibs
+// to verify we don't break anything.
+
#if OS_FAMILY == OS_FAMILY_POSIX
#define fout std::cout
#define ferr std::cerr
@@ -968,7 +971,7 @@ static int initProject(int argc, const _tinydir_char_t **argv)
else if(_tinydir_strcmp(lang, TINYDIR_STRING("zig")) == 0 && projectTypeConf == "executable")
{
auto mainFilePath = projectPath + TINYDIR_STRING("/src/main.zig");
- Result<bool> fileOverwriteResult = fileWrite(mainFilePath.c_str(), "const warn = @import(\"std\").debug.warn;\n\npub fn main() void\n{\n warn(\"Hello, world!\\n\");\n}\n");
+ Result<bool> fileOverwriteResult = fileWrite(mainFilePath.c_str(), "const warn = @import(\"std\").debug.warn;\n\npub fn main() void {\n warn(\"Hello, world!\\n\");\n}\n");
if(!fileOverwriteResult)
fout << "Warning: Failed to create project file: " << toFileString(fileOverwriteResult.getErrMsg()) << endl;
}
@@ -1366,7 +1369,7 @@ static int newProject(int argc, const _tinydir_char_t **argv)
else if(_tinydir_strcmp(lang, TINYDIR_STRING("zig")) == 0 && projectTypeConf == "executable")
{
auto mainFilePath = projectPath + TINYDIR_STRING("/src/main.zig");
- Result<bool> fileOverwriteResult = fileWrite(mainFilePath.c_str(), "const warn = @import(\"std\").debug.warn;\n\npub fn main() void\n{\n warn(\"Hello, world!\\n\");\n}\n");
+ Result<bool> fileOverwriteResult = fileWrite(mainFilePath.c_str(), "const warn = @import(\"std\").debug.warn;\n\npub fn main() void {\n warn(\"Hello, world!\\n\");\n}\n");
if(!fileOverwriteResult)
{
ferr << " Failed to create project file: " << toFileString(fileOverwriteResult.getErrMsg()) << endl;