feat(build): add zig build script

This commit is contained in:
phaneron 2024-06-28 01:51:21 -04:00
parent 2b620905ca
commit cbd169a26a
8 changed files with 131 additions and 3 deletions

View file

@ -47,6 +47,6 @@
#define BC_FILE_SET_ERROR(errorcode) ::Blizzard::File::SetLastError(static_cast<int32_t>(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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

92
build.zig Normal file
View file

@ -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);
}

16
build.zig.zon Normal file
View file

@ -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",
},
} }