From cbd169a26afcca52aef77a635c7da68b58c67194 Mon Sep 17 00:00:00 2001 From: superp00t Date: Fri, 28 Jun 2024 01:51:21 -0400 Subject: [PATCH] feat(build): add zig build script --- bc/file/Defines.hpp | 2 +- bc/system/file/posix/Stacked.cpp | 4 ++ bc/system/file/posix/System_File.cpp | 4 ++ bc/system/file/win/Stacked.cpp | 8 ++- bc/system/file/win/System_File.cpp | 4 ++ bc/system/file/win/WinFile.cpp | 4 ++ build.zig | 92 ++++++++++++++++++++++++++++ build.zig.zon | 16 +++++ 8 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 build.zig create mode 100644 build.zig.zon diff --git a/bc/file/Defines.hpp b/bc/file/Defines.hpp index 715f07d..ca79690 100644 --- a/bc/file/Defines.hpp +++ b/bc/file/Defines.hpp @@ -47,6 +47,6 @@ #define BC_FILE_SET_ERROR(errorcode) ::Blizzard::File::SetLastError(static_cast(errorcode)) #define BC_FILE_SET_ERROR_MSG(errorcode, pfmt, ...) \ ::Blizzard::File::SetLastError(errorcode); \ - ::Blizzard::File::AddToLastErrorStack(errorcode, ::Blizzard::String::QuickFormat<1024>(pfmt, __VA_ARGS__).Str(), 1) + ::Blizzard::File::AddToLastErrorStack(errorcode, ::Blizzard::String::QuickFormat<1024>(pfmt, ##__VA_ARGS__).Str(), 1) #endif diff --git a/bc/system/file/posix/Stacked.cpp b/bc/system/file/posix/Stacked.cpp index 799376d..9fe330c 100644 --- a/bc/system/file/posix/Stacked.cpp +++ b/bc/system/file/posix/Stacked.cpp @@ -1,3 +1,5 @@ +#if defined(WHOA_SYSTEM_LINUX) || defined(WHOA_SYSTEM_MAC) + #include "bc/system/file/Stacked.hpp" #include "bc/file/Path.hpp" #include "bc/Debug.hpp" @@ -635,3 +637,5 @@ bool Delete(FileParms* parms) { } // namespace Stacked } // namespace System_File } // namespace Blizzard + +#endif diff --git a/bc/system/file/posix/System_File.cpp b/bc/system/file/posix/System_File.cpp index 4629d8c..ed045fb 100644 --- a/bc/system/file/posix/System_File.cpp +++ b/bc/system/file/posix/System_File.cpp @@ -1,3 +1,5 @@ +#if defined(WHOA_SYSTEM_LINUX) || defined(WHOA_SYSTEM_MAC) + #include "bc/system/file/System_File.hpp" #include "bc/system/file/Stacked.hpp" #include "bc/file/Path.hpp" @@ -518,3 +520,5 @@ bool Shutdown(File::Filesystem* fs, Stacked::FileParms* parms) { } // namespace System_File } // namespace Blizzard + +#endif diff --git a/bc/system/file/win/Stacked.cpp b/bc/system/file/win/Stacked.cpp index 4dbed56..f66a58a 100644 --- a/bc/system/file/win/Stacked.cpp +++ b/bc/system/file/win/Stacked.cpp @@ -1,3 +1,5 @@ +#if defined(WHOA_SYSTEM_WIN) + #include "bc/file/Defines.hpp" #include "bc/file/File.hpp" #include "bc/file/Path.hpp" @@ -527,8 +529,8 @@ bool Open(FileParms* parms) { HANDLE handle = WinFile::Open(pathNative.Str(), flags, nocache); if (handle == INVALID_HANDLE_VALUE) { - DWORD err = 0; - if (err = ::GetLastError()) { + DWORD err = ::GetLastError(); + if (err) { BC_FILE_SET_ERROR_MSG(BC_FILE_ERROR_GENERIC_FAILURE, "Win32 Open %s", parms->filename); } return false; @@ -815,3 +817,5 @@ bool WriteP(FileParms* parms) { /******************************** * End of Win32 Stacked functions * *********************************/ + +#endif diff --git a/bc/system/file/win/System_File.cpp b/bc/system/file/win/System_File.cpp index ff722b8..57515f1 100644 --- a/bc/system/file/win/System_File.cpp +++ b/bc/system/file/win/System_File.cpp @@ -1,3 +1,5 @@ +#if defined(WHOA_SYSTEM_WIN) + #include "bc/system/file/System_File.hpp" #include "bc/system/file/Stacked.hpp" #include "bc/file/File.hpp" @@ -138,3 +140,5 @@ bool Shutdown(File::Filesystem* fs, Stacked::FileParms* parms) { } // namespace System_File } // namespace Blizzard + +#endif diff --git a/bc/system/file/win/WinFile.cpp b/bc/system/file/win/WinFile.cpp index 2a506b2..481fcea 100644 --- a/bc/system/file/win/WinFile.cpp +++ b/bc/system/file/win/WinFile.cpp @@ -1,3 +1,5 @@ +#if defined(WHOA_SYSTEM_WIN) + #include "bc/file/Defines.hpp" #include "bc/system/file/win/WinFile.hpp" @@ -186,3 +188,5 @@ HANDLE Open(const char* systemPath, uint32_t flags, bool nocache) { } // namespace WinFile } // namespace Blizzard + +#endif diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..cb0051d --- /dev/null +++ b/build.zig @@ -0,0 +1,92 @@ +const std = @import("std"); +const system = @import("system"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + // BlizzardCore library + const bc = b.addStaticLibrary(.{ + .name = "bc", + .target = target, + .optimize = optimize + }); + // Link C++ standard library + bc.linkLibCpp(); + // Add system detection defines + system.add_defines(bc); + + // Publicly link mem + const mem = b.dependency("mem", .{}); + bc.linkLibrary(mem.artifact("mem")); + + bc.addIncludePath(b.path(".")); + bc.addIncludePath(mem.path(".")); + + bc.addCSourceFiles(.{ + .files = &.{ + "bc/file/path/Posix.cpp", + "bc/file/File.cpp", + "bc/file/Filesystem.cpp", + + "bc/lock/Atomic.cpp", + + "bc/os/CommandLine.cpp", + "bc/os/File.cpp", + "bc/os/Path.cpp", + + "bc/system/file/posix/Stacked.cpp", + "bc/system/file/posix/System_File.cpp", + "bc/system/file/win/Stacked.cpp", + "bc/system/file/win/System_File.cpp", + "bc/system/file/Stacked.cpp", + "bc/system/System_Debug.cpp", + "bc/system/System_Lock.cpp", + "bc/system/System_Thread.cpp", + "bc/system/System_Time.cpp", + + "bc/time/Time.cpp", + + "bc/Debug.cpp", + "bc/Lock.cpp", + "bc/Memory.cpp", + "bc/Process.cpp", + "bc/String.cpp", + "bc/Thread.cpp", + }, + + .flags = &.{"-std=c++11"} + }); + + // BcTest executable + const bc_test_exe = b.addExecutable(.{ + .name = "BcTest", + .target = target, + .optimize = optimize + }); + // Link C++ standard library + bc_test_exe.linkLibCpp(); + // Add system detection defines + system.add_defines(bc_test_exe); + + bc_test_exe.linkLibrary(bc); + + bc_test_exe.addIncludePath(b.path(".")); + + bc_test_exe.addCSourceFiles(.{ + .files = &.{ + "test/Lock.cpp", + "test/Memory.cpp", + "test/Process.cpp", + "test/String.cpp", + "test/Test.cpp", + "test/Thread.cpp", + "test/Time.cpp", + }, + + .flags = &.{"-std=c++11"} + }); + + b.installArtifact(bc_test_exe); + b.installArtifact(bc); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..5fae104 --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,16 @@ +.{ .name = "bc", .version = "1.0.0", .paths = .{ + "LICENSE", + "README.md", + "build.zig", + "build.zig.zon", + "bc", +}, .dependencies = .{ + .system = .{ + .url = "https://github.com/thunderbrewhq/system/archive/refs/heads/master.zip", + .hash = "1220d6a6e4e2f836c1c22eb128e6c74c773ea191bfbaac02601dcb5238c2b0874182", + }, + .mem = .{ + .url = "https://github.com/thunderbrewhq/mem/archive/refs/heads/master.zip", + .hash = "122037f90f957dec643fe16e0092c8b971b7dd0a0f8096d00fa134e254053fbced87", + }, +} }