Skip to content

Instantly share code, notes, and snippets.

{
"nodes": {
"flake-utils": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
[geemili@renvi:~/src/3_resources/mach-examples]$ zig build -Drelease-safe
remote: Enumerating objects: 76, done.
remote: Counting objects: 100% (76/76), done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 67 (delta 10), reused 66 (delta 10), pack-reused 0
Unpacking objects: 100% (67/67), 387.14 KiB | 1.22 MiB/s, done.
From https://github.com/hexops/sdk-linux-x86_64
b65ab86..1cb61f5 main -> origin/main
downloading https://github.com/hexops/mach-gpu-dawn/releases/download/release-dd770e7/libdawn_x86_64-linux-gnu_release-fast.a.gz..
% Total % Received % Xferd Average Speed Time Time Time Current

Emscripten as a linker for Zig and C

This shows how to build a nontrivial program using Zig+Emscripten or C+Emscripten. In both cases Emscripten is only used as a linker, that is the frontend is either zig or clang.

"Nontrivial" here means the program uses interesting Emscripten features:

  • Asyncify
  • Full GLES3 support
  • GLFW3 support
@leroycep
leroycep / gist:c25d3aecca59b6b0e743af3a9f8db97e
Created October 23, 2022 19:44
`zig build run-triangle -Drelease-safe` error output
LLD Link... ld.lld: warning: /home/geemili/src/3_resources/mach-examples/zig-cache/mach/gpu-dawn/release-c68d8cd/x86_64-linux-gnu/release-fast/libdawn.a: archive member '/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/zig-cache/o/3782c3161961accaf3f066311d258554/libglfw.a' is neither ET_REL nor LLVM bitcode
ld.lld: warning: /home/geemili/src/3_resources/mach-examples/zig-cache/mach/gpu-dawn/release-c68d8cd/x86_64-linux-gnu/release-fast/libdawn.a: archive member '/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/zig-cache/o/3782c3161961accaf3f066311d258554/libglfw.a' is neither ET_REL nor LLVM bitcode
ld.lld: error: undefined symbol: internal_load_libgamemode
>>> referenced by cimport.zig:737 (/home/geemili/src/3_resources/mach-examples/zig-cache/o/a53156978d47df309a631246da168b16/cimport.zig:737)
>>> lto.tmp:(main)
>>> referenced by cimport.zig:723 (/home/geemili/src/3_resources/mach-examples/zig-cache/o/a53156978d47df309a631246da168b16/cimport.zig:723)
>>> lto.tmp:(main)
>>> referenced
@leroycep
leroycep / gist:dac1e02bb0bb27a4ef9da896b57e8c82
Last active August 7, 2022 23:27
mach game compile error
downloading https://github.com/hexops/mach-gpu-dawn/releases/download/release-fbb4741/libdawn_x86_64-linux-gnu_debug.a.gz..
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 77.4M 100 77.4M 0 0 8970k 0 0:00:08 0:00:08 --:--:-- 13.2M
downloading https://github.com/hexops/mach-gpu-dawn/releases/download/release-fbb4741/headers.json.gz..
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 46762 100 46762 0 0 37047 0 0:00:01 0:00:01 --:--:-- 97k
@leroycep
leroycep / flake.nix
Created July 14, 2022 00:18
zig development environment flake
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
zig-master = {
url = "github:jessestricker/zig-master.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
@leroycep
leroycep / qute-add-todoist.nu
Created July 5, 2022 02:02
A qutebrowser userscript for quickly adding tasks to todoist
#!/usr/bin/env nu
let SECRETS_FILE = ([$env.QUTE_CONFIG_DIR "qute-add-todoist.secrets"] | path join)
if not (echo $SECRETS_FILE | path exists) {
qute $'message-error "Could not find secrets file! Copy the API token into ($SECRETS_FILE)""'
qute 'open -t https://todoist.com/app/settings/integrations'
exit
}
const Errors = error{
hello,
world,
};
// It's a tagged union, expect the tag is an error set
const ErrorUnion = union(Errors) {
hello: u32,
world: []const u8,
};
@leroycep
leroycep / debug output
Created May 21, 2022 22:42
debugging zig c backend duplicate typedef; https://github.com/ziglang/zig/issues/11651
new f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
new fd5814f465beb2c5 tuple "typedef struct {\n uintptr_t field_0;\n uint8_t field_1;\n} zig_T_tuple_7busize_2c_20u1_7d;\n"
new 8d02975f3a25a947 array_u8_sentinel_0 "typedef uint8_t zig_A_u8_5[5];\n"
new d5d7770a0890948e array_u8 "typedef uint8_t zig_A_u8_1[1];\n"
f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
new 4487d943b4f83aed array_u8_sentinel_0 "typedef uint8_t zig_A_u8_1[1];\n"
f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
f4a0c58216b9dad9 const_slice_u8 "typedef struct { uint8_t const * ptr; size_t len; } zig_L_u8;\n"
new 25da5e8e385153e6 single_const_pointer "typedef uint16_t (*zig_F__2aconst_20fn_28_29_20anyerror_21void)(void);\n"
new 3b32fc1c5510a94 optional "typedef struct { uintptr_t payload; bool is_null; } zig_Q_usize
@leroycep
leroycep / eytzinger.zig
Created November 9, 2021 13:27
Utility functions for working with Eytzinger indices
const std = @import("std");
pub fn parent(idx: u32) u32 {
std.debug.assert(idx > 0);
return (idx - 1) / 2;
}
pub fn left(idx: u32) u32 {
return 2 * idx + 1;
}