From 11a0319c305491532321bbe74d472b85d131e3ce Mon Sep 17 00:00:00 2001 From: valerie lirz Date: Sun, 25 May 2025 14:40:40 -0700 Subject: [PATCH] tier1, tier2, vpklib, filesystem_stdio all build --- build.zig | 187 +++++++++----------- mods.zig | 277 ++++++++++++++++++++++++++++++ progress.md | 4 +- project.zig | 190 ++++++++++++-------- public/datamodel/dmattributevar.h | 160 ++++++++--------- 5 files changed, 557 insertions(+), 261 deletions(-) create mode 100644 mods.zig diff --git a/build.zig b/build.zig index b3300e61..453ff6c0 100644 --- a/build.zig +++ b/build.zig @@ -1,117 +1,90 @@ const std = @import("std"); const proj = @import("project.zig"); +const mods = @import("mods.zig"); + +const Compile = *std.Build.Step.Compile; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - - const tier0 = tier0: { - const cpp = [_]proj.PlatformSrc{ - proj.PlatformSrc{ .data = &[_][]const u8{ - "assert_dialog.cpp", - "commandline.cpp", - "cpu.cpp", - "cpumonitoring.cpp", - "cpu_usage.cpp", - "dbg.cpp", - "dynfunction.cpp", - "fasttimer.cpp", - "mem.cpp", - "mem_helpers.cpp", - "memdbg.cpp", - "memstd.cpp", - "memvalidate.cpp", - "minidump.cpp", - "pch_tier0.cpp", - "progressbar.cpp", - "security.cpp", - "systeminformation.cpp", - "stacktools.cpp", - "threadtools.cpp", - "tier0_strtools.cpp", - "tslist.cpp", - "vprof.cpp", - "../tier1/pathmatch.cpp", - } }, - proj.PlatformSrc{ - .data = &[_][]const u8{ - "PMELib.cpp", - "thread.cpp", - "cpu_posix.cpp", - "platform_posix.cpp", - "pme_posix.cpp", - "vcrmode_posix.cpp", - }, - .spec = .{ .os = .{ - .posix = null, - } }, - }, - proj.PlatformSrc{ - .data = &[_][]const u8{ - "PMELib.cpp", - "thread.cpp", - "assert_dialog.rc", - // "etwprof.cpp", - "platform.cpp", - "pme.cpp", - "vcrmode.cpp", - "win32consoleio.cpp", - }, - .spec = .{ - .os = .{ .windows = @as(void, undefined) }, - }, - }, - }; - - const asm_att = [_]proj.PlatformSrc{proj.PlatformSrc{ - .data = &[_][]const u8{"InterlockedCompareExchange128.S"}, - .spec = .{ - .arch = .{ .amd64 = @as(void, undefined) }, - }, - }}; - - const macros = [_]proj.PlatformMacros{proj.PlatformMacros{ - .data = &[_]proj.Macro{ - proj.Macro{ .name = "TIER0_DLL_EXPORT" }, - }, - }}; - - break :tier0 proj.make_module(b, target, optimize, "tier0", .{ .use_sdl = true, .use_gl = true, .use_togles = true }, .shared, b.path("tier0"), &cpp, null, &asm_att, null, ¯os, null, null); + const common = proj.ModCommon{ + .b = b, + .t = target, + .o = optimize, + .cfg = .{ + .use_sdl = true, + .use_gl = true, + .use_togles = true, + }, }; - const vstdlib = vstdlib: { - const cpp = [_]proj.PlatformSrc{ - proj.PlatformSrc{ .data = &[_][]const u8{ "coroutine.cpp", "cvar.cpp", "jobthread.cpp", "KeyValuesSystem.cpp", "random.cpp", "vcover.cpp", "../public/tier0/memoverride.cpp" } }, - proj.PlatformSrc{ - .data = &[_][]const u8{"processutils.cpp"}, - .spec = .{ - .os = .{ .windows = @as(void, undefined) }, - }, - }, - }; - - const asm_att = [_]proj.PlatformSrc{proj.PlatformSrc{ - // TODO: at&t syntax - .data = &[_][]const u8{ "coroutine_win64.masm", "GetStackPtr64.masm" }, - .spec = .{ - .os = .{ .windows = @as(void, undefined) }, - .arch = .{ .amd64 = @as(void, undefined) }, - }, - }}; - - const macros = [_]proj.PlatformMacros{proj.PlatformMacros{ - .data = &[_]proj.Macro{ - proj.Macro{ .name = "VSTDLIB_DLL_EXPORT" }, - }, - }}; - - const incpaths = [_]proj.PlatformIncludePaths{ - proj.PlatformIncludePaths{ .data = &[_]proj.Path{b.path("../public/vstdlib")} }, - }; - - break :vstdlib proj.make_module(b, target, optimize, "vstdlib", .{ .use_sdl = true, .use_gl = true, .use_togles = true }, .shared, b.path("vstdlib"), &cpp, null, &asm_att, null, ¯os, &incpaths, null); - }; - - b.installArtifact(vstdlib); + const tier0 = proj.make_module(common, .{ + .name = "tier0", + .kind = .shared, + .root = b.path("tier0"), + .src_cpp = &mods.tier0.cpp, + .src_asm = &mods.tier0.asm_att, + .macros = &mods.tier0.macros, + }); b.installArtifact(tier0); + + const tier1 = proj.make_module(common, .{ + .name = "tier1", + .kind = .static, + .root = b.path("tier1"), + .src_cpp = &mods.tier1.cpp, + .links = &mods.tier1.links, + .macros = &mods.tier1.macros, + }); + b.installArtifact(tier1); + + const vstdlib = proj.make_module(common, .{ + .name = "vstdlib", + .kind = .shared, + .root = b.path("vstdlib"), + .src_cpp = &mods.vstdlib.cpp, + .src_asm = &mods.vstdlib.asm_att, + .macros = &mods.vstdlib.macros, + .include_paths = &mods.vstdlib.incpaths, + .depends_on = &[_]Compile{ tier0, tier1 }, + }); + b.installArtifact(vstdlib); + + const tier2 = proj.make_module(common, .{ + .name = "tier2", + .kind = .static, + .root = b.path("tier2"), + .src_cpp = &mods.tier2.cpp, + .include_paths = &mods.tier2.incpaths, + }); + b.installArtifact(tier2); + + // TODO: + // dmattributevar.h:1155:15: error: no member named 'Data' in 'CDmaElement' + // const tier3 = proj.make_module(common, .{ + // .name = "tier3", + // .kind = .static, + // .root = b.path("tier3"), + // .src_cpp = &mods.tier3.cpp, + // .include_paths = &mods.tier3.incpaths, + // }); + // b.installArtifact(tier3); + + const vpklib = proj.make_module(common, .{ + .name = "vpklib", + .kind = .static, + .root = b.path("vpklib"), + .src_cpp = &mods.vpklib.cpp, + }); + b.installArtifact(vpklib); + + const filesystem = proj.make_module(common, .{ + .name = "filesystem_stdio", + .kind = .shared, + .root = b.path("filesystem"), + .src_cpp = &mods.filesystem.cpp, + .macros = &mods.filesystem.macros, + .depends_on = &[_]Compile{ tier0, tier1, tier2, vstdlib, vpklib }, + }); + b.installArtifact(filesystem); } diff --git a/mods.zig b/mods.zig new file mode 100644 index 00000000..12d563a1 --- /dev/null +++ b/mods.zig @@ -0,0 +1,277 @@ +const std = @import("std"); +const proj = @import("project.zig"); + +pub const tier0 = struct { + pub const cpp = [_]proj.PlatformSrc{ + proj.PlatformSrc{ .data = &[_][]const u8{ + "assert_dialog.cpp", + "commandline.cpp", + "cpu.cpp", + "cpumonitoring.cpp", + "cpu_usage.cpp", + "dbg.cpp", + "dynfunction.cpp", + "fasttimer.cpp", + "mem.cpp", + "mem_helpers.cpp", + "memdbg.cpp", + "memstd.cpp", + "memvalidate.cpp", + "minidump.cpp", + "pch_tier0.cpp", + "progressbar.cpp", + "security.cpp", + "systeminformation.cpp", + "stacktools.cpp", + "threadtools.cpp", + "tier0_strtools.cpp", + "tslist.cpp", + "vprof.cpp", + "../tier1/pathmatch.cpp", + } }, + proj.PlatformSrc{ + .data = &[_][]const u8{ + "PMELib.cpp", + "thread.cpp", + "cpu_posix.cpp", + "platform_posix.cpp", + "pme_posix.cpp", + "vcrmode_posix.cpp", + }, + .spec = .{ .os = .{ + .posix = null, + } }, + }, + proj.PlatformSrc{ + .data = &[_][]const u8{ + "PMELib.cpp", + "thread.cpp", + "assert_dialog.rc", + // "etwprof.cpp", + "platform.cpp", + "pme.cpp", + "vcrmode.cpp", + "win32consoleio.cpp", + }, + .spec = .{ + .os = .{ .windows = @as(void, undefined) }, + }, + }, + }; + + pub const asm_att = [_]proj.PlatformSrc{proj.PlatformSrc{ + .data = &[_][]const u8{"InterlockedCompareExchange128.S"}, + .spec = .{ + .arch = .{ .amd64 = @as(void, undefined) }, + }, + }}; + + pub const macros = [_]proj.PlatformMacros{proj.PlatformMacros{ + .data = &[_]proj.Macro{ + proj.Macro{ .name = "TIER0_DLL_EXPORT" }, + }, + }}; +}; + +pub const tier1 = struct { + pub const cpp = [_]proj.PlatformSrc{ + proj.PlatformSrc{ + .data = &[_][]const u8{ + "../utils/lzma/C/LzmaDec.c", + "bitbuf.cpp", + "byteswap.cpp", + "characterset.cpp", + "checksum_crc.cpp", + "checksum_md5.cpp", + "checksum_sha1.cpp", + "commandbuffer.cpp", + "convar.cpp", + "datamanager.cpp", + "diff.cpp", + "generichash.cpp", + "ilocalize.cpp", + "interface.cpp", + "KeyValues.cpp", + "keyvaluesjson.cpp", + "kvpacker.cpp", + "lzmaDecoder.cpp", + "lzss.cpp", // [!$SOURCESDK] + "mempool.cpp", + "memstack.cpp", + "NetAdr.cpp", + "newbitbuf.cpp", + "rangecheckedvar.cpp", + "reliabletimer.cpp", + "snappy-sinksource.cpp", + "snappy-stubs-internal.cpp", + "snappy.cpp", + "sparsematrix.cpp", + "splitstring.cpp", + "stringpool.cpp", + "strtools.cpp", + "strtools_unicode.cpp", + "tier1.cpp", + "tokenreader.cpp", + "uniqueid.cpp", + "utlbinaryblock.cpp", + "utlbuffer.cpp", + "utlbufferutil.cpp", + "utlstring.cpp", + "utlsymbol.cpp", + }, + }, + proj.PlatformSrc{ + .data = &[_][]const u8{ + // "pathmatch.cpp" + "processor_detect_linux.cpp", + "qsort_s.cpp", + }, + .spec = .{ .os = .{ + .posix = null, + } }, + }, + proj.PlatformSrc{ + .data = &[_][]const u8{"processor_detect.cpp"}, + .spec = .{ + .os = .{ .windows = @as(void, undefined) }, + }, + }, + }; + + pub const links = [_]proj.PlatformLink{ + proj.PlatformLink{ .data = &[_][]const u8{"iconv"}, .spec = .{ .os = proj.Os.DARWIN } }, + }; + + pub const macros = [_]proj.PlatformMacros{proj.PlatformMacros{ + .data = &[_]proj.Macro{ + proj.Macro{ .name = "TIER1_STATIC_LIB", .val = "1" }, + }, + }}; +}; + +pub const vstdlib = struct { + pub const cpp = [_]proj.PlatformSrc{ + proj.PlatformSrc{ .data = &[_][]const u8{ "coroutine.cpp", "cvar.cpp", "jobthread.cpp", "KeyValuesSystem.cpp", "random.cpp", "vcover.cpp", "../public/tier0/memoverride.cpp" } }, + proj.PlatformSrc{ + .data = &[_][]const u8{"processutils.cpp"}, + .spec = .{ + .os = .{ .windows = @as(void, undefined) }, + }, + }, + }; + + pub const asm_att = [_]proj.PlatformSrc{proj.PlatformSrc{ + // TODO: at&t syntax + .data = &[_][]const u8{ "coroutine_win64.masm", "GetStackPtr64.masm" }, + .spec = .{ + .os = .{ .windows = @as(void, undefined) }, + .arch = .{ .amd64 = @as(void, undefined) }, + }, + }}; + + pub const macros = [_]proj.PlatformMacros{proj.PlatformMacros{ + .data = &[_]proj.Macro{ + proj.Macro{ .name = "VSTDLIB_DLL_EXPORT" }, + }, + }}; + + pub const incpaths = [_]proj.PlatformIncludePaths{ + proj.PlatformIncludePaths{ .data = &[_][]const u8{"../public/vstdlib"} }, + }; +}; + +pub const tier2 = struct { + pub const cpp = [_]proj.PlatformSrc{ + proj.PlatformSrc{ + .data = &[_][]const u8{ + "beamsegdraw.cpp", + "defaultfilesystem.cpp", + "dmconnect.cpp", + "fileutils.cpp", + "keybindings.cpp", + "../public/map_utils.cpp", + "../public/materialsystem/MaterialSystemUtil.cpp", + "camerautils.cpp", + "meshutils.cpp", + "p4helpers.cpp", + "renderutils.cpp", + "riff.cpp", + "soundutils.cpp", + "tier2.cpp", + "util_init.cpp", + "utlstreambuffer.cpp", + "vconfig.cpp", + "keyvaluesmacros.cpp", + }, + }, + }; + + pub const incpaths = [_]proj.PlatformIncludePaths{ + proj.PlatformIncludePaths{ .data = &[_][]const u8{"../public/tier2"} }, + }; +}; + +pub const tier3 = struct { + pub const cpp = [_]proj.PlatformSrc{ + proj.PlatformSrc{ + .data = &[_][]const u8{ + "tier3.cpp", + "mdlutils.cpp", + "choreoutils.cpp", + "scenetokenprocessor.cpp", + "studiohdrstub.cpp", + }, + }, + }; + + pub const incpaths = [_]proj.PlatformIncludePaths{ + proj.PlatformIncludePaths{ .data = &[_][]const u8{ "../public/tier2", "../public/tier3" } }, + }; +}; + +pub const vpklib = struct { + pub const cpp = [_]proj.PlatformSrc{ + proj.PlatformSrc{ + .data = &[_][]const u8{ + "packedstore.cpp", + "../common/simplebitstring.cpp", + }, + }, + }; +}; + +pub const filesystem = struct { + pub const cpp = [_]proj.PlatformSrc{ + proj.PlatformSrc{ + .data = &[_][]const u8{ + "basefilesystem.cpp", + "packfile.cpp", + "filetracker.cpp", + "filesystem_async.cpp", + "filesystem_stdio.cpp", + "../public/kevvaluescompiler.cpp", + "../public/zip_utils.cpp", + "QueuedLoader.cpp", + "../public/tier0/memoverride.cpp", + }, + }, + proj.PlatformSrc{ + .data = &[_][]const u8{ + "linux_support.cpp", + }, + .spec = .{ .os = .{ + .posix = null, + } }, + }, + }; + + pub const macros = [_]proj.PlatformMacros{proj.PlatformMacros{ + .data = &[_]proj.Macro{ + proj.Macro{ .name = "FILESYSTEM_STDIO_EXPORTS", .val = "1" }, + proj.Macro{ .name = "DONT_PROTECT_FILEIO_FUNCTIONS", .val = "1" }, + proj.Macro{ .name = "SUPPORT_PACKED_STORE", .val = "1" }, + // proj.Macro{ .name = "PROTECTED_THINGS_ENABLE", .val = "1" }, + // proj.Macro{ .name = "_USE_32BIT_TIME_T", .val = "1" }, + }, + }}; +}; diff --git a/progress.md b/progress.md index 955a998d..b64a33ab 100644 --- a/progress.md +++ b/progress.md @@ -3,11 +3,13 @@ - make build code generic - build a `vstdlib.so` from zig - pass correct cflags/ldflags/defines into the build (mostly) +- `filesystem_stdio`, `tier1`, `tier2`, `vpklib` - - - ### todo! -- build `tier1.a` +- `particles`, `dmxloader`, `matsys_controls`, `tier3`, `mathlib`, `choreobjects`, `steam_api`, `bitmap` +- work our way up to a game project - work our way up to `engine.so` - - - diff --git a/project.zig b/project.zig index 07c0af13..c511e1a9 100644 --- a/project.zig +++ b/project.zig @@ -47,6 +47,9 @@ pub const Os = union(enum) { }, }; } + + // TODO: more + pub const DARWIN = Os{ .posix = .{ .bsd = .{ .darwin = @as(void, undefined) } } }; }; pub const Arch = union(enum) { @@ -116,6 +119,7 @@ pub const Api = union(enum) { }; } + // TODO // pub fn from(from: Config) Api { // } @@ -127,8 +131,7 @@ pub const Spec = struct { mode: ?Mode = null, api: ?Api = null, - pub fn from(t: std.Build.ResolvedTarget, o: std.builtin.OptimizeMode, c: Config) Spec { - _ = c; + pub fn from(t: std.Build.ResolvedTarget, o: std.builtin.OptimizeMode) Spec { return Spec{ .os = Os.from(t.result.os.tag), .arch = Arch.from(t.result.cpu.arch), @@ -150,8 +153,8 @@ pub const PlatformSrc = struct { data: []const []const u8, spec: ?Spec = null }; pub const PlatformLink = struct { data: []const []const u8, spec: ?Spec = null }; pub const PlatformCflags = struct { data: []const []const u8, spec: ?Spec = null }; pub const PlatformMacros = struct { data: []const Macro, spec: ?Spec = null }; -pub const PlatformIncludePaths = struct { data: []const Path, spec: ?Spec = null }; -pub const PlatformLinkPaths = struct { data: []const Path, spec: ?Spec = null }; +pub const PlatformIncludePaths = struct { data: []const []const u8, spec: ?Spec = null }; +pub const PlatformLinkPaths = struct { data: []const []const u8, spec: ?Spec = null }; pub const Config = struct { use_sdl: bool, @@ -165,22 +168,53 @@ pub const ModType = enum { exe, }; -pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin.OptimizeMode, name_: []const u8, cfg_: Config, modtype_: ModType, mod_root_: ?Path, src_cpp_: []const PlatformSrc, cpp_flags_: ?[]const PlatformCflags, src_assembly_: ?[]const PlatformSrc, links_: ?[]const PlatformLink, macros_: ?[]const PlatformMacros, incpaths_: ?[]const PlatformIncludePaths, linkpaths_: ?[]const PlatformLinkPaths) *std.Build.Step.Compile { +pub const ModCommon = struct { + b: *std.Build, + t: std.Build.ResolvedTarget, + o: std.builtin.OptimizeMode, + cfg: struct { + use_sdl: bool, + use_gl: bool, + use_togles: bool, + }, +}; + +pub const ModInfo = struct { + name: []const u8, + kind: ModType, + root: ?Path = null, + src_cpp: []const PlatformSrc, + src_asm: ?[]const PlatformSrc = null, + flags: ?[]const PlatformCflags = null, + links: ?[]const PlatformLink = null, + macros: ?[]const PlatformMacros = null, + include_paths: ?[]const PlatformIncludePaths = null, + link_paths: ?[]const PlatformLinkPaths = null, + depends_on: ?[]const *std.Build.Step.Compile = null, +}; + +pub fn make_module(common: ModCommon, info: ModInfo) *std.Build.Step.Compile { + const b = common.b; + const t = common.t; + const o = common.o; + // const cfg = common.cfg; + const IPATH = [_]PlatformIncludePaths{ - PlatformIncludePaths{ .data = &[_]Path{ - b_.path("."), - b_.path("../thirdparty"), - b_.path("../"), - b_.path("../public"), - b_.path("../public/tier0"), - b_.path("../public/tier1"), + PlatformIncludePaths{ .data = &[_][]const u8{ + ".", + "../thirdparty", + "../", + "../public", + "../public/tier0", + "../public/tier1", + "../common", } }, - PlatformIncludePaths{ .data = &[_]Path{b_.path("../thirdparty/SDL")}, .spec = .{ .api = .{ .sdl = @as(void, undefined) } } }, + PlatformIncludePaths{ .data = &[_][]const u8{"../thirdparty/SDL"}, .spec = .{ .api = .{ .sdl = @as(void, undefined) } } }, }; const LPATH = [_]PlatformLinkPaths{ PlatformLinkPaths{ - .data = &[_]Path{b_.path("../thirdparty")}, + .data = &[_][]const u8{"../thirdparty"}, }, }; @@ -201,6 +235,7 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin "shlwapi", "imm32", }, .spec = .{ .os = .{ .windows = @as(void, undefined) } } } }; + // TODO: darwin links const MACROS = [_]PlatformMacros{ PlatformMacros{ .data = &[_]Macro{ @@ -228,7 +263,7 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin Macro{ .name = "GNUC", .val = "1" }, Macro{ .name = "NO_MEMOVERRIDE_NEW_DELETE", .val = "1" }, // for darwin - Macro{ .name = "_DLL_EXT", .val = t_.result.os.tag.dynamicLibSuffix() }, + Macro{ .name = "_DLL_EXT", .val = t.result.os.tag.dynamicLibSuffix() }, }, .spec = .{ .os = .{ .posix = null }, @@ -255,34 +290,37 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin }, .spec = .{ .os = .{ .posix = .{ .bsd = .{ .darwin = @as(void, undefined) } } }, } }, - PlatformMacros{ .data = &[_]Macro{ - Macro{ .name = "WIN32", .val = "1" }, - Macro{ .name = "_WIN32", .val = "1" }, - Macro{ - .name = "_WINDOWS", + PlatformMacros{ + .data = &[_]Macro{ + Macro{ .name = "WIN32", .val = "1" }, + Macro{ .name = "_WIN32", .val = "1" }, + Macro{ + .name = "_WINDOWS", + }, + Macro{ + .name = "_CRT_SECURE_NO_DEPRECATE", + }, + Macro{ + .name = "_CRT_NONSTDC_NO_DEPRECATE", + }, + Macro{ + .name = "_ALLOW_RUNTIME_LIBRARY_MISMATCH", + }, + Macro{ + .name = "_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH", + }, + Macro{ + .name = "_ALLOW_MSC_VER_MISMATCH", + }, + Macro{ + .name = "NO_X360_XDK", + }, + Macro{ .name = "_DLL_EXT", .val = ".dll" }, }, - Macro{ - .name = "_CRT_SECURE_NO_DEPRECATE", + .spec = .{ + .os = .{ .windows = @as(void, undefined) }, }, - Macro{ - .name = "_CRT_NONSTDC_NO_DEPRECATE", - }, - Macro{ - .name = "_ALLOW_RUNTIME_LIBRARY_MISMATCH", - }, - Macro{ - .name = "_ALLOW_ITERATOR_DEBUG_LEVEL_MISMATCH", - }, - Macro{ - .name = "_ALLOW_MSC_VER_MISMATCH", - }, - Macro{ - .name = "NO_X360_XDK", - }, - Macro{ .name = "_DLL_EXT", .val = ".dll" }, - }, .spec = .{ - .os = .{ .windows = @as(void, undefined) }, - } }, + }, PlatformMacros{ .data = &[_]Macro{ Macro{ .name = "PLATFORM_64BITS", .val = "1" }, }, .spec = .{ @@ -338,15 +376,15 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin } }, }; - const root = if (mod_root_) |r| r else b_.path("."); + const root = if (info.root) |r| r else b.path("."); - var cxxsrc = std.ArrayList([]const u8).init(b_.allocator); - var asmsrc = std.ArrayList([]const u8).init(b_.allocator); - var cflags = std.ArrayList([]const u8).init(b_.allocator); - var macros = std.ArrayList(Macro).init(b_.allocator); - var links = std.ArrayList([]const u8).init(b_.allocator); - var ipaths = std.ArrayList(Path).init(b_.allocator); - var lpaths = std.ArrayList(Path).init(b_.allocator); + var cxxsrc = std.ArrayList([]const u8).init(b.allocator); + var asmsrc = std.ArrayList([]const u8).init(b.allocator); + var cflags = std.ArrayList([]const u8).init(b.allocator); + var macros = std.ArrayList(Macro).init(b.allocator); + var links = std.ArrayList([]const u8).init(b.allocator); + var ipaths = std.ArrayList([]const u8).init(b.allocator); + var lpaths = std.ArrayList([]const u8).init(b.allocator); defer { macros.deinit(); @@ -358,7 +396,7 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin ipaths.deinit(); } - const spec = Spec.from(t_, o_, cfg_); + const spec = Spec.from(t, o); const fns = struct { pub fn walk(sp: Spec, T: type, I: type, list: []const T, arr: *std.ArrayList(I)) void { @@ -371,54 +409,54 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin }; // defaults - fns.walk(spec, PlatformIncludePaths, Path, &IPATH, &ipaths); - fns.walk(spec, PlatformLinkPaths, Path, &LPATH, &lpaths); + fns.walk(spec, PlatformIncludePaths, []const u8, &IPATH, &ipaths); + fns.walk(spec, PlatformLinkPaths, []const u8, &LPATH, &lpaths); fns.walk(spec, PlatformLink, []const u8, &LINK, &links); fns.walk(spec, PlatformMacros, Macro, &MACROS, ¯os); fns.walk(spec, PlatformCflags, []const u8, &FLAGS, &cflags); // for this module - if (incpaths_) |ip| { - fns.walk(spec, PlatformIncludePaths, Path, ip, &ipaths); + if (info.include_paths) |ip| { + fns.walk(spec, PlatformIncludePaths, []const u8, ip, &ipaths); } - if (linkpaths_) |lp| { - fns.walk(spec, PlatformLinkPaths, Path, lp, &lpaths); + if (info.link_paths) |lp| { + fns.walk(spec, PlatformLinkPaths, []const u8, lp, &lpaths); } - if (links_) |l| { + if (info.links) |l| { fns.walk(spec, PlatformLink, []const u8, l, &links); } - if (macros_) |m| { + if (info.macros) |m| { fns.walk(spec, PlatformMacros, Macro, m, ¯os); } - if (cpp_flags_) |f| { + if (info.flags) |f| { fns.walk(spec, PlatformCflags, []const u8, f, &cflags); } - if (src_assembly_) |a| { + if (info.src_asm) |a| { fns.walk(spec, PlatformSrc, []const u8, a, &asmsrc); } - fns.walk(spec, PlatformSrc, []const u8, src_cpp_, &cxxsrc); + fns.walk(spec, PlatformSrc, []const u8, info.src_cpp, &cxxsrc); - const mod = b_.addModule(name_, .{ - .target = t_, - .optimize = o_, + const mod = b.addModule(info.name, .{ + .target = t, + .optimize = o, .link_libcpp = true, .link_libc = true, }); - const compile = switch (modtype_) { - .static => b_.addLibrary(.{ - .name = name_, + const compile = switch (info.kind) { + .static => b.addLibrary(.{ + .name = info.name, .root_module = mod, .linkage = .static, }), - .shared => b_.addLibrary(.{ - .name = name_, + .shared => b.addLibrary(.{ + .name = info.name, .root_module = mod, .linkage = .dynamic, }), - .exe => b_.addExecutable(.{ + .exe => b.addExecutable(.{ .root_module = mod, - .name = name_, + .name = info.name, .link_libc = true, }), }; @@ -430,11 +468,11 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin } for (ipaths.items) |i| { - mod.addIncludePath(root.join(b_.allocator, i.src_path.sub_path) catch unreachable); + mod.addIncludePath(root.join(b.allocator, i) catch unreachable); } for (lpaths.items) |lp| { - mod.addLibraryPath(root.join(b_.allocator, lp.src_path.sub_path) catch unreachable); + mod.addLibraryPath(root.join(b.allocator, lp) catch unreachable); } for (links.items) |l| { @@ -450,5 +488,11 @@ pub fn make_module(b_: *std.Build, t_: std.Build.ResolvedTarget, o_: std.builtin mod.addCSourceFiles(.{ .files = asmsrc.items, .root = root, .language = .assembly }); + if (info.depends_on) |deps| { + for (deps) |d| { + mod.linkLibrary(d); + } + } + return compile; } diff --git a/public/datamodel/dmattributevar.h b/public/datamodel/dmattributevar.h index e0ce32f5..67c875f4 100644 --- a/public/datamodel/dmattributevar.h +++ b/public/datamodel/dmattributevar.h @@ -1,6 +1,6 @@ //========= Copyright Valve Corporation, All rights reserved. ============// // -// Purpose: +// Purpose: // //============================================================================= @@ -143,7 +143,7 @@ public: // Array count int Count() const; - // Gets + // Gets const void* GetUntyped( int i ) const; // String conversion @@ -227,7 +227,7 @@ protected: template< class T, class B > class CDmaArrayBase : public CDmaArrayConstBase< T, B > { -public: +public: // Insertion int AddToTail(); int InsertBefore( int elem ); @@ -459,16 +459,16 @@ class CDmaArray : public CDmaDecorator< T, CDmaArrayBase< T, CDmaDataInternal< C DECLARE_ATTRIBUTE_ARRAY_VARIABLE( CDmaArray, T ); public: - const CDmaArray& operator=( const CDmaArray &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + const CDmaArray& operator=( const CDmaArray &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } - template< class C > const CDmaArray& operator=( const C &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + template< class C > const CDmaArray& operator=( const C &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } private: @@ -491,16 +491,16 @@ class CDmrArray : public CDmrDecorator< T, CDmaArrayBase< T, CDmaDataExternal< C DECLARE_ATTRIBUTE_ARRAY_REFERENCE( CDmrArray, T ); public: - const CDmrArray& operator=( const CDmrArray &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + const CDmrArray& operator=( const CDmrArray &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } - template< class C > const CDmrArray& operator=( const C &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + template< class C > const CDmrArray& operator=( const C &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } }; @@ -511,16 +511,16 @@ class CDmaStringArray : public CDmaDecorator< CUtlString, CDmaStringArrayBase< C DECLARE_ATTRIBUTE_ARRAY_VARIABLE( CDmaStringArray, CUtlString ); public: - const CDmaStringArray& operator=( const CDmaStringArray &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + const CDmaStringArray& operator=( const CDmaStringArray &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } - template< class C > const CDmaStringArray& operator=( const C &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + template< class C > const CDmaStringArray& operator=( const C &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } private: @@ -536,16 +536,16 @@ public: CDmrStringArray( CDmaStringArray& var ) { Init( var.GetAttribute() ); } CDmrStringArray( CDmrStringArray& var ) { Init( var.GetAttribute() ); } - const CDmrStringArray& operator=( const CDmrStringArray &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + const CDmrStringArray& operator=( const CDmrStringArray &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } - template< class C > const CDmrStringArray& operator=( const C &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + template< class C > const CDmrStringArray& operator=( const C &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } }; @@ -586,17 +586,17 @@ public: } } - template< typename C > CDmaElementArray& operator=( const C &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + template< typename C > CDmaElementArray& operator=( const C &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } // NOTE: The copy operator= must be defined in addition to the generic one - const CDmaElementArray& operator=( const CDmaElementArray &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + const CDmaElementArray& operator=( const CDmaElementArray &val ) + { + CopyArray( val.Base(), val.Count() ); + return *this; } private: @@ -733,16 +733,16 @@ public: } template< typename C > CDmrElementArray& operator=( const C &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + { + CopyArray( val.Base(), val.Count() ); + return *this; } // NOTE: The copy operator= must be defined in addition to the generic one const CDmrElementArray& operator=( const CDmrElementArray &val ) - { - CopyArray( val.Base(), val.Count() ); - return *this; + { + CopyArray( val.Base(), val.Count() ); + return *this; } }; @@ -788,7 +788,7 @@ template< class T > inline const T& CDmaVar::Set( const T &val ) return m_Storage; } -template< class T > inline const T& CDmaVar::operator=( const T &val ) +template< class T > inline const T& CDmaVar::operator=( const T &val ) { return Set( val ); } @@ -799,38 +799,38 @@ template< class T > inline const CDmaVar& CDmaVar::operator=( const CDmaVa return *this; } -template< class T > inline const T& CDmaVar::operator+=( const T &val ) +template< class T > inline const T& CDmaVar::operator+=( const T &val ) { return Set( Value() + val ); } -template< class T > inline const T& CDmaVar::operator-=( const T &val ) +template< class T > inline const T& CDmaVar::operator-=( const T &val ) { return Set( Value() - val ); } -template< class T > inline const T& CDmaVar::operator/=( const T &val ) +template< class T > inline const T& CDmaVar::operator/=( const T &val ) { return Set( Value() / val ); } -template< class T > inline const T& CDmaVar::operator*=( const T &val ) +template< class T > inline const T& CDmaVar::operator*=( const T &val ) { return Set( Value() * val ); } -template< class T > inline const T& CDmaVar::operator^=( const T &val ) +template< class T > inline const T& CDmaVar::operator^=( const T &val ) { return Set( Value() ^ val ); } -template< class T > inline const T& CDmaVar::operator|=( const T &val ) +template< class T > inline const T& CDmaVar::operator|=( const T &val ) { return Set( Value() | val ); } -template< class T > inline const T& CDmaVar::operator&=( const T &val ) -{ +template< class T > inline const T& CDmaVar::operator&=( const T &val ) +{ return Set( Value() & val ); } @@ -858,19 +858,19 @@ template< class T > inline T CDmaVar::operator--( int ) // postfix version.. return oldValue; } -template< class T > inline CDmaVar::operator const T&() const +template< class T > inline CDmaVar::operator const T&() const { - return Value(); + return Value(); } -template< class T > inline const T& CDmaVar::Get() const +template< class T > inline const T& CDmaVar::Get() const { - return Value(); + return Value(); } -template< class T > inline const T* CDmaVar::operator->() const +template< class T > inline const T* CDmaVar::operator->() const { - return &Value(); + return &Value(); } template< class T > inline CDmAttribute *CDmaVar::GetAttribute() @@ -891,34 +891,34 @@ template< class T > inline bool CDmaVar::IsDirty() const return m_pAttribute->IsFlagSet( FATTRIB_DIRTY ); } -template< class T > inline const T& CDmaVar::Value() const -{ - return m_Storage; +template< class T > inline const T& CDmaVar::Value() const +{ + return m_Storage; } -template< class T > inline T& CDmaVar::Value() -{ - return m_Storage; +template< class T > inline T& CDmaVar::Value() +{ + return m_Storage; } -template<> inline const DmElementHandle_t& CDmaVar< DmElementHandle_t >::Value() const +template<> inline const DmElementHandle_t& CDmaVar< DmElementHandle_t >::Value() const { return m_Storage.m_Handle; } -template<> inline DmElementHandle_t& CDmaVar< DmElementHandle_t >::Value() +template<> inline DmElementHandle_t& CDmaVar< DmElementHandle_t >::Value() { return m_Storage.m_Handle; } -template< class T > inline const typename CDmaVar::D& CDmaVar::Storage() const -{ - return m_Storage; +template< class T > inline const typename CDmaVar::D& CDmaVar::Storage() const +{ + return m_Storage; } -template< class T > inline typename CDmaVar::D& CDmaVar::Storage() -{ - return m_Storage; +template< class T > inline typename CDmaVar::D& CDmaVar::Storage() +{ + return m_Storage; } @@ -1000,7 +1000,7 @@ inline void CDmaColor::SetRawColor( int color ) // //----------------------------------------------------------------------------- inline void CDmaObjectId::CreateObjectId( ) -{ +{ DmObjectId_t id; CreateUniqueId( &id ); m_pAttribute->SetValue( id ); @@ -1347,7 +1347,7 @@ inline int CDmaStringArrayBase::InsertBefore( int elem, const char *pValue ) // Inline methods for CDmaElementArrayBase // //----------------------------------------------------------------------------- -template< class E, class B > +template< class E, class B > inline UtlSymId_t CDmaElementArrayConstBase::GetElementType() const { return this->Data().m_ElementType;