diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..066939e --- /dev/null +++ b/build.zig @@ -0,0 +1,158 @@ +const std = @import("std"); +const system = @import("system"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const t = target.result; + + // Squall library + const storm = b.addStaticLibrary(.{ + .name = "storm", + .target = target, + .optimize = optimize + }); + // Link C++ standard library + storm.linkLibCpp(); + // Add system detection defines + system.add_defines(storm); + + // Get dependencies + const mem = b.dependency("mem", .{}); + const bc = b.dependency("bc", .{}); + // Publicly link mem + storm.addIncludePath(mem.path(".")); + storm.linkLibrary(mem.artifact("mem")); + // Link bc + storm.addIncludePath(bc.path(".")); + storm.linkLibrary(bc.artifact("bc")); + + // Include squall project directory + storm.addIncludePath(b.path(".")); + + const storm_compiler_flags = [_][]const u8 { + "-std=c++11", + "-Wno-invalid-offsetof" + }; + + const storm_sources = [_][]const u8 { + "storm/big/BigBuffer.cpp", + "storm/big/BigData.cpp", + "storm/big/BigStack.cpp", + "storm/big/Ops.cpp", + + "storm/hash/HashKey.cpp", + + "storm/queue/CSBasePriority.cpp", + "storm/queue/CSBasePriorityQueue.cpp", + + "storm/string/bjhash.cpp", + + "storm/thread/CCritSect.cpp", + "storm/thread/CSRWLock.cpp", + "storm/thread/S_Thread.cpp", + "storm/thread/SCritSect.cpp", + "storm/thread/SEvent.cpp", + "storm/thread/SSemaphore.cpp", + "storm/thread/SSyncObject.cpp", + "storm/thread/SThread.cpp", + + "storm/Atomic.cpp", + "storm/Big.cpp", + "storm/Command.cpp", + "storm/Crypto.cpp", + "storm/Error.cpp", + "storm/Log.cpp", + "storm/Region.cpp", + "storm/String.cpp", + "storm/Thread.cpp", + "storm/Unicode.cpp" + }; + + const storm_windows_sources = [_][]const u8{ + "storm/error/win/Display.cpp", + "storm/error/win/Error.cpp", + "storm/thread/win/S_Thread.cpp", + "storm/thread/win/SRWLock.cpp", + "storm/thread/win/Thread.cpp" + }; + + const storm_macos_sources = [_][]const u8{ + "storm/thread/mac/S_Thread.mm", + "storm/thread/mac/SThreadRunner.mm", + "storm/thread/mac/Thread.mm" + }; + + const storm_linux_sources = [_][]const u8{ + "storm/thread/linux/S_Thread.cpp", + "storm/thread/linux/Thread.cpp" + }; + + storm.addCSourceFiles(.{ + .files = &storm_sources, + .flags = &storm_compiler_flags + }); + + switch (t.os.tag) { + .windows => { + storm.addCSourceFiles(.{ + .files = &storm_windows_sources, + .flags = &storm_compiler_flags + }); + }, + .macos => { + storm.addCSourceFiles(.{ + .files = &storm_macos_sources, + .flags = &storm_compiler_flags + }); + }, + else => { + storm.addCSourceFiles(.{ + .files = &storm_linux_sources, + .flags = &storm_compiler_flags + }); + } + } + + // StormTest executable + const storm_test_exe = b.addExecutable(.{ + .name = "StormTest", + .target = target, + .optimize = optimize + }); + // Link C++ standard library + storm_test_exe.linkLibCpp(); + // Add system detection defines + system.add_defines(storm_test_exe); + + storm_test_exe.linkLibrary(storm); + + storm_test_exe.addIncludePath(mem.path(".")); + storm_test_exe.addIncludePath(b.path(".")); + + storm_test_exe.addCSourceFiles(.{ + .files = &.{ + "test/big/Ops.cpp", + "test/Array.cpp", + "test/Atomic.cpp", + "test/Big.cpp", + "test/Crypto.cpp", + "test/Hash.cpp", + "test/List.cpp", + "test/Log.cpp", + "test/Memory.cpp", + "test/Queue.cpp", + "test/Region.cpp", + "test/String.cpp", + "test/Test.cpp", + "test/Thread.cpp", + "test/Unicode.cpp", + }, + + .flags = &storm_compiler_flags + }); + + b.installArtifact(storm_test_exe); + b.installArtifact(storm); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..049aaad --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,19 @@ +.{ + .name = "squall", + .version = "1.0.0", + .paths = .{ "LICENSE", "README.md", "build.zig", "build.zig.zon" }, + .dependencies = .{ + .system = .{ + .url = "https://github.com/thunderbrewhq/system/archive/refs/heads/master.zip", + .hash = "1220d6a6e4e2f836c1c22eb128e6c74c773ea191bfbaac02601dcb5238c2b0874182", + }, + .bc = .{ + .url = "https://github.com/thunderbrewhq/bc/archive/refs/heads/master.zip", + .hash = "12202ac82de86543714d79a8c055b7357fd8c4c6ba3bf73ec4f1cdd5771885c728ad", + }, + .mem = .{ + .url = "https://github.com/thunderbrewhq/mem/archive/refs/heads/master.zip", + .hash = "122037f90f957dec643fe16e0092c8b971b7dd0a0f8096d00fa134e254053fbced87", + }, + }, +} diff --git a/storm/Memory.hpp b/storm/Memory.hpp index 2e2ee6e..07c8186 100644 --- a/storm/Memory.hpp +++ b/storm/Memory.hpp @@ -1,6 +1,15 @@ #ifndef STORM_MEMORY_HPP #define STORM_MEMORY_HPP -#include +#include +#include + +void* SMemAlloc(size_t bytes, const char* filename, int32_t linenumber, uint32_t flags); + +void SMemFree(void* ptr); + +void SMemFree(void* ptr, const char* filename, int32_t linenumber, uint32_t flags); + +void* SMemReAlloc(void* ptr, size_t bytes, const char* filename, int32_t linenumber, uint32_t flags); #endif