{"id":17356653,"url":"https://github.com/menduz/zig-steamworks","last_synced_at":"2025-10-31T09:51:51.727Z","repository":{"id":173382972,"uuid":"650353471","full_name":"menduz/zig-steamworks","owner":"menduz","description":"Steamwork bindings for Zig","archived":false,"fork":false,"pushed_at":"2025-07-26T16:35:32.000Z","size":5053,"stargazers_count":26,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-26T21:27:46.734Z","etag":null,"topics":["game-development","steamworks","zig"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/menduz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-06-06T22:27:04.000Z","updated_at":"2025-07-26T16:35:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"7579666a-bc8b-4b0f-ac2b-9737341c13e8","html_url":"https://github.com/menduz/zig-steamworks","commit_stats":null,"previous_names":["menduz/zig-steamworks"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/menduz/zig-steamworks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/menduz%2Fzig-steamworks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/menduz%2Fzig-steamworks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/menduz%2Fzig-steamworks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/menduz%2Fzig-steamworks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/menduz","download_url":"https://codeload.github.com/menduz/zig-steamworks/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/menduz%2Fzig-steamworks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281969178,"owners_count":26591719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-31T02:00:07.401Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game-development","steamworks","zig"],"created_at":"2024-10-15T18:57:49.592Z","updated_at":"2025-10-31T09:51:51.721Z","avatar_url":"https://github.com/menduz.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zig-steamworks\n\nZig bindings for Steamworks, compatible with v1.57 (March 2023).\n\nThe bindings are autogenerated from the C bindings and are compatible with\n- macOS (both Apple Silicon and Intel)\n- linux (x86_64)\n- windows (x86_64)\n\nMain branch is compatible with Zig 0.14.0\n\n# Including the Steamworks SDK\n\nDue to licence agreements, you must bring your own SDK. This project assumes it is located in the ./steamworks folder. But you can have it anywhere else.\n\n# Linking the Steamworks libraries.\n\n```zig\n// build.zig\nconst zig_steamworks = @import(\"zig_steamworks\");\n\npub fn build(b: *std.Build) !void {\n  // create a module\n  const exe_mod = b.createModule( ... );\n\n  // add the library as a dependency\n  const steamworks_lib = b.dependency(\"zig_steamworks\", .{\n        .target = target,\n        .optimize = optimize,\n    });\n\n  // add zig import and link static library\n  exe_mod.addImport(\"steamworks\", steamworks_lib.module(\"steamworks\"));\n  exe_mod.linkLibrary(steamworks_lib.artifact(\"steamworks\"));\n\n  // ...\n  const exe = b.addExecutable( ... );\n\n  zig_steamworks.addLibraryPath(steamworks_lib.builder, exe);\n}\n```\n\n# Build it\n\nFor convenience, this repository offers already built bindings for Zig in the `src` folder. Until Zig modules and package manager are mature, the recommended course of action is to copy these files into your project.\nIn this case, you'll need to manually link the steamapi dlls and headers in your own build.zig file.\nAlternatively, you can use `zig fetch --save git+https://github.com/menduz/zig-steamworks` or `zig fetch --save /path/to/local/zig-steamworks`, and include it as a dependency as outlined above\n\nTo re-build the files run the following command\n\n```\nnode generate.js path_to_steamworks/public/steam/steam_api.json\n```\n\n# Example\n\n```zig\nconst std = @import(\"std\");\nconst steam = @import(\"steamworks\");\n\n/// callback hook for debug text emitted from the Steam API\npub fn SteamAPIDebugTextHook(nSeverity: c_int, pchDebugText: [*c]const u8) callconv(.c) void {\n    // if you're running in the debugger, only warnings (nSeverity \u003e= 1) will be sent\n    // if you add -debug_steamapi to the command-line, a lot of extra informational messages will also be sent\n    std.debug.print(\"SteamAPIDebugTextHook sev:{} msg: {s}\\n\", .{ nSeverity, pchDebugText });\n}\n\n/// get an authentication ticket for our user\nfn authTicket(identity: *steam.SteamNetworkingIdentity) !void {\n    var rgchToken: *[2048]u8 = try std.heap.c_allocator.create([2048]u8);\n    var unTokenLen: c_uint = 0;\n    var m_hAuthTicket = steam.SteamUser().GetAuthSessionTicket(rgchToken, 2048, \u0026unTokenLen, identity);\n    std.debug.print(\"GetAuthSessionTicket={} len={} token={s}\", .{ m_hAuthTicket, unTokenLen, rgchToken });\n}\n\npub fn main() !void {\n    if (steam.SteamAPI_RestartAppIfNecessary(480)) {\n        // if Steam is not running or the game wasn't started through Steam, SteamAPI_RestartAppIfNecessary starts the\n        // local Steam client and also launches this game again.\n\n        // Once you get a public Steam AppID assigned for this game, you need to replace k_uAppIdInvalid with it and\n        // removed steam_appid.txt from the game depot.\n        @panic(\"SteamAPI_RestartAppIfNecessary\");\n    }\n\n    if (steam.SteamAPI_Init()) {\n        std.debug.print(\"Steam initialized correctly. \\n\", .{});\n    } else {\n        @panic(\"Steam did not init\\n\");\n    }\n\n    steam.SteamClient().SetWarningMessageHook(SteamAPIDebugTextHook);\n\n    defer steam.SteamAPI_Shutdown();\n\n    std.debug.print(\"User {?}\\n\", .{steam.SteamUser().GetSteamID()});\n\n    var sock = steam.SteamNetworkingSockets_SteamAPI();\n\n    var pInfo: *steam.SteamNetworkingFakeIPResult_t = try std.heap.c_allocator.create(steam.SteamNetworkingFakeIPResult_t);\n    defer std.heap.c_allocator.destroy(pInfo);\n\n    sock.GetFakeIP(0, pInfo);\n    std.debug.print(\"GetFakeIP: {}\\n\", .{pInfo});\n    if (!pInfo.m_identity.IsEqualTo(pInfo.m_identity)) @panic(\"not equal\");\n\n    var pDetails: *steam.SteamNetAuthenticationStatus_t = try std.heap.c_allocator.create(steam.SteamNetAuthenticationStatus_t);\n    defer std.heap.c_allocator.destroy(pDetails);\n\n    var connectionStatus = sock.GetAuthenticationStatus(pDetails);\n    std.debug.print(\"GetAuthenticationStatus: {} {}\\n\", .{ connectionStatus, pDetails });\n\n    var pIdentity: *steam.SteamNetworkingIdentity = try std.heap.c_allocator.create(steam.SteamNetworkingIdentity);\n    std.heap.c_allocator.destroy(pIdentity);\n    var r = sock.GetIdentity(pIdentity);\n    std.debug.print(\"GetIdentity={} {}\\n\", .{ r, pIdentity });\n\n    try authTicket(pIdentity);\n}\n```\n\n# Alignment\n\nSteamworks is packed with `pragma packs`, I've tried dozens of approaches even brute forcing all structs, but getting the right alignment for every struct was impossible. So I took the good-enough-and-not-so-elegant path of delegating the alignment to the C compiler entirely and then forcing Zig to copy everything with the generated code. In effect, you will see a lot of `align(...)` in the generated code.\n\nIn practice both Mac and Linux alignments are the same.\n\nPlease do the following steps for each steamworks release that is added to this repo. Mind the diff in the steamworks headers to remove the private fields (search for `// ZIG:`).\n\n## To generate the linux alignment file from aarch64 Mac hosts\n\n```bash\n# open a docker container using x86_64\ndocker run -v $(pwd):/mnt -w /mnt --rm -it --platform linux/amd64 mcr.microsoft.com/devcontainers/typescript-node:0-18 zsh\n# install zig\nsudo bash .devcontainer/install-zig.sh\n# run the script and grab a coffee\nbash ./create-align-info-linux.sh\n```\n\n## To generate the mac alignment file from Mac\n\n```bash\n# run the script\nbash ./create-align-info-mac.sh\n```\n\n## To generate the mac alignment file from Windows\n\n```bash\n# run the script\n.\\create-align-info-mac.bat\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenduz%2Fzig-steamworks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmenduz%2Fzig-steamworks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmenduz%2Fzig-steamworks/lists"}